xremote_scene_create_add.c 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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(app->view_dispatcher, xremote_custom_menu_event_pack(custom_type, index));
  22. }
  23. void xremote_scene_create_add_on_enter(void* context) {
  24. furi_assert(context);
  25. XRemote* app = context;
  26. ButtonMenu* button_menu = app->button_menu_create_add;
  27. SceneManager* scene_manager = app->scene_manager;
  28. button_menu_add_item(
  29. button_menu,
  30. "Infrared",
  31. ButtonIndexIr,
  32. xremote_create_add_callback,
  33. ButtonMenuItemTypeCommon,
  34. context);
  35. button_menu_add_item(
  36. button_menu,
  37. "SubGhz",
  38. ButtonIndexSubghz,
  39. xremote_create_add_callback,
  40. ButtonMenuItemTypeCommon,
  41. context);
  42. button_menu_add_item(
  43. button_menu,
  44. "Pause",
  45. ButtonIndexPause,
  46. xremote_create_add_callback,
  47. ButtonMenuItemTypeCommon,
  48. context);
  49. button_menu_set_header(button_menu, "Choose Type");
  50. const int16_t button_index =
  51. (signed)scene_manager_get_scene_state(scene_manager, XRemoteViewIdCreateAdd);
  52. button_menu_set_selected_item(button_menu, button_index);
  53. view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdCreateAdd);
  54. }
  55. bool xremote_scene_create_add_on_event(void* context, SceneManagerEvent event) {
  56. XRemote* app = context;
  57. bool consumed = false;
  58. if(event.type == SceneManagerEventTypeCustom) {
  59. const uint16_t custom_type = xremote_custom_menu_event_get_type(event.event);
  60. const int16_t button_index = xremote_custom_menu_event_get_value(event.event);
  61. if (custom_type == XRemoteCustomEventMenuAddSelected) {
  62. furi_assert(button_index < 0);
  63. scene_manager_set_scene_state(
  64. app->scene_manager, XRemoteSceneCreate, (unsigned)button_index);
  65. if(button_index == ButtonIndexIr) {
  66. scene_manager_next_scene(app->scene_manager, XRemoteSceneIrList);
  67. }
  68. if(button_index == ButtonIndexSubghz) {
  69. //scene_manager_next_scene(app->scene_manager, XRemoteSceneSgList);
  70. scene_manager_next_scene(app->scene_manager, XRemoteSceneWip);
  71. }
  72. if(button_index == ButtonIndexPause) {
  73. scene_manager_next_scene(app->scene_manager, XRemoteScenePauseSet);
  74. }
  75. consumed = true;
  76. }
  77. }
  78. return consumed;
  79. }
  80. void xremote_scene_create_add_on_exit(void* context) {
  81. XRemote* app = context;
  82. button_menu_reset(app->button_menu_create_add);
  83. }