From fdd2addc722364b7892152d9fb4a0e6ca29ea842 Mon Sep 17 00:00:00 2001 From: Peter Marquardt Date: Sat, 16 Jan 2016 03:49:16 +0100 Subject: [PATCH] added animation free time --- appinfo.json | 3 +++ src/pebble-app.js | 5 ++++- src/squared.c | 56 ++++++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 60 insertions(+), 4 deletions(-) diff --git a/appinfo.json b/appinfo.json index 3f1f9d6..df89013 100644 --- a/appinfo.json +++ b/appinfo.json @@ -9,6 +9,9 @@ "large_mode": 0, "leading_zero": 3, "monochrome": 10, + "nightsaver": 14, + "ns_start": 15, + "ns_stop": 16, "number_base_color": 5, "number_variation": 6, "ornament_base_color": 7, diff --git a/src/pebble-app.js b/src/pebble-app.js index f40e4fa..ea165d8 100644 --- a/src/pebble-app.js +++ b/src/pebble-app.js @@ -35,7 +35,10 @@ Pebble.addEventListener('webviewclosed', function(e) { monochrome: 0+(configData.monochrome === 'true'), center: 0+(configData.center === 'true'), btvibe: 0+(configData.btvibe === 'true'), - contrast: 0+(configData.contrast === 'true') + contrast: 0+(configData.contrast === 'true'), + nightsaver: 0+(configData.nightsaver === 'true'), + ns_start: parseInt(configData.ns_start), + ns_stop: parseInt(configData.ns_stop) }, function() { console.log('Send successful!'); }, function() { diff --git a/src/squared.c b/src/squared.c index 1603d0f..5146159 100644 --- a/src/squared.c +++ b/src/squared.c @@ -24,6 +24,10 @@ typedef struct { bool center; bool btvibe; bool contrast; + bool nightsaver; + int ns_start; + int ns_stop; + } Preferences; Preferences curPrefs; @@ -43,6 +47,9 @@ enum { KEY_CENTER, KEY_BTVIBE, KEY_CONTRAST, + KEY_NIGHTSAVER, + KEY_NS_START, + KEY_NS_STOP, }; #define PREFERENCES_KEY 0 @@ -51,6 +58,9 @@ enum { #define CENTER_DATE (curPrefs.center) #define DISCONNECT_VIBRATION (curPrefs.btvibe) #define CONTRAST_WHILE_CHARGING (curPrefs.contrast) +#define DISABLE_ANIM (curPrefs.nightsaver) +#define DISABLE_ANIM_START_TIME (curPrefs.ns_start) +#define DISABLE_ANIM_END_TIME (curPrefs.ns_stop) #define NO_ZERO (!curPrefs.leading_zero) // true == replaces leading Zero for hour, day, month with a "cycler" #define TILE_SIZE PBL_IF_RECT_ELSE((curPrefs.large_mode ? 12 : 10), 10) #define INVERT (curPrefs.invert) @@ -241,7 +251,7 @@ uint8_t combine_colors(uint8_t fg_color, uint8_t bg_color) { #define ORIGIN_X PBL_IF_RECT_ELSE(((144 - TILES_X)/2), ((180 - TILES_X)/2)) #define ORIGIN_Y PBL_IF_RECT_ELSE((curPrefs.large_mode ? 1 : TILE_SIZE*1.5), (TILE_SIZE*2.2)) -static bool contrastmode = false, previous_contrastmode = false; +static bool contrastmode = false, previous_contrastmode = false, allow_animate = true; static void handle_bluetooth(bool connected) { if (DISCONNECT_VIBRATION && !connected) { @@ -452,12 +462,37 @@ void handle_tick(struct tm *t, TimeUnits units_changed) { mi = 15; da = 12; mo = 3; + ho = get_display_hour(t->tm_hour); + mi = t->tm_min; + da = t->tm_mday; + mo = t->tm_mon+1; } else { ho = get_display_hour(t->tm_hour); mi = t->tm_min; da = t->tm_mday; mo = t->tm_mon+1; } + + allow_animate = true; + if (DISABLE_ANIM) { + if (DISABLE_ANIM_START_TIME > DISABLE_ANIM_END_TIME) { + // across midnight + if (ho >= DISABLE_ANIM_START_TIME || ho < DISABLE_ANIM_END_TIME) { + allow_animate = false; + if (debug) { + APP_LOG(APP_LOG_LEVEL_INFO, "Hour %d was after %d and before %d", (int)ho, (int)DISABLE_ANIM_START_TIME , (int)DISABLE_ANIM_END_TIME ); + } + } + } else { + // prior to midnight + if (ho >= DISABLE_ANIM_START_TIME && ho < DISABLE_ANIM_END_TIME) { + allow_animate = false; + if (debug) { + APP_LOG(APP_LOG_LEVEL_INFO, "Hour %d was after %d and before %d", (int)ho, (int)DISABLE_ANIM_START_TIME , (int)DISABLE_ANIM_END_TIME ); + } + } + } + } for (i=0; ivalue->int8; @@ -698,6 +736,15 @@ static void in_received_handler(DictionaryIterator *iter, void *context) { if (contrast_t) { curPrefs.contrast = contrast_t->value->int8; } + if (nightsaver_t) { + curPrefs.nightsaver = nightsaver_t->value->int8; + } + if (ns_start_t) { + curPrefs.ns_start = ns_start_t->value->int8; + } + if (ns_stop_t) { + curPrefs.ns_stop = ns_stop_t->value->int8; + } persist_write_data(PREFERENCES_KEY, &curPrefs, sizeof(curPrefs)); vibes_short_pulse(); if (curPrefs.contrast == false) { @@ -753,6 +800,9 @@ static void init() { .center = false, .btvibe = false, .contrast = false, + .nightsaver = false, + .ns_start = 0, + .ns_stop = 6, }; } @@ -770,7 +820,7 @@ static void init() { // Setup app message app_message_register_inbox_received(in_received_handler); app_message_register_inbox_dropped(in_dropped_handler); - app_message_open(150,0); + app_message_open(200,0); tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);