From 6a92f59d2e6259ef12ca1c9cf23f5d5c609ef2b5 Mon Sep 17 00:00:00 2001 From: Neale Pickett Date: Tue, 3 May 2016 14:09:08 -0600 Subject: [PATCH] Code cleanup Remove some experimental stuff --- appinfo.json | 1 + src/main.c | 99 ++++------------------------------------------------ 2 files changed, 8 insertions(+), 92 deletions(-) diff --git a/appinfo.json b/appinfo.json index 567f892..ff12d2d 100644 --- a/appinfo.json +++ b/appinfo.json @@ -4,6 +4,7 @@ "" ], "companyName": "dartcatcher@gmail.com", + "enableMultiJS": false, "longName": "Twatch Popcorn", "projectType": "native", "resources": { diff --git a/src/main.c b/src/main.c index c95078d..b41a76a 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,5 @@ #include - #define MINLEN 58 #define HRCIRCLER 30 #define NRINGS 17 @@ -10,15 +9,13 @@ #define fat(x) (fatness * x) static Window *window; -static Layer *s_hr_layer, *s_min_layer, *s_sec_layer; +static Layer *s_hr_layer, *s_min_layer; GRect display_bounds; GPoint center, mincenter; -int32_t min_angle, sec_angle; -char hrstr[3], minstr[3]; -bool min_even; -bool show_seconds = false; +int32_t min_angle; +char hrstr[3], minstr[3], datestr[15]; bool bt_vibe = true; bool shape = 0; @@ -33,58 +30,13 @@ GColor *rings[nringcolors] = { &GColorWhite, }; -const GPoint SUN_POINTS[] = { - {0, 119},{78, 162},{93, 74},{175, 40},{116, -26},{140, -112},{52, -108},{0, -180},{-52, -108},{-140, -112},{-116, -26},{-175, 40},{-93, 74},{-78, 162},{0} -}; - -// r = 180; tau = math.pi*2 -// print ','.join(["{%s, %s}"%(int(r/(i%2+1)*sin(tau*(i/10.0))), int(r/(i%2+1)*cos(tau*(i/10.0)))) for i in range(10)]) -const GPoint STAR_POINTS[] = { - {0, 180},{52, 72},{171, 55},{85, -27},{105, -145},{0, -90},{-105, -145},{-85, -27},{-171, 55},{-52, 72},{0} -}; - -const GPoint SQUARE_POINTS[] = { - {0, 180},{180, 0},{0, -180},{-180, 0},{0} -}; - -// print ','.join(["{%s, %s}"%(int(r*sin(tau*(i/3.0))), int(r*cos(tau*(i/3.0)))) for i in range(3)]) -const GPoint TRIANGLE_POINTS[] = { - {0, 180},{155, -90},{-155, -90},{0} -}; - -GPath shape_path = { - 0, - (GPoint [15]){{0}}, - 0, - {0} -}; - static void min_update_proc(Layer *layer, GContext *ctx) { graphics_context_set_fill_color(ctx, *rings[0]); graphics_fill_rect(ctx, layer_get_bounds(layer), 0, GCornerNone); - gpath_move_to(&shape_path, mincenter); - gpath_rotate_to(&shape_path, min_angle + DEG_TO_TRIGANGLE(180)); - for (int i = 0; i < NRINGS; i += 1) { - graphics_context_set_fill_color(ctx, *rings[(NRINGS - i) % nringcolors]); - if (shape) { - for (unsigned int j = 0; ; j += 1) { - GPoint p; - - p = SUN_POINTS[j]; - - if ((p.x == 0) && (p.y == 0)) { - shape_path.num_points = j; - break; - } - shape_path.points[j].x = p.x * (NRINGS - i) / 10; - shape_path.points[j].y = p.y * (NRINGS - i) / 10; - } - gpath_draw_filled(ctx, &shape_path); - } else { - graphics_fill_circle(ctx, mincenter, MINCIRCLER + (NRINGS - i) * fatness); - } + graphics_context_set_fill_color(ctx, *rings[(NRINGS - i) % nringcolors]); + graphics_fill_circle(ctx, mincenter, MINCIRCLER + (NRINGS - i) * fatness); } // center dot @@ -140,31 +92,6 @@ static void hr_update_proc(Layer *layer, GContext *ctx) { NULL); } -static void sec_update_proc(Layer *layer, GContext *ctx) { - if (! show_seconds) { - return; - } - - GRect secbox = { - .origin = { - .x = mincenter.x - (40+2)/2, - .y = mincenter.y - (40+2)/2, - }, - .size = { - .w = 40+2, - .h = 40+2, - } - }; - - graphics_context_set_fill_color(ctx, GColorVividCerulean); - if (min_even) { - graphics_fill_radial(ctx, secbox, GOvalScaleModeFitCircle, 2, 0, sec_angle); - } else { - graphics_fill_radial(ctx, secbox, GOvalScaleModeFitCircle, 2, sec_angle, DEG_TO_TRIGANGLE(360)); - } -} - - static void handle_tick(struct tm *tick_time, TimeUnits units_changed) { if (units_changed & HOUR_UNIT) { if (clock_is_24h_style()) { @@ -180,15 +107,9 @@ static void handle_tick(struct tm *tick_time, TimeUnits units_changed) { min_angle = DEG_TO_TRIGANGLE(tick_time->tm_min * 6); mincenter.x = (int16_t)(sin_lookup(min_angle) * MINLEN / TRIG_MAX_RATIO) + center.x; mincenter.y = (int16_t)(-cos_lookup(min_angle) * MINLEN / TRIG_MAX_RATIO) + center.y; - min_even = (tick_time->tm_min % 2 == 0); layer_mark_dirty(s_min_layer); } - - if (units_changed & SECOND_UNIT) { - sec_angle = DEG_TO_TRIGANGLE(tick_time->tm_sec * 6); - layer_mark_dirty(s_sec_layer); - } } static void window_load(Window *window) { @@ -201,27 +122,21 @@ static void window_load(Window *window) { s_min_layer = layer_create(display_bounds); layer_set_update_proc(s_min_layer, min_update_proc); - // Seconds - s_sec_layer = layer_create(display_bounds); - layer_set_update_proc(s_sec_layer, sec_update_proc); - // Hours s_hr_layer = layer_create(display_bounds); // XXX: Perhaps this is too big. layer_set_update_proc(s_hr_layer, hr_update_proc); layer_add_child(window_layer, s_min_layer); layer_add_child(window_layer, s_hr_layer); - layer_add_child(window_layer, s_sec_layer); time_t now = time(NULL); struct tm *tick_time = localtime(&now); - handle_tick(tick_time, HOUR_UNIT | MINUTE_UNIT | (show_seconds?SECOND_UNIT:0)); + handle_tick(tick_time, HOUR_UNIT | MINUTE_UNIT); } static void window_unload(Window *window) { layer_destroy(s_hr_layer); layer_destroy(s_min_layer); - layer_destroy(s_sec_layer); } static void bt_handler(bool connected) { @@ -240,7 +155,7 @@ static void init() { }); window_stack_push(window, true); - tick_timer_service_subscribe(HOUR_UNIT | MINUTE_UNIT | (show_seconds?SECOND_UNIT:0), handle_tick); + tick_timer_service_subscribe(HOUR_UNIT | MINUTE_UNIT, handle_tick); bluetooth_connection_service_subscribe(bt_handler); bt_connected = bluetooth_connection_service_peek();