uart_terminal_scene_text_input.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. if(0 == strncmp("AT", app->selected_tx_string, strlen("AT"))) {
  23. app->TERMINAL_MODE = 1;
  24. uart_text_input_set_header_text(text_input, "Send AT command to UART");
  25. } else {
  26. app->TERMINAL_MODE = 0;
  27. uart_text_input_set_header_text(text_input, "Send command to UART");
  28. }
  29. uart_text_input_set_result_callback(
  30. text_input,
  31. uart_terminal_scene_text_input_callback,
  32. app,
  33. app->text_input_store,
  34. UART_TERMINAL_TEXT_INPUT_STORE_SIZE,
  35. false);
  36. view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewTextInput);
  37. }
  38. bool uart_terminal_scene_text_input_on_event(void* context, SceneManagerEvent event) {
  39. UART_TerminalApp* app = context;
  40. bool consumed = false;
  41. if(event.type == SceneManagerEventTypeCustom) {
  42. if(event.event == UART_TerminalEventStartConsole) {
  43. // Point to custom string to send
  44. app->selected_tx_string = app->text_input_store;
  45. scene_manager_next_scene(app->scene_manager, UART_TerminalAppViewConsoleOutput);
  46. consumed = true;
  47. }
  48. }
  49. return consumed;
  50. }
  51. void uart_terminal_scene_text_input_on_exit(void* context) {
  52. UART_TerminalApp* app = context;
  53. uart_text_input_reset(app->text_input);
  54. }