xremote_scene_create_add.c 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #include "../xremote.h"
  2. #include "../helpers/xremote_custom_event.h"
  3. typedef enum {
  4. ButtonIndexIr = -3,
  5. ButtonIndexSubghz = -2,
  6. ButtonIndexPause = -1,
  7. ButtonIndexNA = 0,
  8. } ButtonIndex;
  9. static void xremote_create_add_callback(void* context, int32_t index, InputType type) {
  10. XRemote* app = context;
  11. uint16_t custom_type;
  12. if(type == InputTypePress) {
  13. custom_type = XRemoteCustomEventMenuVoid;
  14. } else if(type == InputTypeRelease) {
  15. custom_type = XRemoteCustomEventMenuAddSelected;
  16. } else if(type == InputTypeShort) {
  17. custom_type = XRemoteCustomEventMenuVoid;
  18. } else {
  19. furi_crash("Unexpected Input Type");
  20. }
  21. view_dispatcher_send_custom_event(
  22. app->view_dispatcher, xremote_custom_menu_event_pack(custom_type, index));
  23. }
  24. void xremote_scene_create_add_on_enter(void* context) {
  25. furi_assert(context);
  26. XRemote* app = context;
  27. ButtonMenu* button_menu = app->button_menu_create_add;
  28. SceneManager* scene_manager = app->scene_manager;
  29. button_menu_add_item(
  30. button_menu,
  31. "Infrared",
  32. ButtonIndexIr,
  33. xremote_create_add_callback,
  34. ButtonMenuItemTypeCommon,
  35. context);
  36. button_menu_add_item(
  37. button_menu,
  38. "SubGhz",
  39. ButtonIndexSubghz,
  40. xremote_create_add_callback,
  41. ButtonMenuItemTypeCommon,
  42. context);
  43. button_menu_add_item(
  44. button_menu,
  45. "Pause",
  46. ButtonIndexPause,
  47. xremote_create_add_callback,
  48. ButtonMenuItemTypeCommon,
  49. context);
  50. button_menu_set_header(button_menu, "Choose Type");
  51. const int16_t button_index =
  52. (signed)scene_manager_get_scene_state(scene_manager, XRemoteViewIdCreateAdd);
  53. button_menu_set_selected_item(button_menu, button_index);
  54. view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdCreateAdd);
  55. }
  56. bool xremote_scene_create_add_on_event(void* context, SceneManagerEvent event) {
  57. XRemote* app = context;
  58. bool consumed = false;
  59. if(event.type == SceneManagerEventTypeCustom) {
  60. const uint16_t custom_type = xremote_custom_menu_event_get_type(event.event);
  61. const int16_t button_index = xremote_custom_menu_event_get_value(event.event);
  62. if(custom_type == XRemoteCustomEventMenuAddSelected) {
  63. furi_assert(button_index < 0);
  64. scene_manager_set_scene_state(
  65. app->scene_manager, XRemoteSceneCreate, (unsigned)button_index);
  66. if(button_index == ButtonIndexIr) {
  67. scene_manager_next_scene(app->scene_manager, XRemoteSceneIrList);
  68. }
  69. if(button_index == ButtonIndexSubghz) {
  70. scene_manager_next_scene(app->scene_manager, XRemoteSceneSgList);
  71. //scene_manager_next_scene(app->scene_manager, XRemoteSceneWip);
  72. }
  73. if(button_index == ButtonIndexPause) {
  74. scene_manager_next_scene(app->scene_manager, XRemoteScenePauseSet);
  75. }
  76. consumed = true;
  77. }
  78. }
  79. return consumed;
  80. }
  81. void xremote_scene_create_add_on_exit(void* context) {
  82. XRemote* app = context;
  83. button_menu_reset(app->button_menu_create_add);
  84. }