uart_terminal_scene_text_input.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. 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. text_input_set_header_text(text_input, "Send AT command to UART");
  25. } else {
  26. app->TERMINAL_MODE = 0;
  27. text_input_set_header_text(text_input, "Send command to UART");
  28. }
  29. 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. text_input_add_illegal_symbols(text_input);
  37. view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewTextInput);
  38. }
  39. bool uart_terminal_scene_text_input_on_event(void* context, SceneManagerEvent event) {
  40. UART_TerminalApp* app = context;
  41. bool consumed = false;
  42. if(event.type == SceneManagerEventTypeCustom) {
  43. if(event.event == UART_TerminalEventStartConsole) {
  44. // Point to custom string to send
  45. app->selected_tx_string = app->text_input_store;
  46. scene_manager_next_scene(app->scene_manager, UART_TerminalSceneConsoleOutput);
  47. consumed = true;
  48. }
  49. }
  50. return consumed;
  51. }
  52. void uart_terminal_scene_text_input_on_exit(void* context) {
  53. UART_TerminalApp* app = context;
  54. text_input_reset(app->text_input);
  55. }