From 99b8c084b6d01301e31f46f1086af1c051a0d038 Mon Sep 17 00:00:00 2001 From: Matthew <113921492+MatthewKuKanich@users.noreply.github.com> Date: Fri, 8 Sep 2023 17:52:43 -0400 Subject: [PATCH 1/3] Update ibutton.c comments --- applications/main/ibutton/ibutton.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/applications/main/ibutton/ibutton.c b/applications/main/ibutton/ibutton.c index f3ac2c7391..3075d3acd7 100644 --- a/applications/main/ibutton/ibutton.c +++ b/applications/main/ibutton/ibutton.c @@ -40,11 +40,13 @@ static void ibutton_make_app_folder(iButton* ibutton) { furi_record_close(RECORD_STORAGE); } +// Callback function for handling RPC commands static void ibutton_rpc_command_callback(RpcAppSystemEvent event, void* context) { furi_assert(context); iButton* ibutton = context; if(event == RpcAppEventSessionClose) { + // Send a custom event and detach from RPC on session close, load, and exit view_dispatcher_send_custom_event( ibutton->view_dispatcher, iButtonCustomEventRpcSessionClose); rpc_system_app_set_callback(ibutton->rpc, NULL, NULL); @@ -61,6 +63,7 @@ static void ibutton_rpc_command_callback(RpcAppSystemEvent event, void* context) bool ibutton_custom_event_callback(void* context, uint32_t event) { furi_assert(context); iButton* ibutton = context; + return scene_manager_handle_custom_event(ibutton->scene_manager, event); } @@ -76,6 +79,7 @@ void ibutton_tick_event_callback(void* context) { scene_manager_handle_tick_event(ibutton->scene_manager); } +// Allocate memory and initialize the iButton structure iButton* ibutton_alloc() { iButton* ibutton = malloc(sizeof(iButton)); @@ -133,6 +137,7 @@ iButton* ibutton_alloc() { void ibutton_free(iButton* ibutton) { furi_assert(ibutton); + // Remove and free views, then free the view dispatcher and scene manager view_dispatcher_remove_view(ibutton->view_dispatcher, iButtonViewLoading); loading_free(ibutton->loading); @@ -154,6 +159,7 @@ void ibutton_free(iButton* ibutton) { view_dispatcher_free(ibutton->view_dispatcher); scene_manager_free(ibutton->scene_manager); + // Close records and free worker and key furi_record_close(RECORD_NOTIFICATION); ibutton->notifications = NULL; @@ -176,6 +182,7 @@ void ibutton_free(iButton* ibutton) { bool ibutton_load_key(iButton* ibutton) { view_dispatcher_switch_to_view(ibutton->view_dispatcher, iButtonViewLoading); + // Attempt to load the key using protocols const bool success = ibutton_protocols_load( ibutton->protocols, ibutton->key, furi_string_get_cstr(ibutton->file_path)); @@ -183,6 +190,7 @@ bool ibutton_load_key(iButton* ibutton) { dialog_message_show_storage_error(ibutton->dialogs, "Cannot load\nkey file"); } else { + // Extract and store the key name FuriString* tmp = furi_string_alloc(); path_extract_filename(ibutton->file_path, tmp, true); @@ -194,6 +202,7 @@ bool ibutton_load_key(iButton* ibutton) { return success; } +// Select and load a key for iButton using the file browser bool ibutton_select_and_load_key(iButton* ibutton) { DialogsFileBrowserOptions browser_options; bool success = false; @@ -254,6 +263,7 @@ void ibutton_notification_message(iButton* ibutton, uint32_t message) { notification_message(ibutton->notifications, ibutton_notification_sequences[message]); } +// Callback functions for submenu and widget actions void ibutton_submenu_callback(void* context, uint32_t index) { iButton* ibutton = context; view_dispatcher_send_custom_event(ibutton->view_dispatcher, index); @@ -278,10 +288,12 @@ int32_t ibutton_app(char* arg) { if(sscanf(arg, "RPC %lX", (uint32_t*)&ibutton->rpc) == 1) { FURI_LOG_D(TAG, "Running in RPC mode"); + // Attach to RPC and handle RPC events rpc_system_app_set_callback(ibutton->rpc, ibutton_rpc_command_callback, ibutton); rpc_system_app_send_started(ibutton->rpc); } else { + // Set the file_path and attempt to load the key furi_string_set(ibutton->file_path, (const char*)arg); key_loaded = ibutton_load_key(ibutton); } @@ -294,6 +306,7 @@ int32_t ibutton_app(char* arg) { dolphin_deed(DolphinDeedIbuttonEmulate); } else { + // Attach to GUI (fullscreen) and set the initial scene based on key loading view_dispatcher_attach_to_gui( ibutton->view_dispatcher, ibutton->gui, ViewDispatcherTypeFullscreen); if(key_loaded) { //-V547 @@ -311,6 +324,7 @@ int32_t ibutton_app(char* arg) { } if(ibutton->rpc) { + // Detach from RPC and handle RPC exit rpc_system_app_set_callback(ibutton->rpc, NULL, NULL); rpc_system_app_send_exited(ibutton->rpc); } From 09986b33a7ff1912a1167f2427eddc8adfe82e6f Mon Sep 17 00:00:00 2001 From: MatthewKuKanich Date: Fri, 8 Sep 2023 23:23:02 -0400 Subject: [PATCH 2/3] commit new compact menu style --- .../xtreme_app_scene_interface_mainmenu.c | 1 + applications/services/gui/modules/menu.c | 74 ++++++++++++++++++- lib/xtreme/xtreme.h | 1 + 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_mainmenu.c b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_mainmenu.c index 98d9f0f35d..ccebe47400 100644 --- a/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_mainmenu.c +++ b/applications/main/xtreme_app/scenes/xtreme_app_scene_interface_mainmenu.c @@ -22,6 +22,7 @@ const char* const menu_style_names[MenuStyleCount] = { "Vertical", "C64", "Eurocorp", + "Compact", }; static void xtreme_app_scene_interface_mainmenu_menu_style_changed(VariableItem* item) { XtremeApp* app = variable_item_get_context(item); diff --git a/applications/services/gui/modules/menu.c b/applications/services/gui/modules/menu.c index 7fbc69d9b0..f21fa27206 100644 --- a/applications/services/gui/modules/menu.c +++ b/applications/services/gui/modules/menu.c @@ -362,6 +362,48 @@ static void menu_draw_callback(Canvas* canvas, void* _model) { } break; } + case MenuStyleCompact: { + FuriString* memstr = furi_string_alloc(); + + size_t index; + size_t y_off, x_off; + + canvas_set_font(canvas, FontKeyboard); + + for(size_t i = 0; i < 2; i++) { + for(size_t j = 0; j < 7; j++) { // Change 5 to 6 to accommodate the extra row + index = i * 7 + j + (position - (position % 14)); // Change 10 to 12 + if(index >= items_count) continue; + y_off = (9 * j) - 4; // Adjust the y offset + x_off = 64 * i; + bool selected = index == position; + size_t scroll_counter = menu_scroll_counter(model, selected); + if(selected) { + canvas_draw_box(canvas, x_off, y_off + 4, 64, 9); + canvas_set_color(canvas, ColorWhite); + } + item = MenuItemArray_get(model->items, index); + menu_short_name(item, name); + + FuriString* item_str = furi_string_alloc(); + + furi_string_printf(item_str, "%s", furi_string_get_cstr(name)); + + elements_scrollable_text_line( + canvas, x_off + 2, y_off + 12, 64, item_str, scroll_counter, false); + + furi_string_free(item_str); + + if(selected) { + canvas_set_color(canvas, ColorBlack); + } + } + } + + furi_string_free(memstr); + + break; + } default: break; } @@ -612,6 +654,13 @@ static void menu_process_up(Menu* menu) { position = count - 1; } break; + case MenuStyleCompact: + if(position > 0) { + position--; + } else { + position = count - 1; + } + break; default: break; } @@ -660,6 +709,13 @@ static void menu_process_down(Menu* menu) { position = 0; } break; + case MenuStyleCompact: + if(position < count - 1) { + position++; + } else { + position = 0; + } + break; default: break; } @@ -712,6 +768,14 @@ static void menu_process_left(Menu* menu) { } else if((position % 10) >= 5) { position = position - 5; } + break; + case MenuStyleCompact: + if((position % 16) < 8) { + position = position + 7; + } else if((position % 16) >= 8) { + position = position - 7; + } + break; default: break; } @@ -769,6 +833,14 @@ static void menu_process_right(Menu* menu) { } else if((position % 10) >= 5 && position < count) { position = position - 5; } + break; + case MenuStyleCompact: + if(position >= (count - count) && (position % 16) < 8) { + position = position + 7; + } else if((position % 16) >= 8 && position < count) { + position = position - 7; + } + break; default: break; } @@ -793,4 +865,4 @@ static void menu_process_ok(Menu* menu) { if(item && item->callback) { item->callback(item->callback_context, item->index); } -} +} \ No newline at end of file diff --git a/lib/xtreme/xtreme.h b/lib/xtreme/xtreme.h index 16b4d57d22..f11d6e70fe 100644 --- a/lib/xtreme/xtreme.h +++ b/lib/xtreme/xtreme.h @@ -33,6 +33,7 @@ typedef enum { MenuStyleVertical, MenuStyleC64, MenuStyleEurocorp, + MenuStyleCompact, MenuStyleCount, } MenuStyle; From 58d782f7f2b9c00cb853a9148bc75180bf55e19f Mon Sep 17 00:00:00 2001 From: MatthewKuKanich Date: Fri, 8 Sep 2023 23:27:10 -0400 Subject: [PATCH 3/3] commit new compact menu style --- applications/services/gui/modules/menu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/applications/services/gui/modules/menu.c b/applications/services/gui/modules/menu.c index f21fa27206..251e4605a2 100644 --- a/applications/services/gui/modules/menu.c +++ b/applications/services/gui/modules/menu.c @@ -371,10 +371,10 @@ static void menu_draw_callback(Canvas* canvas, void* _model) { canvas_set_font(canvas, FontKeyboard); for(size_t i = 0; i < 2; i++) { - for(size_t j = 0; j < 7; j++) { // Change 5 to 6 to accommodate the extra row - index = i * 7 + j + (position - (position % 14)); // Change 10 to 12 + for(size_t j = 0; j < 7; j++) { + index = i * 7 + j + (position - (position % 14)); if(index >= items_count) continue; - y_off = (9 * j) - 4; // Adjust the y offset + y_off = (9 * j) - 4; x_off = 64 * i; bool selected = index == position; size_t scroll_counter = menu_scroll_counter(model, selected);