From 4ee5789168d581a1b5f7cb1555e8dc087a13b907 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Tue, 29 Oct 2024 18:19:15 +0000 Subject: [PATCH] GUI: Ascii input for ByteInput --- CHANGELOG.md | 1 + .../services/gui/modules/byte_input.c | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8c8a5286b..88f7a3a688 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -89,6 +89,7 @@ - OFW: Dolphin: Happy mode in Desktop settings (by @portasynthinca3) - OFW: CLI: Improvements part I, `neofetch` command (by @portasynthinca3), fix for lab.flipper.net (by @xMasterX) - GUI: + - ByteInput supports ASCII input (by @Willy-JL) - OFW: Add up and down button drawing functions to GUI elements (by @DerSkythe) - OFW: Extended icon draw function in Canvas (by @RebornedBrain) - OFW: RPC: Support 5V on GPIO control for ext. modules (by @gsurkov) diff --git a/applications/services/gui/modules/byte_input.c b/applications/services/gui/modules/byte_input.c index 3e23ee6c14..c9f6896625 100644 --- a/applications/services/gui/modules/byte_input.c +++ b/applications/services/gui/modules/byte_input.c @@ -726,6 +726,51 @@ static bool byte_input_view_input_callback(InputEvent* event, void* context) { return consumed; } +static bool byte_input_view_ascii_callback(AsciiEvent* event, void* context) { + ByteInput* byte_input = context; + furi_assert(byte_input); + + switch(event->value) { + case AsciiValueDC3: // Right + case AsciiValueDC4: // Left + with_view_model( + byte_input->view, + ByteInputModel * model, + { + if(event->value == AsciiValueDC3) { + byte_input_inc_selected_byte_mini(model); + } else { + byte_input_dec_selected_byte_mini(model); + } + }, + true); + return true; + default: // Look in keyboard + for(size_t r = 0; r < keyboard_row_count; r++) { + const ByteInputKey* row = byte_input_get_row(r); + uint8_t size = byte_input_get_row_size(r); + for(size_t key = 0; key < size; key++) { + char value = row[key].value; + if(event->value == value) { + with_view_model( + byte_input->view, + ByteInputModel * model, + { + model->selected_row = r; + model->selected_column = key; + byte_input_handle_ok(model); + }, + true); + return true; + } + } + } + break; + } + + return false; +} + /** Reset all input-related data in model * * @param model The model @@ -747,6 +792,7 @@ ByteInput* byte_input_alloc(void) { view_allocate_model(byte_input->view, ViewModelTypeLocking, sizeof(ByteInputModel)); view_set_draw_callback(byte_input->view, byte_input_view_draw_callback); view_set_input_callback(byte_input->view, byte_input_view_input_callback); + view_set_ascii_callback(byte_input->view, byte_input_view_ascii_callback); with_view_model( byte_input->view,