-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwakeup.c~
81 lines (60 loc) · 2.04 KB
/
wakeup.c~
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <pebble.h>
Window *window;
// Key values for AppMessage Dictionary
enum {
STATUS_KEY = 0,
MESSAGE_KEY = 1
};
// Write message to buffer & send
void send_message(void){
DictionaryIterator *iter;
app_message_outbox_begin(&iter);
dict_write_uint8(iter, STATUS_KEY, 0x1);
dict_write_end(iter);
app_message_outbox_send();
}
// Called when a message is received from PebbleKitJS
static void in_received_handler(DictionaryIterator *received, void *context) {
Tuple *tuple;
tuple = dict_find(received, STATUS_KEY);
if(tuple) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "Received Status: %d", (int)tuple->value->uint32);
}
tuple = dict_find(received, MESSAGE_KEY);
if(tuple) {
APP_LOG(APP_LOG_LEVEL_DEBUG, "Received Message: %s", tuple->value->cstring);
}
//Renders display
Layer *window_layer = window_get_root_layer(window);
GRect window_bounds = layer_get_bounds(window_layer);
s_text_layer = text_layer_create(GRect(5, 0, window_bounds.size.w - 5, window_bounds.size.h));
text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24));
text_layer_set_text(s_text_layer, "Get Back to Work!");
//Vibrates device
vibes_long_pulse();
}
// Called when an incoming message from PebbleKitJS is dropped
static void in_dropped_handler(AppMessageResult reason, void *context) {
}
// Called when PebbleKitJS does not acknowledge receipt of a message
static void out_failed_handler(DictionaryIterator *failed, AppMessageResult reason, void *context) {
}
void init(void) {
window = window_create();
window_stack_push(window, true);
// Register AppMessage handlers
app_message_register_inbox_received(in_received_handler);
app_message_register_inbox_dropped(in_dropped_handler);
app_message_register_outbox_failed(out_failed_handler);
app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
send_message();
}
void deinit(void) {
app_message_deregister_callbacks();
window_destroy(window);
}
int main( void ) {
init();
app_event_loop();
deinit();
}