#include #include "string.h" #include "stdlib.h" static Window *window; static ActionBarLayer *action_bar; static GBitmap *action_icon_start; static GBitmap *action_icon_stop; static TextLayer *text_layer; static TextLayer *distance_layer; int32_t angle=0; Layer *angle_layer; static GPath *angle_arrow; static const GPathInfo ANGLE_HAND_POINTS = { 3, (GPoint []){ {-10, 0}, {10, 0}, {0, -40} } }; static int state; static void hands_update_proc(Layer *layer, GContext *ctx) { //GRect bounds = layer_get_bounds(layer); //const GPoint center = grect_center_point(&bounds); graphics_context_set_fill_color(ctx, GColorBlack); graphics_context_set_stroke_color(ctx, GColorBlack); gpath_rotate_to(angle_arrow, (TRIG_MAX_ANGLE*angle/360)); gpath_draw_filled(ctx, angle_arrow); gpath_draw_outline(ctx, angle_arrow); } void out_sent_handler(DictionaryIterator *sent, void *context) { // outgoing message was delivered if(state == 1){ text_layer_set_text(distance_layer, "Start"); } else if(state == 2){ text_layer_set_text(distance_layer, "Stop"); } } void out_failed_handler(DictionaryIterator *failed, AppMessageResult reason, void *context) { // outgoing message failed text_layer_set_text(distance_layer, "Faild"); } void in_received_handler(DictionaryIterator *received, void *context) { // incoming message received Tuple *distance_tuple = dict_find(received,1); Tuple *angle_tuple = dict_find(received,2); Tuple *angle_string_tuple = dict_find(received,3); if(distance_tuple){ text_layer_set_text(distance_layer,distance_tuple->value->cstring); } if(angle_tuple){ //text_layer_set_text(text_layer,angle_tuple->value->uint8); angle = angle_tuple->value->uint8; } if(angle_string_tuple){ text_layer_set_text(text_layer,angle_string_tuple->value->cstring); } layer_mark_dirty(window_get_root_layer(window)); } void in_dropped_handler(AppMessageResult reason, void *context) { // incoming message dropped } static void up_click_handler(ClickRecognizerRef recognizer, void *context) { state=1; DictionaryIterator *iter; app_message_outbox_begin(&iter); Tuplet value = TupletInteger(1, 1); dict_write_tuplet(iter, &value); app_message_outbox_send(); } static void down_click_handler(ClickRecognizerRef recognizer, void *context) { state=2; DictionaryIterator *iter; app_message_outbox_begin(&iter); Tuplet value = TupletInteger(1, 2); dict_write_tuplet(iter, &value); app_message_outbox_send(); } static void select_click_handler(ClickRecognizerRef recognizer, void *context) { state=3; DictionaryIterator *iter; app_message_outbox_begin(&iter); Tuplet value = TupletInteger(1, 3); dict_write_tuplet(iter, &value); app_message_outbox_send(); } static void click_config_provider(void *context) { window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler); window_single_click_subscribe(BUTTON_ID_UP, up_click_handler); window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler); } static void window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); //text layer text_layer = text_layer_create((GRect) { .origin = { 10, 138 }, .size = { bounds.size.w, 30 } }); text_layer_set_text(text_layer, "fieldWalking"); text_layer_set_text_alignment(text_layer, GTextAlignmentLeft); layer_add_child(window_layer, text_layer_get_layer(text_layer)); //distance text layer distance_layer = text_layer_create((GRect) { .origin = { 0, 0 }, .size = { bounds.size.w-22, 42 } }); text_layer_set_text(distance_layer, "Koma Navi"); text_layer_set_text_alignment(distance_layer, GTextAlignmentCenter); text_layer_set_font(distance_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD)); //24 layer_add_child(window_layer, text_layer_get_layer(distance_layer)); //action bar action_bar = action_bar_layer_create(); action_bar_layer_add_to_window(action_bar, window); action_bar_layer_set_click_config_provider(action_bar,click_config_provider); action_icon_start = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_START); action_icon_stop = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_ACTION_ICON_STOP); action_bar_layer_set_icon(action_bar, BUTTON_ID_UP, action_icon_start); action_bar_layer_set_icon(action_bar, BUTTON_ID_DOWN, action_icon_stop); //arrow angle_arrow = gpath_create(&ANGLE_HAND_POINTS); angle_layer = layer_create(bounds); layer_set_update_proc(angle_layer, hands_update_proc); layer_add_child(window_layer, angle_layer); GRect centerRect =(GRect){.origin = {0,20}, .size = {bounds.size.w-11,bounds.size.h-20}}; const GPoint center = grect_center_point(¢erRect); gpath_move_to(angle_arrow, center); } static void window_unload(Window *window) { text_layer_destroy(text_layer); text_layer_destroy(distance_layer); action_bar_layer_destroy(action_bar); layer_destroy(angle_layer); } static void init(void) { window = window_create(); //window_set_click_config_provider(window, click_config_provider); window_set_window_handlers(window, (WindowHandlers) { .load = window_load, .unload = window_unload, }); const bool animated = true; window_stack_push(window, animated); app_message_register_inbox_received(in_received_handler); app_message_register_inbox_dropped(in_dropped_handler); app_message_register_outbox_sent(out_sent_handler); app_message_register_outbox_failed(out_failed_handler); const uint32_t inbound_size = 64; const uint32_t outbound_size = 64; app_message_open(inbound_size, outbound_size); } static void deinit(void) { window_destroy(window); gbitmap_destroy(action_icon_start); gbitmap_destroy(action_icon_stop); gpath_destroy(angle_arrow); } int main(void) { init(); app_event_loop(); deinit(); }