|
3 | 3 | Window *my_window; |
4 | 4 | TextLayer *text_layer; |
5 | 5 |
|
| 6 | +enum { |
| 7 | + value = 0 |
| 8 | +}; |
| 9 | + |
| 10 | +void out_sent_handler(DictionaryIterator *sent, void *context) { |
| 11 | + // outgoing message was delivered |
| 12 | + } |
| 13 | + |
| 14 | + |
| 15 | + void out_failed_handler(DictionaryIterator *failed, AppMessageResult reason, void *context) { |
| 16 | + // outgoing message failed |
| 17 | + } |
| 18 | + |
| 19 | + |
| 20 | + void in_received_handler(DictionaryIterator *received, void *context) { |
| 21 | + // incoming message received |
| 22 | + |
| 23 | + // Check for fields you expect to receive |
| 24 | + Tuple *text_tuple = dict_find(received, value); |
| 25 | + |
| 26 | + // Act on the found fields received |
| 27 | + if (text_tuple) { |
| 28 | + text_layer_set_text(text_layer, text_tuple->value->cstring); |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + |
| 33 | + void in_dropped_handler(AppMessageResult reason, void *context) { |
| 34 | + // incoming message dropped |
| 35 | + } |
| 36 | + |
6 | 37 | void handle_init(void) { |
| 38 | + // Create window |
7 | 39 | my_window = window_create(); |
8 | 40 | window_stack_push(my_window, true /* Animated */); |
9 | 41 | Layer *window_layer = window_get_root_layer(my_window); |
10 | 42 | GRect bounds = layer_get_frame(window_layer); |
11 | | - |
| 43 | + // Initiate AppMessage |
| 44 | + app_message_register_inbox_received(in_received_handler); |
| 45 | + app_message_register_inbox_dropped(in_dropped_handler); |
| 46 | + app_message_register_outbox_sent(out_sent_handler); |
| 47 | + app_message_register_outbox_failed(out_failed_handler); |
| 48 | + const uint32_t inbound_size = 64; |
| 49 | + const uint32_t outbound_size = 64; |
| 50 | + app_message_open(inbound_size, outbound_size); |
| 51 | + //Create Text |
12 | 52 | text_layer = text_layer_create((GRect){ .origin = { 0, 30 }, .size = bounds.size }); |
13 | | - text_layer_set_text(text_layer, "1 DOGE = 0.00000048 BTC"); |
| 53 | + text_layer_set_text(text_layer, "1 DOGE = 0.00000000 BTC"); |
14 | 54 | text_layer_set_font(text_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_COMIC_SANS_25))); |
15 | 55 | layer_add_child(window_layer, text_layer_get_layer(text_layer)); |
16 | 56 | } |
|
0 commit comments