uart_terminal_scene_text_input.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "../uart_terminal_app_i.h"
  2. void uart_terminal_scene_text_input_callback(void* context) {
  3. UART_TerminalApp* app = context;
  4. view_dispatcher_send_custom_event(app->view_dispatcher, UART_TerminalEventStartConsole);
  5. }
  6. void uart_terminal_scene_text_input_on_enter(void* context) {
  7. UART_TerminalApp* app = context;
  8. if(false == app->is_custom_tx_string) {
  9. // Fill text input with selected string so that user can add to it
  10. size_t length = strlen(app->selected_tx_string);
  11. furi_assert(length < UART_TERMINAL_TEXT_INPUT_STORE_SIZE);
  12. bzero(app->text_input_store, UART_TERMINAL_TEXT_INPUT_STORE_SIZE);
  13. strncpy(app->text_input_store, app->selected_tx_string, length);
  14. // Add space - because flipper keyboard currently doesn't have a space
  15. //app->text_input_store[length] = ' ';
  16. app->text_input_store[length + 1] = '\0';
  17. app->is_custom_tx_string = true;
  18. }
  19. // Setup view
  20. UART_TextInput* text_input = app->text_input;
  21. // Add help message to header
  22. uart_text_input_set_header_text(text_input, "Send command to UART");
  23. uart_text_input_set_result_callback(
  24. text_input,
  25. uart_terminal_scene_text_input_callback,
  26. app,
  27. app->text_input_store,
  28. UART_TERMINAL_TEXT_INPUT_STORE_SIZE,
  29. false);
  30. view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewTextInput);
  31. }
  32. bool uart_terminal_scene_text_input_on_event(void* context, SceneManagerEvent event) {
  33. UART_TerminalApp* app = context;
  34. bool consumed = false;
  35. if(event.type == SceneManagerEventTypeCustom) {
  36. if(event.event == UART_TerminalEventStartConsole) {
  37. // Point to custom string to send
  38. app->selected_tx_string = app->text_input_store;
  39. scene_manager_next_scene(app->scene_manager, UART_TerminalAppViewConsoleOutput);
  40. consumed = true;
  41. }
  42. }
  43. return consumed;
  44. }
  45. void uart_terminal_scene_text_input_on_exit(void* context) {
  46. UART_TerminalApp* app = context;
  47. uart_text_input_reset(app->text_input);
  48. }