evil_portal_scene_text_input.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "../evil_portal_app_i.h"
  2. void evil_portal_scene_text_input_callback(void *context) {
  3. Evil_PortalApp *app = context;
  4. view_dispatcher_send_custom_event(app->view_dispatcher,
  5. Evil_PortalEventStartConsole);
  6. }
  7. void evil_portal_scene_text_input_on_enter(void *context) {
  8. Evil_PortalApp *app = context;
  9. if (false == app->is_custom_tx_string) {
  10. // Fill text input with selected string so that user can add to it
  11. size_t length = strlen(app->selected_tx_string);
  12. furi_assert(length < EVIL_PORTAL_TEXT_INPUT_STORE_SIZE);
  13. bzero(app->text_input_store, EVIL_PORTAL_TEXT_INPUT_STORE_SIZE);
  14. strncpy(app->text_input_store, app->selected_tx_string, length);
  15. // Add space - because flipper keyboard currently doesn't have a space
  16. // app->text_input_store[length] = ' ';
  17. app->text_input_store[length + 1] = '\0';
  18. app->is_custom_tx_string = true;
  19. }
  20. // Setup view
  21. UART_TextInput *text_input = app->text_input;
  22. // Add help message to header
  23. if (0 == strncmp("AT", app->selected_tx_string, strlen("AT"))) {
  24. app->TERMINAL_MODE = 1;
  25. uart_text_input_set_header_text(text_input, "Send AT command to UART");
  26. } else {
  27. app->TERMINAL_MODE = 0;
  28. uart_text_input_set_header_text(text_input, "Send command to UART");
  29. }
  30. uart_text_input_set_result_callback(
  31. text_input, evil_portal_scene_text_input_callback, app,
  32. app->text_input_store, EVIL_PORTAL_TEXT_INPUT_STORE_SIZE, false);
  33. view_dispatcher_switch_to_view(app->view_dispatcher,
  34. Evil_PortalAppViewTextInput);
  35. }
  36. bool evil_portal_scene_text_input_on_event(void *context,
  37. SceneManagerEvent event) {
  38. Evil_PortalApp *app = context;
  39. bool consumed = false;
  40. if (event.type == SceneManagerEventTypeCustom) {
  41. if (event.event == Evil_PortalEventStartConsole) {
  42. app->selected_tx_string = app->text_input_store;
  43. scene_manager_next_scene(app->scene_manager,
  44. Evil_PortalAppViewConsoleOutput);
  45. consumed = true;
  46. }
  47. }
  48. return consumed;
  49. }
  50. void evil_portal_scene_text_input_on_exit(void *context) {
  51. Evil_PortalApp *app = context;
  52. uart_text_input_reset(app->text_input);
  53. }