parent
a0454fb1cd
commit
517d0180dc
|
@ -9,17 +9,21 @@ String.prototype.hashCode = function(){
|
||||||
return hash;
|
return hash;
|
||||||
};
|
};
|
||||||
|
|
||||||
var debugwatches = Array(1568511776, 1135189913, -826258655, -1783317168);
|
var debugwatches = Array(
|
||||||
|
1568511776, //c
|
||||||
|
1135189913, //b
|
||||||
|
-826258655, //a
|
||||||
|
-1783317168, //em
|
||||||
|
91860716, //a sl
|
||||||
|
-1462573071, //b sl
|
||||||
|
244993878 //c sl
|
||||||
|
);
|
||||||
var tokenhash;
|
var tokenhash;
|
||||||
|
|
||||||
|
|
||||||
Pebble.addEventListener('ready', function() {
|
Pebble.addEventListener('ready', function() {
|
||||||
console.log('PebbleKit JS ready!');
|
console.log('PebbleKit JS ready!');
|
||||||
tokenhash = Pebble.getWatchToken().hashCode();
|
console.log('WatchToken '+Pebble.getWatchToken());
|
||||||
console.log('Watch identifier '+tokenhash);
|
|
||||||
if (debugwatches.indexOf(tokenhash) > -1) {
|
|
||||||
var dict = {"debugwatch": 1};
|
|
||||||
Pebble.sendAppMessage(dict);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
Pebble.addEventListener('appmessage', function() {
|
Pebble.addEventListener('appmessage', function() {
|
||||||
|
@ -49,8 +53,7 @@ Pebble.addEventListener('showConfiguration', function() {
|
||||||
Pebble.addEventListener('webviewclosed', function(e) {
|
Pebble.addEventListener('webviewclosed', function(e) {
|
||||||
var configData = JSON.parse(decodeURIComponent(e.response));
|
var configData = JSON.parse(decodeURIComponent(e.response));
|
||||||
console.log('Configuration page returned: '+JSON.stringify(configData));
|
console.log('Configuration page returned: '+JSON.stringify(configData));
|
||||||
if (configData.background_color) {
|
var options = {
|
||||||
Pebble.sendAppMessage({
|
|
||||||
large_mode: 0+(configData.large_mode === 'true'),
|
large_mode: 0+(configData.large_mode === 'true'),
|
||||||
eu_date: 0+(configData.eu_date === 'true'),
|
eu_date: 0+(configData.eu_date === 'true'),
|
||||||
quick_start: 0+(configData.quick_start === 'true'),
|
quick_start: 0+(configData.quick_start === 'true'),
|
||||||
|
@ -69,8 +72,14 @@ Pebble.addEventListener('webviewclosed', function(e) {
|
||||||
ns_start: parseInt(configData.ns_start),
|
ns_start: parseInt(configData.ns_start),
|
||||||
ns_stop: parseInt(configData.ns_stop),
|
ns_stop: parseInt(configData.ns_stop),
|
||||||
backlight: 0+(configData.backlight === 'true'),
|
backlight: 0+(configData.backlight === 'true'),
|
||||||
weekday: 0+(configData.weekday === 'true')
|
weekday: 0+(configData.weekday === 'true'),
|
||||||
}, function() {
|
};
|
||||||
|
if (debugwatches.indexOf(tokenhash) > -1) {
|
||||||
|
console.log('Debug Watch with Hash '+tokenhash+'. Setting debug flag on watchface …');
|
||||||
|
options.debugwatch = 1;
|
||||||
|
}
|
||||||
|
if (configData.background_color) {
|
||||||
|
Pebble.sendAppMessage(options, function() {
|
||||||
console.log('Send successful!');
|
console.log('Send successful!');
|
||||||
}, function() {
|
}, function() {
|
||||||
console.log('Send failed!');
|
console.log('Send failed!');
|
||||||
|
|
|
@ -62,8 +62,10 @@ enum {
|
||||||
|
|
||||||
#define SCREENSHOTMODE false
|
#define SCREENSHOTMODE false
|
||||||
|
|
||||||
|
#define DEBUG false
|
||||||
#define SUPERDEBUG false
|
#define SUPERDEBUG false
|
||||||
|
|
||||||
|
|
||||||
#define EU_DATE (curPrefs.eu_date) // true == MM/DD, false == DD/MM
|
#define EU_DATE (curPrefs.eu_date) // true == MM/DD, false == DD/MM
|
||||||
#define WEEKDAY (curPrefs.weekday)
|
#define WEEKDAY (curPrefs.weekday)
|
||||||
#define CENTER_DATE (curPrefs.center)
|
#define CENTER_DATE (curPrefs.center)
|
||||||
|
@ -632,16 +634,13 @@ static unsigned short get_display_hour(uint8_t hour) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void setupAnimation() {
|
static void setupAnimation() {
|
||||||
if (debug) {
|
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Setting up anim");
|
|
||||||
}
|
|
||||||
anim = animation_create();
|
anim = animation_create();
|
||||||
animation_set_delay(anim, 0);
|
animation_set_delay(anim, 0);
|
||||||
animation_set_duration(anim, contrastmode ? 500 : DIGIT_CHANGE_ANIM_DURATION);
|
animation_set_duration(anim, contrastmode ? 500 : DIGIT_CHANGE_ANIM_DURATION);
|
||||||
animation_set_implementation(anim, &animImpl);
|
animation_set_implementation(anim, &animImpl);
|
||||||
animation_set_curve(anim, AnimationCurveEaseInOut);
|
animation_set_curve(anim, AnimationCurveEaseInOut);
|
||||||
if (debug) {
|
if (debug) {
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Done setting up anim %i", (int)anim);
|
APP_LOG(APP_LOG_LEVEL_INFO, "Set up anim %i", (int)anim);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,7 +669,8 @@ static void handle_tick(struct tm *t, TimeUnits units_changed) {
|
||||||
}
|
}
|
||||||
uint8_t localeid = 0;
|
uint8_t localeid = 0;
|
||||||
static char weekdayname[3];
|
static char weekdayname[3];
|
||||||
const char * locale = i18n_get_system_locale();
|
static char locale[3];
|
||||||
|
strncpy(locale, i18n_get_system_locale(), 2);
|
||||||
if (WEEKDAY) {
|
if (WEEKDAY) {
|
||||||
strftime(weekday_buffer, sizeof(weekday_buffer), "%w", t);
|
strftime(weekday_buffer, sizeof(weekday_buffer), "%w", t);
|
||||||
for (uint8_t lid = 0; lid < 6; lid++) {
|
for (uint8_t lid = 0; lid < 6; lid++) {
|
||||||
|
@ -683,27 +683,19 @@ static void handle_tick(struct tm *t, TimeUnits units_changed) {
|
||||||
strcpy(weekdayname, weekdays[localeid][weekdaynum]);
|
strcpy(weekdayname, weekdays[localeid][weekdaynum]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (debug) {
|
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "It is now %d:%d %d.%d.", (int)ho, (int)mi, (int)da, (int)mo);
|
|
||||||
if (WEEKDAY) {
|
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Locale is %s", locale);
|
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "The Weekday is %c%c", weekdayname[0], weekdayname[1]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
allow_animate = true;
|
allow_animate = true;
|
||||||
if (DISABLE_ANIM) {
|
if (DISABLE_ANIM) {
|
||||||
if (DISABLE_ANIM_START_TIME == DISABLE_ANIM_END_TIME) {
|
if (DISABLE_ANIM_START_TIME == DISABLE_ANIM_END_TIME) {
|
||||||
allow_animate = false;
|
allow_animate = false;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "No Animation because activation and deactivation times are the same");
|
APP_LOG(APP_LOG_LEVEL_INFO, "Animation always off");
|
||||||
}
|
}
|
||||||
} else if (DISABLE_ANIM_START_TIME > DISABLE_ANIM_END_TIME) {
|
} else if (DISABLE_ANIM_START_TIME > DISABLE_ANIM_END_TIME) {
|
||||||
// across midnight
|
// across midnight
|
||||||
if (t->tm_hour >= DISABLE_ANIM_START_TIME || t->tm_hour < DISABLE_ANIM_END_TIME) {
|
if (t->tm_hour >= DISABLE_ANIM_START_TIME || t->tm_hour < DISABLE_ANIM_END_TIME) {
|
||||||
allow_animate = false;
|
allow_animate = false;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "No Animation because time is between %d:00 and %d:00", (int)DISABLE_ANIM_START_TIME , (int)DISABLE_ANIM_END_TIME );
|
APP_LOG(APP_LOG_LEVEL_INFO, "Animation off (%d:00 - %d:00)", (int)DISABLE_ANIM_START_TIME , (int)DISABLE_ANIM_END_TIME );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -711,7 +703,7 @@ static void handle_tick(struct tm *t, TimeUnits units_changed) {
|
||||||
if (t->tm_hour >= DISABLE_ANIM_START_TIME && t->tm_hour < DISABLE_ANIM_END_TIME) {
|
if (t->tm_hour >= DISABLE_ANIM_START_TIME && t->tm_hour < DISABLE_ANIM_END_TIME) {
|
||||||
allow_animate = false;
|
allow_animate = false;
|
||||||
if (debug) {
|
if (debug) {
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "No Animation because time is between %d:00 and %d:00", (int)DISABLE_ANIM_START_TIME , (int)DISABLE_ANIM_END_TIME );
|
APP_LOG(APP_LOG_LEVEL_INFO, "Animation off (%d:00 - %d:00)", (int)DISABLE_ANIM_START_TIME , (int)DISABLE_ANIM_END_TIME );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -776,32 +768,20 @@ static void handle_tick(struct tm *t, TimeUnits units_changed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NO_ZERO) {
|
if (NO_ZERO) {
|
||||||
if (debug) {
|
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Slot 0 was %d and is %d", (int) slot[0].prevDigit, (int) slot[0].curDigit);
|
|
||||||
}
|
|
||||||
if (slot[0].curDigit == 0) {
|
if (slot[0].curDigit == 0) {
|
||||||
if (NUMSLOTS > 8) {
|
if (NUMSLOTS > 8) {
|
||||||
if (debug) {
|
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "More than 8 slots");
|
|
||||||
}
|
|
||||||
if (slot[10].prevDigit != 10 && slot[10].prevDigit != 12) {
|
if (slot[10].prevDigit != 10 && slot[10].prevDigit != 12) {
|
||||||
slot[0].curDigit = 11;
|
slot[0].curDigit = 11;
|
||||||
} else {
|
} else {
|
||||||
slot[0].curDigit = 10;
|
slot[0].curDigit = 10;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (debug) {
|
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "8 slots or fewer");
|
|
||||||
}
|
|
||||||
if (slot[0].prevDigit == 10) {
|
if (slot[0].prevDigit == 10) {
|
||||||
slot[0].curDigit = 11;
|
slot[0].curDigit = 11;
|
||||||
} else {
|
} else {
|
||||||
slot[0].curDigit = 10;
|
slot[0].curDigit = 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (debug) {
|
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Slot 0 is now %d", (uint8_t) slot[0].curDigit);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (slot[4].curDigit == 0) {
|
if (slot[4].curDigit == 0) {
|
||||||
slot[4].curDigit = 10;
|
slot[4].curDigit = 10;
|
||||||
|
@ -831,9 +811,6 @@ static void handle_tick(struct tm *t, TimeUnits units_changed) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void initialAnimationDone() {
|
static void initialAnimationDone() {
|
||||||
if (debug) {
|
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Stopped initial Animation");
|
|
||||||
}
|
|
||||||
initial_anim = false;
|
initial_anim = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -845,9 +822,6 @@ void handle_timer(void *data) {
|
||||||
curTime = time(NULL);
|
curTime = time(NULL);
|
||||||
handle_tick(localtime(&curTime), SECOND_UNIT|MINUTE_UNIT|HOUR_UNIT|DAY_UNIT|MONTH_UNIT|YEAR_UNIT);
|
handle_tick(localtime(&curTime), SECOND_UNIT|MINUTE_UNIT|HOUR_UNIT|DAY_UNIT|MONTH_UNIT|YEAR_UNIT);
|
||||||
initial_anim = true;
|
initial_anim = true;
|
||||||
if (debug) {
|
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Starting initial Animation");
|
|
||||||
}
|
|
||||||
if (initial_anim) {
|
if (initial_anim) {
|
||||||
app_timer_register(contrastmode ? 500 : DIGIT_CHANGE_ANIM_DURATION, initialAnimationDone, NULL);
|
app_timer_register(contrastmode ? 500 : DIGIT_CHANGE_ANIM_DURATION, initialAnimationDone, NULL);
|
||||||
}
|
}
|
||||||
|
@ -968,17 +942,16 @@ static void in_received_handler(DictionaryIterator *iter, void *context) {
|
||||||
Tuple *weekday_t = dict_find(iter, KEY_WEEKDAY);
|
Tuple *weekday_t = dict_find(iter, KEY_WEEKDAY);
|
||||||
Tuple *debug_t = dict_find(iter, KEY_DEBUGWATCH);
|
Tuple *debug_t = dict_find(iter, KEY_DEBUGWATCH);
|
||||||
|
|
||||||
static bool was_config = true;
|
|
||||||
|
|
||||||
if (debug_t) {
|
if (debug_t) {
|
||||||
if (debug_t->value->int8 == 1) {
|
if (debug_t->value->int8 == 1) {
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Enabling debug infos for debug watch");
|
APP_LOG(APP_LOG_LEVEL_INFO, "Setting debug watch");
|
||||||
debug = true;
|
debug = true;
|
||||||
was_config = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (was_config) {
|
if (debug) {
|
||||||
|
APP_LOG(APP_LOG_LEVEL_INFO, "Got config");
|
||||||
|
}
|
||||||
if (large_mode_t) { curPrefs.large_mode = large_mode_t->value->int8; }
|
if (large_mode_t) { curPrefs.large_mode = large_mode_t->value->int8; }
|
||||||
if (eu_date_t) { curPrefs.eu_date = eu_date_t->value->int8; }
|
if (eu_date_t) { curPrefs.eu_date = eu_date_t->value->int8; }
|
||||||
if (quick_start_t) { curPrefs.quick_start = quick_start_t->value->int8; }
|
if (quick_start_t) { curPrefs.quick_start = quick_start_t->value->int8; }
|
||||||
|
@ -998,7 +971,14 @@ static void in_received_handler(DictionaryIterator *iter, void *context) {
|
||||||
if (ns_stop_t) { curPrefs.ns_stop = ns_stop_t->value->int8; }
|
if (ns_stop_t) { curPrefs.ns_stop = ns_stop_t->value->int8; }
|
||||||
if (backlight_t) { curPrefs.backlight = backlight_t->value->int8; }
|
if (backlight_t) { curPrefs.backlight = backlight_t->value->int8; }
|
||||||
if (weekday_t) { curPrefs.weekday = weekday_t->value->int8; }
|
if (weekday_t) { curPrefs.weekday = weekday_t->value->int8; }
|
||||||
|
|
||||||
|
if (debug) {
|
||||||
|
APP_LOG(APP_LOG_LEVEL_INFO, "Writing config");
|
||||||
|
}
|
||||||
persist_write_data(PREFERENCES_KEY, &curPrefs, sizeof(curPrefs));
|
persist_write_data(PREFERENCES_KEY, &curPrefs, sizeof(curPrefs));
|
||||||
|
if (debug) {
|
||||||
|
APP_LOG(APP_LOG_LEVEL_INFO, "Wrote config");
|
||||||
|
}
|
||||||
vibes_short_pulse();
|
vibes_short_pulse();
|
||||||
#if defined(PBL_COLOR)
|
#if defined(PBL_COLOR)
|
||||||
if (curPrefs.contrast == false) {
|
if (curPrefs.contrast == false) {
|
||||||
|
@ -1021,28 +1001,30 @@ static void in_received_handler(DictionaryIterator *iter, void *context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (debug) {
|
if (debug) {
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Tearing down");
|
APP_LOG(APP_LOG_LEVEL_INFO, "Teardown");
|
||||||
}
|
}
|
||||||
teardownUI();
|
teardownUI();
|
||||||
if (debug) {
|
if (debug) {
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Setting up");
|
APP_LOG(APP_LOG_LEVEL_INFO, "Setup");
|
||||||
}
|
}
|
||||||
setupUI();
|
setupUI();
|
||||||
if (debug) {
|
if (debug) {
|
||||||
APP_LOG(APP_LOG_LEVEL_INFO, "Done");
|
APP_LOG(APP_LOG_LEVEL_INFO, "Done");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void in_dropped_handler(AppMessageResult reason, void *context) {
|
static void in_dropped_handler(AppMessageResult reason, void *context) {
|
||||||
APP_LOG(APP_LOG_LEVEL_WARNING, "Dropped a message because %i", (int)reason);
|
APP_LOG(APP_LOG_LEVEL_WARNING, "Dropped message because %i", (int)reason);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void init() {
|
static void init() {
|
||||||
setlocale(LC_ALL, "en_US");
|
|
||||||
window = window_create();
|
window = window_create();
|
||||||
|
|
||||||
|
if (DEBUG) {
|
||||||
|
debug = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Set up preferences
|
// Set up preferences
|
||||||
if(persist_exists(PREFERENCES_KEY)){
|
if(persist_exists(PREFERENCES_KEY)){
|
||||||
persist_read_data(PREFERENCES_KEY, &curPrefs, sizeof(curPrefs));
|
persist_read_data(PREFERENCES_KEY, &curPrefs, sizeof(curPrefs));
|
||||||
|
|
Loading…
Reference in New Issue