From ce83dc690c386d669229b2601cedff97c165fdd2 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Wed, 17 Jan 2024 22:46:36 +0000 Subject: [PATCH] Feed ASCII events from "input keyboard" --- applications/services/input/input_cli.c | 109 +++++++++++------------- 1 file changed, 51 insertions(+), 58 deletions(-) diff --git a/applications/services/input/input_cli.c b/applications/services/input/input_cli.c index d82e90e98..5f5c233e6 100644 --- a/applications/services/input/input_cli.c +++ b/applications/services/input/input_cli.c @@ -3,19 +3,14 @@ #include #include #include -#include -#include -#include -#include -#include static void input_cli_usage() { printf("Usage:\r\n"); printf("input \r\n"); printf("Cmd list:\r\n"); printf("\tdump\t\t\t - dump input events\r\n"); + printf("\tkeyboard\t\t - use keyboard feedback to control flipper\r\n"); printf("\tsend \t - send input event\r\n"); - printf("\tkeyboard\t\t - read keyboard input and control flipper with it\r\n"); } static void input_cli_dump_events_callback(const void* value, void* ctx) { @@ -48,23 +43,15 @@ static void input_cli_dump(Cli* cli, FuriString* args, Input* input) { static void input_cli_keyboard(Cli* cli, FuriString* args, Input* input) { UNUSED(args); - Gui* gui = furi_record_open(RECORD_GUI); - NotificationApp* notification = furi_record_open(RECORD_NOTIFICATION); + FuriPubSub* ascii_events = furi_record_open(RECORD_ASCII_EVENTS); printf("Using console keyboard feedback for flipper input\r\n"); printf("\r\nUsage:\r\n"); printf("\tMove = Arrows\r\n"); printf("\tOk = Enter\r\n"); - printf("\tBack = Backspace\r\n"); - printf("\tToggle hold for next key = Space\r\n"); - - printf("\r\nIn Keyboard:\r\n"); - printf("\tType normally on PC Keyboard\r\n"); - printf("\tQuit = Ctrl + Q\r\n"); - printf("\tSelect All = Ctrl + A\r\n"); - printf("\tMove Cursor = Arrows\r\n"); - printf("\tSave Text = Enter\r\n"); + printf("\tBack = Backspace/Ctrl + Q\r\n"); + printf("\tEnable hold for next key = Space (press twice to send space key)\r\n"); printf("\r\nPress CTRL+C to stop\r\n"); bool hold = false; @@ -72,60 +59,66 @@ static void input_cli_keyboard(Cli* cli, FuriString* args, Input* input) { char in_chr = cli_getc(cli); if(in_chr == CliSymbolAsciiETX) break; InputKey send_key = InputKeyMAX; + uint8_t send_ascii = AsciiValueNUL; - ViewPort* view_port = gui->ongoing_input_view_port; - if(view_port && view_port->input_callback == view_dispatcher_input_callback) { - ViewDispatcher* view_dispatcher = view_port->input_callback_context; - if(view_dispatcher) { - View* view = view_dispatcher->current_view; - if(view && view->input_callback == text_input_view_input_callback) { - TextInput* text_input = view->context; - if(text_input) { - if(in_chr == 0x11) { // Ctrl Q = Close text input - send_key = InputKeyBack; - } else if(text_input_insert_character(text_input, in_chr)) { - notification_message(notification, &sequence_display_backlight_on); - continue; - } - } + switch(in_chr) { + case CliSymbolAsciiEsc: // Escape code for arrows + if(!cli_read(cli, (uint8_t*)&in_chr, 1) || in_chr != '[') break; + if(!cli_read(cli, (uint8_t*)&in_chr, 1)) break; + if(in_chr >= 'A' && in_chr <= 'D') { // Arrows = Dpad + if(hold) { + send_key = InputKeyUp + (in_chr - 'A'); // Same order as InputKey + } else { + send_ascii = AsciiValueDC1 + (in_chr - 'A'); // Same order as DC } } - } - - if(send_key == InputKeyMAX) { - switch(in_chr) { - case CliSymbolAsciiEsc: // Escape code for arrows - if(!cli_read(cli, (uint8_t*)&in_chr, 1) || in_chr != '[') break; - if(!cli_read(cli, (uint8_t*)&in_chr, 1)) break; - if(in_chr >= 'A' && in_chr <= 'D') { // Arrows = Dpad - send_key = in_chr - 'A'; // Arrows in same order as InputKey - } - break; - case CliSymbolAsciiBackspace: // (minicom) Backspace = Back - case CliSymbolAsciiDel: // (putty/picocom) Backspace = Back + break; + case CliSymbolAsciiBackspace: // (minicom) Backspace = Back + case CliSymbolAsciiDel: // (putty/picocom) Backspace = Back + if(hold) { send_key = InputKeyBack; - break; - case CliSymbolAsciiSpace: // Space = Toggle hold next key - hold = !hold; - break; - case CliSymbolAsciiCR: // Enter = Ok - send_key = InputKeyOk; - break; - default: - printf("ignoring key: %u\r\n", in_chr); - break; + } else { + send_ascii = AsciiValueBS; } + break; + case 0x11: // Ctrl Q = Escape (no Esc key over CLI) + if(hold) { + send_key = InputKeyBack; + } else { + send_ascii = AsciiValueESC; + } + break; + case CliSymbolAsciiCR: // Enter = Ok + if(hold) { + send_key = InputKeyOk; + } else { + send_ascii = AsciiValueCR; + } + break; + case CliSymbolAsciiSpace: // Space = Toggle hold next key + if(hold) { + send_ascii = ' '; + } else { + hold = true; + } + break; + default: + send_ascii = in_chr; + break; } if(send_key != InputKeyMAX) { - notification_message(notification, &sequence_display_backlight_on); input_fake_event(input, send_key, hold ? InputTypeLong : InputTypeShort); hold = false; } + if(send_ascii != AsciiValueNUL) { + AsciiEvent event = {.value = send_ascii}; + furi_pubsub_publish(ascii_events, &event); + hold = false; + } } - furi_record_close(RECORD_GUI); - furi_record_close(RECORD_NOTIFICATION); + furi_record_close(RECORD_ASCII_EVENTS); } static void input_cli_send_print_usage() {