uart_terminal_scene_text_input.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. text_input_set_header_text(text_input, "Send new morse message");
  23. 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. text_input_show_illegal_symbols(text_input, true);
  31. view_dispatcher_switch_to_view(app->view_dispatcher, UART_TerminalAppViewTextInput);
  32. }
  33. bool uart_terminal_scene_text_input_on_event(void* context, SceneManagerEvent event) {
  34. UART_TerminalApp* app = context;
  35. bool consumed = false;
  36. if(event.type == SceneManagerEventTypeCustom) {
  37. if(event.event == UART_TerminalEventStartConsole) {
  38. // Point to custom string to send
  39. app->selected_tx_string = app->text_input_store;
  40. scene_manager_next_scene(app->scene_manager, UART_TerminalAppViewConsoleOutput);
  41. consumed = true;
  42. }
  43. }
  44. return consumed;
  45. }
  46. void uart_terminal_scene_text_input_on_exit(void* context) {
  47. UART_TerminalApp* app = context;
  48. text_input_reset(app->text_input);
  49. }