From 1388670ce7ff26cefd3e7a003bda30db3941b12b Mon Sep 17 00:00:00 2001 From: Peter Marquardt Date: Sat, 16 Jan 2016 23:01:19 +0100 Subject: [PATCH] fixed bug and bundled up for release --- appinfo.json | 1 + src/pebble-app.js | 8 +++--- src/squared.c | 68 ++++++++++++++++++++++++++++++++--------------- 3 files changed, 53 insertions(+), 24 deletions(-) diff --git a/appinfo.json b/appinfo.json index df89013..f6e039c 100644 --- a/appinfo.json +++ b/appinfo.json @@ -1,6 +1,7 @@ { "appKeys": { "background_color": 4, + "backlight": 17, "btvibe": 12, "center": 11, "contrast": 13, diff --git a/src/pebble-app.js b/src/pebble-app.js index ea165d8..47773f6 100644 --- a/src/pebble-app.js +++ b/src/pebble-app.js @@ -8,10 +8,11 @@ Pebble.addEventListener('showConfiguration', function() { watch = Pebble.getActiveWatchInfo(); } var url='http://pebble.lastfuture.de/config/squared46/'; + url += "?model="+watch.model; if (watch.platform == "basalt") { - url += "?rect=true"; + url += "&rect=true"; } else if (watch.platform == "aplite") { - url += "?rect=true&bw=true"; + url += "&rect=true&bw=true"; } console.log('Showing configuration page: '+url); Pebble.openURL(url); @@ -38,7 +39,8 @@ Pebble.addEventListener('webviewclosed', function(e) { contrast: 0+(configData.contrast === 'true'), nightsaver: 0+(configData.nightsaver === 'true'), ns_start: parseInt(configData.ns_start), - ns_stop: parseInt(configData.ns_stop) + ns_stop: parseInt(configData.ns_stop), + backlight: 0+(configData.backlight === 'true') }, function() { console.log('Send successful!'); }, function() { diff --git a/src/squared.c b/src/squared.c index a073660..c5426f4 100644 --- a/src/squared.c +++ b/src/squared.c @@ -2,7 +2,7 @@ * Original source code by lastfuture * SDK 2.0beta4 port by Jnm * SDK 3.0 port and colorizing by hexahedria - * adaptations for Chalk and Aplite by lastfuture + * adaptations for Chalk and Aplite as well as continued development by lastfuture */ #include @@ -27,6 +27,7 @@ typedef struct { bool nightsaver; int ns_start; int ns_stop; + bool backlight; } Preferences; @@ -50,6 +51,7 @@ enum { KEY_NIGHTSAVER, KEY_NS_START, KEY_NS_STOP, + KEY_BACKLIGHT, }; #define PREFERENCES_KEY 0 @@ -58,6 +60,7 @@ enum { #define CENTER_DATE (curPrefs.center) #define DISCONNECT_VIBRATION (curPrefs.btvibe) #define CONTRAST_WHILE_CHARGING (curPrefs.contrast) +#define LIGHT_WHILE_CHARGING (curPrefs.backlight) #define DISABLE_ANIM (curPrefs.nightsaver) #define DISABLE_ANIM_START_TIME (curPrefs.ns_start) #define DISABLE_ANIM_END_TIME (curPrefs.ns_stop) @@ -457,22 +460,16 @@ void handle_tick(struct tm *t, TimeUnits units_changed) { animation_unschedule(anim); animation_destroy(anim); } + ho = get_display_hour(t->tm_hour); + mi = t->tm_min; + da = t->tm_mday; + mo = t->tm_mon+1; if (debug) { - ho = 5; - 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; + ho = 9; } + APP_LOG(APP_LOG_LEVEL_INFO, "It is now %d:%d %d.%d.", (int)ho, (int)mi, (int)da, (int)mo); + allow_animate = true; if (DISABLE_ANIM) { if (DISABLE_ANIM_START_TIME > DISABLE_ANIM_END_TIME) { @@ -536,7 +533,7 @@ void handle_tick(struct tm *t, TimeUnits units_changed) { if (debug) { APP_LOG(APP_LOG_LEVEL_INFO, "Slot 0 was %d", (int) slot[0].prevDigit); } - if (slot[0].curDigit == 0 || slot[0].prevDigit >= 10) { + if (ho < 10 && slot[0].prevDigit >= 10) { if (NUMSLOTS > 8) { if (debug) { APP_LOG(APP_LOG_LEVEL_INFO, "More than 8 slots"); @@ -622,7 +619,11 @@ static void animateDigits(struct Animation *anim, const AnimationProgress normTi int i; for (i=0; ivalue->int8; @@ -745,6 +754,9 @@ static void in_received_handler(DictionaryIterator *iter, void *context) { if (ns_stop_t) { curPrefs.ns_stop = ns_stop_t->value->int8; } + if (backlight_t) { + curPrefs.backlight = backlight_t->value->int8; + } persist_write_data(PREFERENCES_KEY, &curPrefs, sizeof(curPrefs)); vibes_short_pulse(); if (curPrefs.contrast == false) { @@ -757,6 +769,14 @@ static void in_received_handler(DictionaryIterator *iter, void *context) { previous_contrastmode = true; } } + if (curPrefs.backlight == false) { + light_enable(false); + } else { + BatteryChargeState charge_state = battery_state_service_peek(); + if (charge_state.is_plugged) { + light_enable(true); + } + } if (debug) { APP_LOG(APP_LOG_LEVEL_INFO, "Tearing down"); } @@ -803,6 +823,7 @@ static void init() { .nightsaver = false, .ns_start = 0, .ns_stop = 6, + .backlight = false, }; } @@ -811,10 +832,15 @@ static void init() { BatteryChargeState charge_state = battery_state_service_peek(); if (charge_state.is_plugged) { - previous_contrastmode = true; - contrastmode = true; - teardownUI(); - setupUI(); + if (CONTRAST_WHILE_CHARGING) { + previous_contrastmode = true; + contrastmode = true; + teardownUI(); + setupUI(); + } + if (LIGHT_WHILE_CHARGING) { + light_enable(true); + } } // Setup app message @@ -825,7 +851,7 @@ static void init() { tick_timer_service_subscribe(MINUTE_UNIT, handle_tick); if (debug) { - light_enable(true); + //light_enable(true); } handle_bluetooth(connection_service_peek_pebble_app_connection());