|
|
@@ -17,7 +17,23 @@
|
|
|
#endif
|
|
|
|
|
|
static const char* YES_NO_LIST[] = {"NO", "YES"};
|
|
|
-static const char* ON_OFF_LIST[] = {"OFF", "ON"};
|
|
|
+static const char* AUTOMATION_LIST[] = {
|
|
|
+ "None",
|
|
|
+ "USB"
|
|
|
+#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
+ ,
|
|
|
+ "Bluetooth",
|
|
|
+ "BT and USB"
|
|
|
+#endif
|
|
|
+};
|
|
|
+
|
|
|
+#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
+#define AUTOMATION_LIST_MAX_INDEX (3)
|
|
|
+#else
|
|
|
+#define AUTOMATION_LIST_MAX_INDEX (1)
|
|
|
+#endif
|
|
|
+
|
|
|
+static const char* BAD_KB_LAYOUT_LIST[] = {"QWERTY", "AZERTY"};
|
|
|
static const char* FONT_TEST_STR = "0123BCD";
|
|
|
static const uint8_t FONT_TEST_STR_LENGTH = 7;
|
|
|
|
|
|
@@ -27,10 +43,8 @@ typedef enum {
|
|
|
FontSelect,
|
|
|
SoundSwitch,
|
|
|
VibroSwitch,
|
|
|
- BadUsbSwitch,
|
|
|
-#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
- BadBtSwitch,
|
|
|
-#endif
|
|
|
+ AutomationSwitch,
|
|
|
+ BadKeyboardLayoutSelect,
|
|
|
ConfirmButton
|
|
|
} Control;
|
|
|
|
|
|
@@ -39,11 +53,9 @@ typedef struct {
|
|
|
uint8_t tz_offset_minutes;
|
|
|
bool notification_sound;
|
|
|
bool notification_vibro;
|
|
|
- bool badusb_enabled;
|
|
|
-#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
- bool badbt_enabled;
|
|
|
-#endif
|
|
|
- uint8_t y_offset;
|
|
|
+ AutomationMethod automation_method;
|
|
|
+ uint16_t y_offset;
|
|
|
+ AutomationKeyboardLayout automation_kb_layout;
|
|
|
Control selected_control;
|
|
|
uint8_t active_font;
|
|
|
} SceneState;
|
|
|
@@ -59,10 +71,9 @@ void totp_scene_app_settings_activate(PluginState* plugin_state) {
|
|
|
scene_state->tz_offset_minutes = 60.0f * off_dec;
|
|
|
scene_state->notification_sound = plugin_state->notification_method & NotificationMethodSound;
|
|
|
scene_state->notification_vibro = plugin_state->notification_method & NotificationMethodVibro;
|
|
|
- scene_state->badusb_enabled = plugin_state->automation_method & AutomationMethodBadUsb;
|
|
|
-#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
- scene_state->badbt_enabled = plugin_state->automation_method & AutomationMethodBadBt;
|
|
|
-#endif
|
|
|
+ scene_state->automation_method = plugin_state->automation_method;
|
|
|
+ scene_state->automation_kb_layout = plugin_state->automation_kb_layout;
|
|
|
+
|
|
|
scene_state->active_font = plugin_state->active_font_index;
|
|
|
}
|
|
|
|
|
|
@@ -82,127 +93,121 @@ static void two_digit_to_str(int8_t num, char* str) {
|
|
|
|
|
|
void totp_scene_app_settings_render(Canvas* const canvas, const PluginState* plugin_state) {
|
|
|
const SceneState* scene_state = plugin_state->current_scene_state;
|
|
|
+ if(scene_state->selected_control < FontSelect) {
|
|
|
+ canvas_set_font(canvas, FontPrimary);
|
|
|
+ canvas_draw_str_aligned(
|
|
|
+ canvas, 0, 0 - scene_state->y_offset, AlignLeft, AlignTop, "Timezone offset");
|
|
|
+ canvas_set_font(canvas, FontSecondary);
|
|
|
+
|
|
|
+ char tmp_str[4];
|
|
|
+ two_digit_to_str(scene_state->tz_offset_hours, &tmp_str[0]);
|
|
|
+ canvas_draw_str_aligned(
|
|
|
+ canvas, 0, 17 - scene_state->y_offset, AlignLeft, AlignTop, "Hours:");
|
|
|
+ ui_control_select_render(
|
|
|
+ canvas,
|
|
|
+ 36,
|
|
|
+ 10 - scene_state->y_offset,
|
|
|
+ SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
|
|
|
+ &tmp_str[0],
|
|
|
+ scene_state->selected_control == HoursInput);
|
|
|
+
|
|
|
+ two_digit_to_str(scene_state->tz_offset_minutes, &tmp_str[0]);
|
|
|
+ canvas_draw_str_aligned(
|
|
|
+ canvas, 0, 35 - scene_state->y_offset, AlignLeft, AlignTop, "Minutes:");
|
|
|
+ ui_control_select_render(
|
|
|
+ canvas,
|
|
|
+ 36,
|
|
|
+ 28 - scene_state->y_offset,
|
|
|
+ SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
|
|
|
+ &tmp_str[0],
|
|
|
+ scene_state->selected_control == MinutesInput);
|
|
|
+
|
|
|
+ } else if(scene_state->selected_control < SoundSwitch) {
|
|
|
+ canvas_set_font(canvas, FontPrimary);
|
|
|
+ canvas_draw_str_aligned(
|
|
|
+ canvas, 0, 64 - scene_state->y_offset, AlignLeft, AlignTop, "Font");
|
|
|
+ canvas_set_font(canvas, FontSecondary);
|
|
|
+
|
|
|
+ const FONT_INFO* const font = available_fonts[scene_state->active_font];
|
|
|
+ ui_control_select_render(
|
|
|
+ canvas,
|
|
|
+ 0,
|
|
|
+ 74 - scene_state->y_offset,
|
|
|
+ SCREEN_WIDTH - UI_CONTROL_VSCROLL_WIDTH,
|
|
|
+ font->name,
|
|
|
+ scene_state->selected_control == FontSelect);
|
|
|
+
|
|
|
+ uint8_t font_x_offset =
|
|
|
+ SCREEN_WIDTH_CENTER -
|
|
|
+ (((font->charInfo[0].width + font->spacePixels) * FONT_TEST_STR_LENGTH) >> 1);
|
|
|
+ uint8_t font_y_offset = 108 - scene_state->y_offset - (font->height >> 1);
|
|
|
+ canvas_draw_str_ex(
|
|
|
+ canvas, font_x_offset, font_y_offset, FONT_TEST_STR, FONT_TEST_STR_LENGTH, font);
|
|
|
+
|
|
|
+ } else if(scene_state->selected_control < AutomationSwitch) {
|
|
|
+ canvas_set_font(canvas, FontPrimary);
|
|
|
+ canvas_draw_str_aligned(
|
|
|
+ canvas, 0, 128 - scene_state->y_offset, AlignLeft, AlignTop, "Notifications");
|
|
|
+ canvas_set_font(canvas, FontSecondary);
|
|
|
+
|
|
|
+ canvas_draw_str_aligned(
|
|
|
+ canvas, 0, 145 - scene_state->y_offset, AlignLeft, AlignTop, "Sound:");
|
|
|
+ ui_control_select_render(
|
|
|
+ canvas,
|
|
|
+ 36,
|
|
|
+ 138 - scene_state->y_offset,
|
|
|
+ SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
|
|
|
+ YES_NO_LIST[scene_state->notification_sound],
|
|
|
+ scene_state->selected_control == SoundSwitch);
|
|
|
+
|
|
|
+ canvas_draw_str_aligned(
|
|
|
+ canvas, 0, 163 - scene_state->y_offset, AlignLeft, AlignTop, "Vibro:");
|
|
|
+ ui_control_select_render(
|
|
|
+ canvas,
|
|
|
+ 36,
|
|
|
+ 156 - scene_state->y_offset,
|
|
|
+ SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
|
|
|
+ YES_NO_LIST[scene_state->notification_vibro],
|
|
|
+ scene_state->selected_control == VibroSwitch);
|
|
|
+ } else {
|
|
|
+ canvas_set_font(canvas, FontPrimary);
|
|
|
+ canvas_draw_str_aligned(
|
|
|
+ canvas, 0, 192 - scene_state->y_offset, AlignLeft, AlignTop, "Automation");
|
|
|
+ canvas_set_font(canvas, FontSecondary);
|
|
|
+
|
|
|
+ canvas_draw_str_aligned(
|
|
|
+ canvas, 0, 209 - scene_state->y_offset, AlignLeft, AlignTop, "Method:");
|
|
|
+ ui_control_select_render(
|
|
|
+ canvas,
|
|
|
+ 36,
|
|
|
+ 202 - scene_state->y_offset,
|
|
|
+ SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
|
|
|
+ AUTOMATION_LIST[scene_state->automation_method],
|
|
|
+ scene_state->selected_control == AutomationSwitch);
|
|
|
+
|
|
|
+ canvas_draw_str_aligned(
|
|
|
+ canvas, 0, 227 - scene_state->y_offset, AlignLeft, AlignTop, "Layout:");
|
|
|
+
|
|
|
+ ui_control_select_render(
|
|
|
+ canvas,
|
|
|
+ 36,
|
|
|
+ 220 - scene_state->y_offset,
|
|
|
+ SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH,
|
|
|
+ BAD_KB_LAYOUT_LIST[scene_state->automation_kb_layout],
|
|
|
+ scene_state->selected_control == BadKeyboardLayoutSelect);
|
|
|
+
|
|
|
+ ui_control_button_render(
|
|
|
+ canvas,
|
|
|
+ SCREEN_WIDTH_CENTER - 24,
|
|
|
+ 242 - scene_state->y_offset,
|
|
|
+ 48,
|
|
|
+ 13,
|
|
|
+ "Confirm",
|
|
|
+ scene_state->selected_control == ConfirmButton);
|
|
|
+ }
|
|
|
|
|
|
- canvas_set_font(canvas, FontPrimary);
|
|
|
- canvas_draw_str_aligned(
|
|
|
- canvas, 0, 0 - scene_state->y_offset, AlignLeft, AlignTop, "Timezone offset");
|
|
|
- canvas_set_font(canvas, FontSecondary);
|
|
|
-
|
|
|
- char tmp_str[4];
|
|
|
- two_digit_to_str(scene_state->tz_offset_hours, &tmp_str[0]);
|
|
|
- canvas_draw_str_aligned(canvas, 0, 17 - scene_state->y_offset, AlignLeft, AlignTop, "Hours:");
|
|
|
- ui_control_select_render(
|
|
|
- canvas,
|
|
|
- 36,
|
|
|
- 10 - scene_state->y_offset,
|
|
|
- SCREEN_WIDTH - 36,
|
|
|
- &tmp_str[0],
|
|
|
- scene_state->selected_control == HoursInput);
|
|
|
-
|
|
|
- two_digit_to_str(scene_state->tz_offset_minutes, &tmp_str[0]);
|
|
|
- canvas_draw_str_aligned(
|
|
|
- canvas, 0, 35 - scene_state->y_offset, AlignLeft, AlignTop, "Minutes:");
|
|
|
- ui_control_select_render(
|
|
|
- canvas,
|
|
|
- 36,
|
|
|
- 28 - scene_state->y_offset,
|
|
|
- SCREEN_WIDTH - 36,
|
|
|
- &tmp_str[0],
|
|
|
- scene_state->selected_control == MinutesInput);
|
|
|
-
|
|
|
- canvas_draw_icon(
|
|
|
- canvas,
|
|
|
- SCREEN_WIDTH_CENTER - 5,
|
|
|
- SCREEN_HEIGHT - 5 - scene_state->y_offset,
|
|
|
- &I_totp_arrow_bottom_10x5);
|
|
|
-
|
|
|
- canvas_set_font(canvas, FontPrimary);
|
|
|
- canvas_draw_str_aligned(canvas, 0, 64 - scene_state->y_offset, AlignLeft, AlignTop, "Font");
|
|
|
- canvas_set_font(canvas, FontSecondary);
|
|
|
-
|
|
|
- const FONT_INFO* const font = available_fonts[scene_state->active_font];
|
|
|
- ui_control_select_render(
|
|
|
- canvas,
|
|
|
- 0,
|
|
|
- 74 - scene_state->y_offset,
|
|
|
- SCREEN_WIDTH,
|
|
|
- font->name,
|
|
|
- scene_state->selected_control == FontSelect);
|
|
|
-
|
|
|
- uint8_t font_x_offset =
|
|
|
- SCREEN_WIDTH_CENTER -
|
|
|
- (((font->charInfo[0].width + font->spacePixels) * FONT_TEST_STR_LENGTH) >> 1);
|
|
|
- uint8_t font_y_offset = 108 - scene_state->y_offset - (font->height >> 1);
|
|
|
- canvas_draw_str_ex(
|
|
|
- canvas, font_x_offset, font_y_offset, FONT_TEST_STR, FONT_TEST_STR_LENGTH, font);
|
|
|
-
|
|
|
- canvas_draw_icon(
|
|
|
- canvas, SCREEN_WIDTH_CENTER - 5, 123 - scene_state->y_offset, &I_totp_arrow_bottom_10x5);
|
|
|
-
|
|
|
- canvas_set_font(canvas, FontPrimary);
|
|
|
- canvas_draw_str_aligned(
|
|
|
- canvas, 0, 128 - scene_state->y_offset, AlignLeft, AlignTop, "Notifications");
|
|
|
- canvas_set_font(canvas, FontSecondary);
|
|
|
-
|
|
|
- canvas_draw_str_aligned(canvas, 0, 145 - scene_state->y_offset, AlignLeft, AlignTop, "Sound:");
|
|
|
- ui_control_select_render(
|
|
|
- canvas,
|
|
|
- 36,
|
|
|
- 138 - scene_state->y_offset,
|
|
|
- SCREEN_WIDTH - 36,
|
|
|
- YES_NO_LIST[scene_state->notification_sound],
|
|
|
- scene_state->selected_control == SoundSwitch);
|
|
|
-
|
|
|
- canvas_draw_str_aligned(canvas, 0, 163 - scene_state->y_offset, AlignLeft, AlignTop, "Vibro:");
|
|
|
- ui_control_select_render(
|
|
|
- canvas,
|
|
|
- 36,
|
|
|
- 156 - scene_state->y_offset,
|
|
|
- SCREEN_WIDTH - 36,
|
|
|
- YES_NO_LIST[scene_state->notification_vibro],
|
|
|
- scene_state->selected_control == VibroSwitch);
|
|
|
-
|
|
|
- canvas_draw_icon(
|
|
|
- canvas, SCREEN_WIDTH_CENTER - 5, 187 - scene_state->y_offset, &I_totp_arrow_bottom_10x5);
|
|
|
-
|
|
|
- canvas_set_font(canvas, FontPrimary);
|
|
|
- canvas_draw_str_aligned(
|
|
|
- canvas, 0, 192 - scene_state->y_offset, AlignLeft, AlignTop, "Automation");
|
|
|
- canvas_set_font(canvas, FontSecondary);
|
|
|
-
|
|
|
- canvas_draw_str_aligned(
|
|
|
- canvas, 0, 209 - scene_state->y_offset, AlignLeft, AlignTop, "BadUSB:");
|
|
|
- ui_control_select_render(
|
|
|
- canvas,
|
|
|
- 36,
|
|
|
- 202 - scene_state->y_offset,
|
|
|
- SCREEN_WIDTH - 36,
|
|
|
- ON_OFF_LIST[scene_state->badusb_enabled],
|
|
|
- scene_state->selected_control == BadUsbSwitch);
|
|
|
-
|
|
|
-#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
- canvas_draw_str_aligned(canvas, 0, 227 - scene_state->y_offset, AlignLeft, AlignTop, "BadBT:");
|
|
|
- ui_control_select_render(
|
|
|
- canvas,
|
|
|
- 36,
|
|
|
- 220 - scene_state->y_offset,
|
|
|
- SCREEN_WIDTH - 36,
|
|
|
- ON_OFF_LIST[scene_state->badbt_enabled],
|
|
|
- scene_state->selected_control == BadBtSwitch);
|
|
|
-#endif
|
|
|
-
|
|
|
- ui_control_button_render(
|
|
|
- canvas,
|
|
|
- SCREEN_WIDTH_CENTER - 24,
|
|
|
-#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
- 242 - scene_state->y_offset,
|
|
|
-#else
|
|
|
- 229 - scene_state->y_offset,
|
|
|
-#endif
|
|
|
- 48,
|
|
|
- 13,
|
|
|
- "Confirm",
|
|
|
- scene_state->selected_control == ConfirmButton);
|
|
|
+ ui_control_vscroll_render(
|
|
|
+ canvas, SCREEN_WIDTH - 3, 0, SCREEN_HEIGHT, scene_state->selected_control, ConfirmButton);
|
|
|
}
|
|
|
|
|
|
bool totp_scene_app_settings_handle_event(
|
|
|
@@ -267,14 +272,17 @@ bool totp_scene_app_settings_handle_event(
|
|
|
scene_state->notification_sound = !scene_state->notification_sound;
|
|
|
} else if(scene_state->selected_control == VibroSwitch) {
|
|
|
scene_state->notification_vibro = !scene_state->notification_vibro;
|
|
|
- } else if(scene_state->selected_control == BadUsbSwitch) {
|
|
|
- scene_state->badusb_enabled = !scene_state->badusb_enabled;
|
|
|
- }
|
|
|
-#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
- else if(scene_state->selected_control == BadBtSwitch) {
|
|
|
- scene_state->badbt_enabled = !scene_state->badbt_enabled;
|
|
|
+ } else if(scene_state->selected_control == AutomationSwitch) {
|
|
|
+ totp_roll_value_uint8_t(
|
|
|
+ &scene_state->automation_method,
|
|
|
+ 1,
|
|
|
+ 0,
|
|
|
+ AUTOMATION_LIST_MAX_INDEX,
|
|
|
+ RollOverflowBehaviorRoll);
|
|
|
+ } else if(scene_state->selected_control == BadKeyboardLayoutSelect) {
|
|
|
+ totp_roll_value_uint8_t(
|
|
|
+ &scene_state->automation_kb_layout, 1, 0, 1, RollOverflowBehaviorRoll);
|
|
|
}
|
|
|
-#endif
|
|
|
break;
|
|
|
case InputKeyLeft:
|
|
|
if(scene_state->selected_control == HoursInput) {
|
|
|
@@ -294,14 +302,17 @@ bool totp_scene_app_settings_handle_event(
|
|
|
scene_state->notification_sound = !scene_state->notification_sound;
|
|
|
} else if(scene_state->selected_control == VibroSwitch) {
|
|
|
scene_state->notification_vibro = !scene_state->notification_vibro;
|
|
|
- } else if(scene_state->selected_control == BadUsbSwitch) {
|
|
|
- scene_state->badusb_enabled = !scene_state->badusb_enabled;
|
|
|
- }
|
|
|
-#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
- else if(scene_state->selected_control == BadBtSwitch) {
|
|
|
- scene_state->badbt_enabled = !scene_state->badbt_enabled;
|
|
|
+ } else if(scene_state->selected_control == AutomationSwitch) {
|
|
|
+ totp_roll_value_uint8_t(
|
|
|
+ &scene_state->automation_method,
|
|
|
+ -1,
|
|
|
+ 0,
|
|
|
+ AUTOMATION_LIST_MAX_INDEX,
|
|
|
+ RollOverflowBehaviorRoll);
|
|
|
+ } else if(scene_state->selected_control == BadKeyboardLayoutSelect) {
|
|
|
+ totp_roll_value_uint8_t(
|
|
|
+ &scene_state->automation_kb_layout, -1, 0, 1, RollOverflowBehaviorRoll);
|
|
|
}
|
|
|
-#endif
|
|
|
break;
|
|
|
case InputKeyOk:
|
|
|
break;
|
|
|
@@ -322,14 +333,9 @@ bool totp_scene_app_settings_handle_event(
|
|
|
(scene_state->notification_sound ? NotificationMethodSound : NotificationMethodNone) |
|
|
|
(scene_state->notification_vibro ? NotificationMethodVibro : NotificationMethodNone);
|
|
|
|
|
|
- plugin_state->automation_method = scene_state->badusb_enabled ? AutomationMethodBadUsb :
|
|
|
- AutomationMethodNone;
|
|
|
-#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
- plugin_state->automation_method |= scene_state->badbt_enabled ? AutomationMethodBadBt :
|
|
|
- AutomationMethodNone;
|
|
|
-#endif
|
|
|
-
|
|
|
+ plugin_state->automation_method = scene_state->automation_method;
|
|
|
plugin_state->active_font_index = scene_state->active_font;
|
|
|
+ plugin_state->automation_kb_layout = scene_state->automation_kb_layout;
|
|
|
|
|
|
if(!totp_config_file_update_user_settings(plugin_state)) {
|
|
|
totp_dialogs_config_updating_error(plugin_state);
|
|
|
@@ -337,7 +343,8 @@ bool totp_scene_app_settings_handle_event(
|
|
|
}
|
|
|
|
|
|
#ifdef TOTP_BADBT_TYPE_ENABLED
|
|
|
- if(!scene_state->badbt_enabled && plugin_state->bt_type_code_worker_context != NULL) {
|
|
|
+ if((scene_state->automation_method & AutomationMethodBadBt) == 0 &&
|
|
|
+ plugin_state->bt_type_code_worker_context != NULL) {
|
|
|
totp_bt_type_code_worker_free(plugin_state->bt_type_code_worker_context);
|
|
|
plugin_state->bt_type_code_worker_context = NULL;
|
|
|
}
|