From 649887fe0f1b8c8123a77b3d5ac36de1acafb667 Mon Sep 17 00:00:00 2001 From: Matt Van Zanten Date: Sun, 2 Oct 2022 08:18:01 -0700 Subject: [PATCH 1/6] progress, adding on the fly --- .../scene/flipfrid_scene_select_field.c | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c index 03411b2f4..ebd22f7cb 100644 --- a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c +++ b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c @@ -1,42 +1,51 @@ #include "flipfrid_scene_select_field.h" void flipfrid_center_displayed_key(FlipFridState* context, uint8_t index) { - const char* key_cstr = string_get_cstr(context->data_str); + //const char* key_cstr = string_get_cstr(context->data_str); uint8_t str_index = (index * 3); + int data_len = sizeof(context->data) / sizeof(context->data[0]); + + char str[20]; + int index_temp = 0; + + for(uint8_t i = 0; i < data_len; i++) { + index_temp += snprintf(&str[index_temp], 20-index_temp, "%x", context->data[i]); + } + char display_menu[17] = { 'X', 'X', ' ', 'X', 'X', ' ', '<', 'X', 'X', '>', ' ', 'X', 'X', ' ', 'X', 'X', '\0'}; if(index > 1) { - display_menu[0] = key_cstr[str_index - 6]; - display_menu[1] = key_cstr[str_index - 5]; + display_menu[0] = str[str_index - 6]; + display_menu[1] = str[str_index - 5]; } else { display_menu[0] = ' '; display_menu[1] = ' '; } if(index > 0) { - display_menu[3] = key_cstr[str_index - 3]; - display_menu[4] = key_cstr[str_index - 2]; + display_menu[3] = str[str_index - 3]; + display_menu[4] = str[str_index - 2]; } else { display_menu[3] = ' '; display_menu[4] = ' '; } - display_menu[7] = key_cstr[str_index]; - display_menu[8] = key_cstr[str_index + 1]; + display_menu[7] = str[str_index]; + display_menu[8] = str[str_index + 1]; - if((str_index + 4) <= (uint8_t)strlen(key_cstr)) { - display_menu[11] = key_cstr[str_index + 3]; - display_menu[12] = key_cstr[str_index + 4]; + if((str_index + 4) <= (uint8_t)strlen(str)) { + display_menu[11] = str[str_index + 3]; + display_menu[12] = str[str_index + 4]; } else { display_menu[11] = ' '; display_menu[12] = ' '; } - if((str_index + 8) <= (uint8_t)strlen(key_cstr)) { - display_menu[14] = key_cstr[str_index + 6]; - display_menu[15] = key_cstr[str_index + 7]; + if((str_index + 8) <= (uint8_t)strlen(str)) { + display_menu[14] = str[str_index + 6]; + display_menu[15] = str[str_index + 7]; } else { display_menu[14] = ' '; display_menu[15] = ' '; @@ -62,6 +71,7 @@ void flipfrid_scene_select_field_on_event(FlipFridEvent event, FlipFridState* co if(event.evt_type == EventTypeKey) { if(event.input_type == InputTypeShort) { const char* key_cstr = string_get_cstr(context->data_str); + int data_len = sizeof(context->data) / sizeof(context->data[0]); // don't look, it's ugly but I'm a python dev so... uint8_t nb_bytes = 0; @@ -73,7 +83,23 @@ void flipfrid_scene_select_field_on_event(FlipFridEvent event, FlipFridState* co switch(event.key) { case InputKeyDown: + FURI_LOG_D(TAG, "Size down: %d", data_len); + for(uint8_t i = 0; i < data_len; i++) { + FURI_LOG_D(TAG, "in for down: %d", i); + if(context->key_index == i) { + FURI_LOG_D(TAG, "in for down if: %d", context->data[i]); + context->data[i] = (context->data[i] - 1); + } + } + break; case InputKeyUp: + for(uint8_t i = 0; i < data_len; i++) { + FURI_LOG_D(TAG, "in for down: %d", i); + if(context->key_index == i) { + FURI_LOG_D(TAG, "in for down if: %d", context->data[i]); + context->data[i] = (context->data[i] + 1); + } + } break; case InputKeyLeft: if(context->key_index > 0) { From 1e63f57bf74036577f06002cdf6d974867f84b5d Mon Sep 17 00:00:00 2001 From: mvanzanten Date: Sun, 2 Oct 2022 12:06:06 -0700 Subject: [PATCH 2/6] working version, change bits on the fly --- .../scene/flipfrid_scene_select_field.c | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c index ebd22f7cb..e936ecfb6 100644 --- a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c +++ b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c @@ -1,51 +1,52 @@ #include "flipfrid_scene_select_field.h" void flipfrid_center_displayed_key(FlipFridState* context, uint8_t index) { - //const char* key_cstr = string_get_cstr(context->data_str); + char key_cstr[18]; uint8_t str_index = (index * 3); int data_len = sizeof(context->data) / sizeof(context->data[0]); - - char str[20]; - int index_temp = 0; + int key_index = 0; for(uint8_t i = 0; i < data_len; i++) { - index_temp += snprintf(&str[index_temp], 20-index_temp, "%x", context->data[i]); + if(context->data[i] > 9 ) { + key_index += snprintf(&key_cstr[key_index], 18-key_index, "%X ", context->data[i]); + } else { + key_index += snprintf(&key_cstr[key_index], 18-key_index, "0%X ", context->data[i]); + } } - char display_menu[17] = { 'X', 'X', ' ', 'X', 'X', ' ', '<', 'X', 'X', '>', ' ', 'X', 'X', ' ', 'X', 'X', '\0'}; if(index > 1) { - display_menu[0] = str[str_index - 6]; - display_menu[1] = str[str_index - 5]; + display_menu[0] = key_cstr[str_index - 6]; + display_menu[1] = key_cstr[str_index - 5]; } else { display_menu[0] = ' '; display_menu[1] = ' '; } if(index > 0) { - display_menu[3] = str[str_index - 3]; - display_menu[4] = str[str_index - 2]; + display_menu[3] = key_cstr[str_index - 3]; + display_menu[4] = key_cstr[str_index - 2]; } else { display_menu[3] = ' '; display_menu[4] = ' '; } - display_menu[7] = str[str_index]; - display_menu[8] = str[str_index + 1]; + display_menu[7] = key_cstr[str_index]; + display_menu[8] = key_cstr[str_index + 1]; - if((str_index + 4) <= (uint8_t)strlen(str)) { - display_menu[11] = str[str_index + 3]; - display_menu[12] = str[str_index + 4]; + if((str_index + 4) <= (uint8_t)strlen(key_cstr)) { + display_menu[11] = key_cstr[str_index + 3]; + display_menu[12] = key_cstr[str_index + 4]; } else { display_menu[11] = ' '; display_menu[12] = ' '; } - if((str_index + 8) <= (uint8_t)strlen(str)) { - display_menu[14] = str[str_index + 6]; - display_menu[15] = str[str_index + 7]; + if((str_index + 8) <= (uint8_t)strlen(key_cstr)) { + display_menu[14] = key_cstr[str_index + 6]; + display_menu[15] = key_cstr[str_index + 7]; } else { display_menu[14] = ' '; display_menu[15] = ' '; @@ -143,5 +144,5 @@ void flipfrid_scene_select_field_on_draw(Canvas* canvas, FlipFridState* context) flipfrid_center_displayed_key(context, context->key_index); canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned( - canvas, 64, 40, AlignCenter, AlignTop, string_get_cstr(context->notification_msg)); + canvas, 64, 45, AlignCenter, AlignTop, string_get_cstr(context->notification_msg)); } From d6b7fae7e489de3564b52a1172089c16c68c4f11 Mon Sep 17 00:00:00 2001 From: Matt Van Zanten Date: Mon, 3 Oct 2022 10:29:04 -0700 Subject: [PATCH 3/6] working version of the on the fly bit switcher --- .../flipfrid/scene/flipfrid_scene_select_field.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c index e936ecfb6..28652479c 100644 --- a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c +++ b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c @@ -2,15 +2,20 @@ void flipfrid_center_displayed_key(FlipFridState* context, uint8_t index) { char key_cstr[18]; + uint8_t key_len = 18; uint8_t str_index = (index * 3); int data_len = sizeof(context->data) / sizeof(context->data[0]); int key_index = 0; + if(context->proto == EM4100) { + key_len = 16; + } + for(uint8_t i = 0; i < data_len; i++) { - if(context->data[i] > 9 ) { - key_index += snprintf(&key_cstr[key_index], 18-key_index, "%X ", context->data[i]); + if(context->data[i] < 9 ) { + key_index += snprintf(&key_cstr[key_index], key_len-key_index, "0%X ", context->data[i]); } else { - key_index += snprintf(&key_cstr[key_index], 18-key_index, "0%X ", context->data[i]); + key_index += snprintf(&key_cstr[key_index], key_len-key_index, "%X ", context->data[i]); } } From 8b0fa6d0b107a00d0fcd599f19dec5ee15833fcc Mon Sep 17 00:00:00 2001 From: Matt Van Zanten Date: Mon, 3 Oct 2022 11:07:16 -0700 Subject: [PATCH 4/6] running fbt format --- .../plugins/flipfrid/scene/flipfrid_scene_select_field.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c index 28652479c..3e0810174 100644 --- a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c +++ b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c @@ -12,10 +12,12 @@ void flipfrid_center_displayed_key(FlipFridState* context, uint8_t index) { } for(uint8_t i = 0; i < data_len; i++) { - if(context->data[i] < 9 ) { - key_index += snprintf(&key_cstr[key_index], key_len-key_index, "0%X ", context->data[i]); + if(context->data[i] < 9) { + key_index += + snprintf(&key_cstr[key_index], key_len - key_index, "0%X ", context->data[i]); } else { - key_index += snprintf(&key_cstr[key_index], key_len-key_index, "%X ", context->data[i]); + key_index += + snprintf(&key_cstr[key_index], key_len - key_index, "%X ", context->data[i]); } } From 71589b28a7c9d4e7703afd1907aa3b7401e56c53 Mon Sep 17 00:00:00 2001 From: Matt Van Zanten Date: Mon, 3 Oct 2022 11:09:51 -0700 Subject: [PATCH 5/6] removing debug logs --- .../plugins/flipfrid/scene/flipfrid_scene_select_field.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c index 3e0810174..e81046eb6 100644 --- a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c +++ b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c @@ -91,20 +91,15 @@ void flipfrid_scene_select_field_on_event(FlipFridEvent event, FlipFridState* co switch(event.key) { case InputKeyDown: - FURI_LOG_D(TAG, "Size down: %d", data_len); for(uint8_t i = 0; i < data_len; i++) { - FURI_LOG_D(TAG, "in for down: %d", i); if(context->key_index == i) { - FURI_LOG_D(TAG, "in for down if: %d", context->data[i]); context->data[i] = (context->data[i] - 1); } } break; case InputKeyUp: for(uint8_t i = 0; i < data_len; i++) { - FURI_LOG_D(TAG, "in for down: %d", i); if(context->key_index == i) { - FURI_LOG_D(TAG, "in for down if: %d", context->data[i]); context->data[i] = (context->data[i] + 1); } } From 9403128a038d7877a43c394572f774757a94e308 Mon Sep 17 00:00:00 2001 From: Matt Van Zanten Date: Mon, 3 Oct 2022 11:32:10 -0700 Subject: [PATCH 6/6] moving to center nicer --- .../plugins/flipfrid/scene/flipfrid_scene_select_field.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c index e81046eb6..6e4d5c6c4 100644 --- a/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c +++ b/applications/plugins/flipfrid/scene/flipfrid_scene_select_field.c @@ -146,5 +146,5 @@ void flipfrid_scene_select_field_on_draw(Canvas* canvas, FlipFridState* context) flipfrid_center_displayed_key(context, context->key_index); canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned( - canvas, 64, 45, AlignCenter, AlignTop, string_get_cstr(context->notification_msg)); + canvas, 64, 44, AlignCenter, AlignTop, string_get_cstr(context->notification_msg)); }