main_menu.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include "nfc_playlist.h"
  2. #include "scences/main_menu.h"
  3. typedef enum {
  4. NfcPlaylistEvent_ShowEmulatingPopup
  5. } NfcPlaylistMainMenuEvent;
  6. typedef enum {
  7. NfcPlaylistSettings_Timeout,
  8. NfcPlaylistSettings_Delay,
  9. NfcPlaylistMenuSelection_Start
  10. } NfcPlaylistMenuSelection;
  11. static void nfc_playlist_menu_callback(void* context, uint32_t index) {
  12. NfcPlaylist* app = context;
  13. switch(index) {
  14. case NfcPlaylistMenuSelection_Start:
  15. scene_manager_handle_custom_event(app->scene_manager, NfcPlaylistEvent_ShowEmulatingPopup);
  16. break;
  17. default:
  18. break;
  19. }
  20. }
  21. static void nfc_playlist_settings_change_callback(VariableItem* item) {
  22. NfcPlaylist* app = variable_item_get_context(item);
  23. uint8_t current_option = variable_item_list_get_selected_item_index(app->variable_item_list);
  24. uint8_t option_value_index = variable_item_get_current_value_index(item);
  25. switch(current_option) {
  26. case NfcPlaylistSettings_Timeout: ;
  27. app->emulate_timeout = option_value_index;
  28. char emulate_timeout_text[10];
  29. snprintf(emulate_timeout_text, 10, "%ds", (options_emulate_timeout[option_value_index]/1000));
  30. variable_item_set_current_value_text(item, (char*)emulate_timeout_text);
  31. break;
  32. case NfcPlaylistSettings_Delay: ;
  33. app->emulate_delay = option_value_index;
  34. char emulate_delay_text[10];
  35. snprintf(emulate_delay_text, 10, "%ds", (options_emulate_delay[option_value_index]/1000));
  36. variable_item_set_current_value_text(item, (char*)emulate_delay_text);
  37. break;
  38. default:
  39. break;
  40. }
  41. }
  42. void nfc_playlist_main_menu_scene_on_enter(void* context) {
  43. NfcPlaylist* app = context;
  44. variable_item_list_set_header(app->variable_item_list, "NFC Playlist");
  45. VariableItem* emulation_timeout_settings = variable_item_list_add(
  46. app->variable_item_list,
  47. "Timeout",
  48. 10,
  49. nfc_playlist_settings_change_callback,
  50. app);
  51. variable_item_set_current_value_index(emulation_timeout_settings, app->emulate_timeout);
  52. char emulation_timeout_settings_text[10];
  53. snprintf(emulation_timeout_settings_text, 10, "%ds", (options_emulate_timeout[app->emulate_timeout]/1000));
  54. variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text);
  55. VariableItem* emulation_delay_settings = variable_item_list_add(
  56. app->variable_item_list,
  57. "Delay",
  58. 6,
  59. nfc_playlist_settings_change_callback,
  60. app);
  61. variable_item_set_current_value_index(emulation_delay_settings, app->emulate_delay);
  62. char emulation_delay_settings_text[10];
  63. snprintf(emulation_delay_settings_text, 10, "%ds", (options_emulate_delay[app->emulate_delay]/1000));
  64. variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text);
  65. variable_item_list_add(app->variable_item_list, "Start", 0, NULL, NULL);
  66. variable_item_list_set_enter_callback(app->variable_item_list, nfc_playlist_menu_callback, app);
  67. view_dispatcher_switch_to_view(app->view_dispatcher, NfcPlaylistView_Menu);
  68. }
  69. bool nfc_playlist_main_menu_scene_on_event(void* context, SceneManagerEvent event) {
  70. NfcPlaylist* app = context;
  71. bool consumed = false;
  72. switch(event.type) {
  73. case SceneManagerEventTypeCustom:
  74. switch(event.event) {
  75. case NfcPlaylistEvent_ShowEmulatingPopup:
  76. scene_manager_next_scene(app->scene_manager, NfcPlaylistScene_EmulatingPopup);
  77. consumed = true;
  78. break;
  79. default:
  80. break;
  81. }
  82. break;
  83. default:
  84. consumed = false;
  85. break;
  86. }
  87. return consumed;
  88. }
  89. void nfc_playlist_main_menu_scene_on_exit(void* context) {
  90. NfcPlaylist* app = context;
  91. variable_item_list_reset(app->variable_item_list);
  92. }