Further reduce code duplication in received handler
This commit is contained in:
+13
-24
@@ -568,6 +568,13 @@ static void main_window_unload() {
|
||||
}
|
||||
}
|
||||
|
||||
static void apply_uint8_from_tuple(DictionaryIterator *iter, uint32_t key, void *dest) {
|
||||
Tuple *t = dict_find(iter, key);
|
||||
if (!t)
|
||||
return;
|
||||
*(uint8_t *)dest = t->value->uint8;
|
||||
}
|
||||
|
||||
static void apply_color_from_tuple(DictionaryIterator *iter, uint32_t key, GColor *dest) {
|
||||
Tuple *t = dict_find(iter, key);
|
||||
if (!t)
|
||||
@@ -598,12 +605,12 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
||||
}
|
||||
|
||||
// CLAY SETTINGS
|
||||
Tuple *enable_peek_tuple = dict_find(iter, MESSAGE_KEY_CLAY_ENABLE_PEEK);
|
||||
Tuple *show_digits_mg_tuple = dict_find(iter, MESSAGE_KEY_CLAY_SHOW_DIGITS_MG);
|
||||
Tuple *track_bt_status_tuple = dict_find(iter, MESSAGE_KEY_CLAY_TRACK_BT_STATUS);
|
||||
Tuple *date_timeout_secs_tuple = dict_find(iter, MESSAGE_KEY_CLAY_DATE_TIMEOUT_SECS);
|
||||
Tuple *low_fuel_percent_tuple = dict_find(iter, MESSAGE_KEY_CLAY_LOW_FUEL_PERCENT);
|
||||
Tuple *use_custom_led_tuple = dict_find(iter, MESSAGE_KEY_CLAY_USE_CUSTOM_LED);
|
||||
apply_uint8_from_tuple(iter, MESSAGE_KEY_CLAY_ENABLE_PEEK, &settings.EnablePeek);
|
||||
apply_uint8_from_tuple(iter, MESSAGE_KEY_CLAY_SHOW_DIGITS_MG, &settings.ShowDigitsMG);
|
||||
apply_uint8_from_tuple(iter, MESSAGE_KEY_CLAY_TRACK_BT_STATUS, &settings.TrackBTStatus);
|
||||
apply_uint8_from_tuple(iter, MESSAGE_KEY_CLAY_DATE_TIMEOUT_SECS, &settings.DateTimeoutSecs);
|
||||
apply_uint8_from_tuple(iter, MESSAGE_KEY_CLAY_LOW_FUEL_PERCENT, &settings.LowFuelPercent);
|
||||
apply_uint8_from_tuple(iter, MESSAGE_KEY_CLAY_USE_CUSTOM_LED, &settings.UseCustomLED);
|
||||
apply_color_from_tuple(iter, MESSAGE_KEY_CLAY_COLOR_LED, &settings.ColorLED);
|
||||
apply_color_from_tuple(iter, MESSAGE_KEY_CLAY_COLOR_BG, &settings.ColorBG);
|
||||
apply_color_from_tuple(iter, MESSAGE_KEY_CLAY_COLOR_BAR_MG, &settings.ColorBarsMG);
|
||||
@@ -615,24 +622,6 @@ static void inbox_received_handler(DictionaryIterator *iter, void *context) {
|
||||
apply_color_from_tuple(iter, MESSAGE_KEY_CLAY_COLOR_HOURS, &settings.ColorHours);
|
||||
apply_color_from_tuple(iter, MESSAGE_KEY_CLAY_COLOR_MINUTES, &settings.ColorMinutes);
|
||||
apply_color_from_tuple(iter, MESSAGE_KEY_CLAY_COLOR_WARNING, &settings.ColorWarning);
|
||||
if (enable_peek_tuple) {
|
||||
settings.EnablePeek = enable_peek_tuple->value->uint8;
|
||||
}
|
||||
if (show_digits_mg_tuple) {
|
||||
settings.ShowDigitsMG = show_digits_mg_tuple->value->uint8;
|
||||
}
|
||||
if (track_bt_status_tuple) {
|
||||
settings.TrackBTStatus = track_bt_status_tuple->value->uint8;
|
||||
}
|
||||
if (date_timeout_secs_tuple) {
|
||||
settings.DateTimeoutSecs = date_timeout_secs_tuple->value->uint8;
|
||||
}
|
||||
if (low_fuel_percent_tuple) {
|
||||
settings.LowFuelPercent = low_fuel_percent_tuple->value->uint8;
|
||||
}
|
||||
if (use_custom_led_tuple) {
|
||||
settings.UseCustomLED = use_custom_led_tuple->value->uint8;
|
||||
}
|
||||
persist_write_data(STORAGE_KEY_SETTINGS, &settings, sizeof(settings));
|
||||
apply_settings();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user