hex_viewer_scene_scene_3.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. #include "../hex_viewer.h"
  2. #include "../helpers/hex_viewer_custom_event.h"
  3. #include "../helpers/hex_viewer_haptic.h"
  4. #include "../helpers/hex_viewer_led.h"
  5. typedef enum {
  6. ButtonIndexControl3 = -3,
  7. ButtonIndexControl2 = -2,
  8. ButtonIndexControl1 = -1,
  9. ButtonIndexButton1 = 0,
  10. ButtonIndexButton2 = 1,
  11. ButtonIndexButton3 = 2,
  12. } ButtonIndex;
  13. static void hex_viewer_scene_3_callback(void* context, int32_t index, InputType type) {
  14. HexViewer* app = context;
  15. uint16_t custom_type;
  16. if(type == InputTypePress) {
  17. custom_type = HexViewerCustomEventMenuSelected;
  18. } else if(type == InputTypeRelease) {
  19. custom_type = HexViewerCustomEventMenuVoid;
  20. } else if(type == InputTypeShort) {
  21. //somehow ButtonMenuItemTypeCommon uses InputTypeShort
  22. custom_type = HexViewerCustomEventMenuSelected;
  23. } else {
  24. furi_crash("Unexpected Input Type");
  25. }
  26. view_dispatcher_send_custom_event(app->view_dispatcher, hex_viewer_custom_menu_event_pack(custom_type, index));
  27. }
  28. void hex_viewer_scene_scene_3_on_enter(void* context) {
  29. furi_assert(context);
  30. HexViewer* app = context;
  31. ButtonMenu* button_menu = app->button_menu;
  32. SceneManager* scene_manager = app->scene_manager;
  33. button_menu_add_item(
  34. button_menu,
  35. "Common",
  36. ButtonIndexButton1,
  37. hex_viewer_scene_3_callback,
  38. ButtonMenuItemTypeCommon,
  39. context);
  40. button_menu_add_item(
  41. button_menu,
  42. "Button",
  43. ButtonIndexButton2,
  44. hex_viewer_scene_3_callback,
  45. ButtonMenuItemTypeCommon,
  46. context);
  47. button_menu_add_item(
  48. button_menu,
  49. "Examples",
  50. ButtonIndexButton1,
  51. hex_viewer_scene_3_callback,
  52. ButtonMenuItemTypeCommon,
  53. context);
  54. button_menu_add_item(
  55. button_menu,
  56. "Control",
  57. ButtonIndexControl1,
  58. hex_viewer_scene_3_callback,
  59. ButtonMenuItemTypeControl,
  60. context);
  61. button_menu_add_item(
  62. button_menu,
  63. "Button",
  64. ButtonIndexControl2,
  65. hex_viewer_scene_3_callback,
  66. ButtonMenuItemTypeControl,
  67. context);
  68. button_menu_add_item(
  69. button_menu,
  70. "Examples",
  71. ButtonIndexControl3,
  72. hex_viewer_scene_3_callback,
  73. ButtonMenuItemTypeControl,
  74. context);
  75. button_menu_set_header(button_menu, "Button Menu");
  76. const int16_t button_index =
  77. (signed)scene_manager_get_scene_state(app->scene_manager, HexViewerViewIdScene3);
  78. button_menu_set_selected_item(button_menu, button_index);
  79. scene_manager_set_scene_state(scene_manager, HexViewerSceneScene_3, ButtonIndexButton1);
  80. view_dispatcher_switch_to_view(app->view_dispatcher, HexViewerViewIdScene3);
  81. }
  82. bool hex_viewer_scene_scene_3_on_event(void* context, SceneManagerEvent event) {
  83. HexViewer* app = context;
  84. bool consumed = false;
  85. if(event.type == SceneManagerEventTypeCustom) {
  86. const uint16_t custom_type = hex_viewer_custom_menu_event_get_type(event.event);
  87. const int16_t button_index = hex_viewer_custom_menu_event_get_value(event.event);
  88. if (custom_type == HexViewerCustomEventMenuSelected) {
  89. switch(button_index) {
  90. case ButtonIndexButton1:
  91. hex_viewer_play_happy_bump(app);
  92. hex_viewer_led_set_rgb(app, 255, 0, 0);
  93. break;
  94. case ButtonIndexButton2:
  95. hex_viewer_play_happy_bump(app);
  96. hex_viewer_led_set_rgb(app, 0, 255, 0);
  97. break;
  98. case ButtonIndexButton3:
  99. hex_viewer_play_happy_bump(app);
  100. hex_viewer_led_set_rgb(app, 0, 0, 255);
  101. break;
  102. case ButtonIndexControl1:
  103. hex_viewer_play_bad_bump(app);
  104. hex_viewer_led_set_rgb(app, 255, 0, 255);
  105. break;
  106. case ButtonIndexControl2:
  107. hex_viewer_play_bad_bump(app);
  108. hex_viewer_led_set_rgb(app, 255, 255, 0);
  109. break;
  110. case ButtonIndexControl3:
  111. hex_viewer_play_bad_bump(app);
  112. hex_viewer_led_set_rgb(app, 0, 255, 255);
  113. break;
  114. }
  115. consumed = true;
  116. }
  117. }
  118. return consumed;
  119. }
  120. void hex_viewer_scene_scene_3_on_exit(void* context) {
  121. HexViewer* app = context;
  122. button_menu_reset(app->button_menu);
  123. notification_message(app->notification, &sequence_reset_red);
  124. notification_message(app->notification, &sequence_reset_green);
  125. notification_message(app->notification, &sequence_reset_blue);
  126. }