Make date timeout/enabled status configurable

This commit is contained in:
2026-06-01 23:32:35 -04:00
parent 381db14404
commit 152823fd99
4 changed files with 81 additions and 57 deletions
+1
View File
@@ -30,6 +30,7 @@
"messageKeys": [ "messageKeys": [
"PKJS_READY", "PKJS_READY",
"PKJS_TEMP_BAR_COUNT", "PKJS_TEMP_BAR_COUNT",
"CLAY_DATE_TIMEOUT",
"CLAY_SHOW_TIME_MG", "CLAY_SHOW_TIME_MG",
"CLAY_LOW_FUEL_BARS", "CLAY_LOW_FUEL_BARS",
"CLAY_LED_COLOR", "CLAY_LED_COLOR",
+70 -57
View File
@@ -128,6 +128,61 @@ static void update_temperature() {
} }
} }
static void update_minute_1() {
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
uint8_t hour = (uint8_t)tick_time->tm_hour;
if (!clock_is_24h_style()) {
hour = hour % 12;
if (hour == 0) {
hour = 12;
}
}
uint8_t minute = (uint8_t)tick_time->tm_min;
static uint8_t s_time_digits[4];
s_time_digits[0] = hour / 10;
s_time_digits[1] = hour % 10;
s_time_digits[2] = minute / 10;
s_time_digits[3] = minute % 10;
for (int i = 0; i < 4; ++i) {
bitmap_layer_set_bitmap(s_time_fg_layers[i], s_font_bitmaps[s_time_digits[i]]);
}
}
static void minute_handler(struct tm *tick_time, TimeUnits units_changed) {
if (!s_showing_date) {
update_minute_1();
}
if (s_pkjs_ready && tick_time->tm_min % 30 == 0) {
update_temperature();
}
}
static void date_timeout(void *context) {
s_showing_date = false;
s_date_timer = NULL;
update_minute_1();
}
static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
static char s_date_buffer[16];
strftime(s_date_buffer, sizeof(s_date_buffer), "%m%d", tick_time);
for (int i = 0; i < 4; ++i) {
bitmap_layer_set_bitmap(s_time_fg_layers[i], s_font_bitmaps[s_date_buffer[i] - '0']);
}
s_showing_date = true;
if (s_date_timer) {
app_timer_cancel(s_date_timer);
}
s_date_timer = app_timer_register(settings.DateTimeoutSecs * 1000, date_timeout, NULL);
}
static void apply_settings(bool first_run) { static void apply_settings(bool first_run) {
// LED&BG // LED&BG
light_set_color(settings.ColorLED); // no-op on unsupported platforms light_set_color(settings.ColorLED); // no-op on unsupported platforms
@@ -204,6 +259,13 @@ static void apply_settings(bool first_run) {
// changes to low fuel threshold // changes to low fuel threshold
batt_callback(battery_state_service_peek()); batt_callback(battery_state_service_peek());
// sub/unsub from accelerometer if needed
if (settings.DateTimeoutSecs == 0) {
accel_tap_service_unsubscribe();
} else {
accel_tap_service_subscribe(accel_tap_handler);
}
} }
static void main_window_load() { static void main_window_load() {
@@ -243,6 +305,9 @@ static void main_window_load() {
} }
static void main_window_unload() { static void main_window_unload() {
if (settings.DateTimeoutSecs != 0) {
accel_tap_service_unsubscribe();
}
layer_destroy(s_fuel_mg_layer); layer_destroy(s_fuel_mg_layer);
layer_destroy(s_temp_mg_layer); layer_destroy(s_temp_mg_layer);
bitmap_layer_destroy(s_f_layer); bitmap_layer_destroy(s_f_layer);
@@ -257,61 +322,6 @@ static void main_window_unload() {
} }
} }
static void update_minute_1() {
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
uint8_t hour = (uint8_t)tick_time->tm_hour;
if (!clock_is_24h_style()) {
hour = hour % 12;
if (hour == 0) {
hour = 12;
}
}
uint8_t minute = (uint8_t)tick_time->tm_min;
static uint8_t s_time_digits[4];
s_time_digits[0] = hour / 10;
s_time_digits[1] = hour % 10;
s_time_digits[2] = minute / 10;
s_time_digits[3] = minute % 10;
for (int i = 0; i < 4; ++i) {
bitmap_layer_set_bitmap(s_time_fg_layers[i], s_font_bitmaps[s_time_digits[i]]);
}
}
static void date_timeout(void *context) {
s_showing_date = false;
s_date_timer = NULL;
update_minute_1();
}
static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
time_t temp = time(NULL);
struct tm *tick_time = localtime(&temp);
static char s_date_buffer[16];
strftime(s_date_buffer, sizeof(s_date_buffer), "%m%d", tick_time);
for (int i = 0; i < 4; ++i) {
bitmap_layer_set_bitmap(s_time_fg_layers[i], s_font_bitmaps[s_date_buffer[i] - '0']);
}
s_showing_date = true;
if (s_date_timer) {
app_timer_cancel(s_date_timer);
}
s_date_timer = app_timer_register(3000, date_timeout, NULL);
}
static void minute_handler(struct tm *tick_time, TimeUnits units_changed) {
if (!s_showing_date) {
update_minute_1();
}
if (s_pkjs_ready && tick_time->tm_min % 30 == 0) {
update_temperature();
}
}
static void inbox_received_handler(DictionaryIterator *iter, void *context) { static void inbox_received_handler(DictionaryIterator *iter, void *context) {
Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY); Tuple *ready_tuple = dict_find(iter, MESSAGE_KEY_PKJS_READY);
if (ready_tuple) { if (ready_tuple) {
@@ -328,6 +338,7 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
} }
// CLAY SETTINGS // CLAY SETTINGS
Tuple *date_timeout_tuple = dict_find(iter, MESSAGE_KEY_CLAY_DATE_TIMEOUT);
Tuple *show_time_mg_tuple = dict_find(iter, MESSAGE_KEY_CLAY_SHOW_TIME_MG); Tuple *show_time_mg_tuple = dict_find(iter, MESSAGE_KEY_CLAY_SHOW_TIME_MG);
Tuple *low_fuel_bars_tuple = dict_find(iter, MESSAGE_KEY_CLAY_LOW_FUEL_BARS); Tuple *low_fuel_bars_tuple = dict_find(iter, MESSAGE_KEY_CLAY_LOW_FUEL_BARS);
Tuple *color_led_tuple = dict_find(iter, MESSAGE_KEY_CLAY_LED_COLOR); Tuple *color_led_tuple = dict_find(iter, MESSAGE_KEY_CLAY_LED_COLOR);
@@ -338,6 +349,9 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
Tuple *color_mg_time_tuple = dict_find(iter, MESSAGE_KEY_CLAY_TIME_MG_COLOR); Tuple *color_mg_time_tuple = dict_find(iter, MESSAGE_KEY_CLAY_TIME_MG_COLOR);
Tuple *color_fg_tuple = dict_find(iter, MESSAGE_KEY_CLAY_FG_COLOR); Tuple *color_fg_tuple = dict_find(iter, MESSAGE_KEY_CLAY_FG_COLOR);
Tuple *color_low_fuel_tuple = dict_find(iter, MESSAGE_KEY_CLAY_LOW_FUEL_COLOR); Tuple *color_low_fuel_tuple = dict_find(iter, MESSAGE_KEY_CLAY_LOW_FUEL_COLOR);
if (date_timeout_tuple) {
settings.DateTimeoutSecs = date_timeout_tuple->value->uint8;
}
if (show_time_mg_tuple) { if (show_time_mg_tuple) {
settings.ShowTimeMG = show_time_mg_tuple->value->uint8; settings.ShowTimeMG = show_time_mg_tuple->value->uint8;
} }
@@ -377,6 +391,7 @@ static void init() {
if (persist_exists(STORAGE_KEY_SETTINGS)) { if (persist_exists(STORAGE_KEY_SETTINGS)) {
persist_read_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings)); persist_read_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings));
} else { } else {
settings.DateTimeoutSecs = 3;
settings.ShowTimeMG = false; settings.ShowTimeMG = false;
settings.LowFuelBars = 21; settings.LowFuelBars = 21;
settings.ColorLED = GColorWhite; settings.ColorLED = GColorWhite;
@@ -428,11 +443,9 @@ static void init() {
tick_timer_service_subscribe(MINUTE_UNIT, minute_handler); tick_timer_service_subscribe(MINUTE_UNIT, minute_handler);
battery_state_service_subscribe(batt_callback); battery_state_service_subscribe(batt_callback);
accel_tap_service_subscribe(accel_tap_handler);
} }
static void deinit() { static void deinit() {
accel_data_service_unsubscribe();
battery_state_service_unsubscribe(); battery_state_service_unsubscribe();
tick_timer_service_unsubscribe(); tick_timer_service_unsubscribe();
layer_destroy(s_fuel_layer); layer_destroy(s_fuel_layer);
+1
View File
@@ -4,6 +4,7 @@
#define STORAGE_KEY_SETTINGS 69 #define STORAGE_KEY_SETTINGS 69
typedef struct ClaySettings { typedef struct ClaySettings {
uint8_t DateTimeoutSecs;
bool ShowTimeMG; bool ShowTimeMG;
uint8_t LowFuelBars; uint8_t LowFuelBars;
GColor ColorLED; GColor ColorLED;
+9
View File
@@ -19,6 +19,15 @@ module.exports = [
"label": "Show time segments midground", "label": "Show time segments midground",
"description": "Show or hide the unlit segments behind the time." "description": "Show or hide the unlit segments behind the time."
}, },
{
"type": "slider",
"messageKey": "CLAY_DATE_TIMEOUT",
defaultValue: 3,
min: 0,
max: 15,
"label": "Date timeout (seconds)",
"description": "When you flick your wrist, the date will be shown for this number of seconds.<br><br>Set to 0 to disable this feature."
},
{ {
"type": "slider", "type": "slider",
"messageKey": "CLAY_TEMP_BAR_0", "messageKey": "CLAY_TEMP_BAR_0",