esubghz_chat_key_menu.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "../esubghz_chat_i.h"
  2. typedef enum {
  3. ESubGhzChatKeyMenuItems_NoEncryption,
  4. ESubGhzChatKeyMenuItems_Password,
  5. ESubGhzChatKeyMenuItems_HexKey,
  6. } ESubGhzChatKeyMenuItems;
  7. static void key_menu_cb(void* context, uint32_t index)
  8. {
  9. furi_assert(context);
  10. ESubGhzChatState* state = context;
  11. switch(index) {
  12. case ESubGhzChatKeyMenuItems_NoEncryption:
  13. state->encrypted = false;
  14. enter_chat(state);
  15. scene_manager_handle_custom_event(state->scene_manager,
  16. ESubGhzChatEvent_KeyMenuNoEncryption);
  17. break;
  18. case ESubGhzChatKeyMenuItems_Password:
  19. scene_manager_handle_custom_event(state->scene_manager,
  20. ESubGhzChatEvent_KeyMenuPassword);
  21. break;
  22. case ESubGhzChatKeyMenuItems_HexKey:
  23. scene_manager_handle_custom_event(state->scene_manager,
  24. ESubGhzChatEvent_KeyMenuHexKey);
  25. break;
  26. default:
  27. break;
  28. }
  29. }
  30. /* Prepares the key menu scene. */
  31. void scene_on_enter_key_menu(void* context)
  32. {
  33. FURI_LOG_T(APPLICATION_NAME, "scene_on_enter_key_menu");
  34. furi_assert(context);
  35. ESubGhzChatState* state = context;
  36. menu_reset(state->menu);
  37. menu_add_item(
  38. state->menu,
  39. "No encryption",
  40. NULL,
  41. ESubGhzChatKeyMenuItems_NoEncryption,
  42. key_menu_cb,
  43. state
  44. );
  45. menu_add_item(
  46. state->menu,
  47. "Password",
  48. NULL,
  49. ESubGhzChatKeyMenuItems_Password,
  50. key_menu_cb,
  51. state
  52. );
  53. menu_add_item(
  54. state->menu,
  55. "Hex Key",
  56. NULL,
  57. ESubGhzChatKeyMenuItems_HexKey,
  58. key_menu_cb,
  59. state
  60. );
  61. view_dispatcher_switch_to_view(state->view_dispatcher, ESubGhzChatView_Menu);
  62. }
  63. /* Handles scene manager events for the key menu scene. */
  64. bool scene_on_event_key_menu(void* context, SceneManagerEvent event)
  65. {
  66. FURI_LOG_T(APPLICATION_NAME, "scene_on_event_key_menu");
  67. furi_assert(context);
  68. ESubGhzChatState* state = context;
  69. bool consumed = false;
  70. switch(event.type) {
  71. case SceneManagerEventTypeCustom:
  72. switch(event.event) {
  73. /* switch to message input scene */
  74. case ESubGhzChatEvent_KeyMenuNoEncryption:
  75. scene_manager_next_scene(state->scene_manager,
  76. ESubGhzChatScene_ChatInput);
  77. consumed = true;
  78. break;
  79. /* switch to password input scene */
  80. case ESubGhzChatEvent_KeyMenuPassword:
  81. scene_manager_next_scene(state->scene_manager,
  82. ESubGhzChatScene_PassInput);
  83. consumed = true;
  84. break;
  85. /* switch to hex key input scene */
  86. case ESubGhzChatEvent_KeyMenuHexKey:
  87. scene_manager_next_scene(state->scene_manager,
  88. ESubGhzChatScene_HexKeyInput);
  89. consumed = true;
  90. break;
  91. }
  92. break;
  93. case SceneManagerEventTypeBack:
  94. /* stop the application if the user presses back here */
  95. view_dispatcher_stop(state->view_dispatcher);
  96. consumed = true;
  97. break;
  98. default:
  99. consumed = false;
  100. break;
  101. }
  102. return consumed;
  103. }
  104. /* Cleans up the key menu scene. */
  105. void scene_on_exit_key_menu(void* context)
  106. {
  107. FURI_LOG_T(APPLICATION_NAME, "scene_on_exit_key_menu");
  108. furi_assert(context);
  109. ESubGhzChatState* state = context;
  110. menu_reset(state->menu);
  111. }