xremote_scene_create.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #include "../xremote.h"
  2. #include "../helpers/xremote_custom_event.h"
  3. typedef enum {
  4. ButtonIndexPlus = -2,
  5. ButtonIndexSave = -1,
  6. ButtonIndexNA = 0,
  7. } ButtonIndex;
  8. static void xremote_create_callback(void* context, int32_t index, InputType type) {
  9. XRemote* app = context;
  10. uint16_t custom_type;
  11. if(type == InputTypePress) {
  12. custom_type = XRemoteCustomEventMenuSelected;
  13. } else if(type == InputTypeRelease) {
  14. custom_type = XRemoteCustomEventMenuVoid;
  15. } else if(type == InputTypeShort) {
  16. //somehow ButtonMenuItemTypeCommon uses InputTypeShort
  17. custom_type = XRemoteCustomEventMenuSelected;
  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_on_enter(void* context) {
  25. furi_assert(context);
  26. XRemote* app = context;
  27. ButtonMenu* button_menu = app->button_menu_create;
  28. //SceneManager* scene_manager = app->scene_manager;
  29. size_t item_count = cross_remote_get_item_count(app->cross_remote);
  30. for(size_t i = 0; i < item_count; ++i) {
  31. CrossRemoteItem* item = cross_remote_get_item(app->cross_remote, i);
  32. button_menu_add_item(
  33. button_menu,
  34. xremote_remote_item_get_name(item),
  35. i,
  36. xremote_create_callback,
  37. ButtonMenuItemTypeCommon,
  38. context);
  39. }
  40. button_menu_add_item(
  41. button_menu,
  42. "+",
  43. ButtonIndexPlus,
  44. xremote_create_callback,
  45. ButtonMenuItemTypeControl,
  46. context);
  47. button_menu_add_item(
  48. button_menu,
  49. "Save",
  50. ButtonIndexSave,
  51. xremote_create_callback,
  52. ButtonMenuItemTypeControl,
  53. context);
  54. button_menu_set_header(button_menu, "Add Cmd");
  55. const int16_t button_index =
  56. (signed)scene_manager_get_scene_state(app->scene_manager, XRemoteViewIdCreate);
  57. button_menu_set_selected_item(button_menu, button_index);
  58. scene_manager_set_scene_state(app->scene_manager, XRemoteSceneCreate, ButtonIndexNA);
  59. view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdCreate);
  60. }
  61. bool xremote_scene_create_on_event(void* context, SceneManagerEvent event) {
  62. XRemote* app = context;
  63. bool consumed = false;
  64. if(event.type == SceneManagerEventTypeBack) {
  65. scene_manager_next_scene(app->scene_manager, XRemoteSceneMenu);
  66. consumed = true;
  67. /*if(is_transmitter_idle) {
  68. const uint32_t possible_scenes[] = {InfraredSceneRemoteList, InfraredSceneStart};
  69. consumed = scene_manager_search_and_switch_to_previous_scene_one_of(
  70. scene_manager, possible_scenes, COUNT_OF(possible_scenes));
  71. } else {
  72. consumed = true;
  73. }*/
  74. } else if(event.type == SceneManagerEventTypeCustom) {
  75. const uint16_t custom_type = xremote_custom_menu_event_get_type(event.event);
  76. const int16_t button_index = xremote_custom_menu_event_get_value(event.event);
  77. scene_manager_set_scene_state(
  78. app->scene_manager, XRemoteSceneCreate, (unsigned)button_index);
  79. if(custom_type == XRemoteCustomEventMenuSelected && button_index < 0) {
  80. //scene_manager_set_scene_state(
  81. // app->scene_manager, XRemoteSceneCreate, (unsigned)button_index);
  82. if(button_index == ButtonIndexPlus) {
  83. scene_manager_next_scene(app->scene_manager, XRemoteSceneCreateAdd);
  84. consumed = true;
  85. } else if(button_index == ButtonIndexSave) {
  86. scene_manager_next_scene(app->scene_manager, XRemoteSceneSaveRemote);
  87. }
  88. } else if(custom_type == XRemoteCustomEventMenuSelected) {
  89. app->edit_item = button_index;
  90. scene_manager_next_scene(app->scene_manager, XRemoteSceneEditItem);
  91. }
  92. /*switch(event.event) {
  93. case XRemoteCustomEventCreateLeft:
  94. case XRemoteCustomEventCreateRight:
  95. break;
  96. case XRemoteCustomEventCreateUp:
  97. case XRemoteCustomEventCreateDown:
  98. break;
  99. case XRemoteCustomEventCreateBack:
  100. notification_message(app->notification, &sequence_reset_red);
  101. notification_message(app->notification, &sequence_reset_green);
  102. notification_message(app->notification, &sequence_reset_blue);
  103. if(!scene_manager_search_and_switch_to_previous_scene(
  104. app->scene_manager, XRemoteSceneMenu)) {
  105. scene_manager_stop(app->scene_manager);
  106. view_dispatcher_stop(app->view_dispatcher);
  107. }
  108. consumed = true;
  109. break;
  110. }*/
  111. }
  112. return consumed;
  113. }
  114. void xremote_scene_create_on_exit(void* context) {
  115. XRemote* app = context;
  116. button_menu_reset(app->button_menu_create);
  117. }