settings.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #include "nfc_playlist.h"
  2. #include "scences/settings.h"
  3. typedef enum {
  4. NfcPlaylistSettings_Timeout,
  5. NfcPlaylistSettings_Delay,
  6. NfcPlaylistSettings_LedIndicator,
  7. NfcPlaylistSettings_HideError,
  8. NfcPlaylistSettings_Reset
  9. } NfcPlaylistMenuSelection;
  10. void nfc_playlist_settings_menu_callback(void* context, uint32_t index) {
  11. NfcPlaylist* nfc_playlist = context;
  12. if (index == NfcPlaylistSettings_Reset) {
  13. nfc_playlist->settings.emulate_timeout = default_emulate_timeout;
  14. VariableItem* emulation_timeout_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Timeout);
  15. variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout);
  16. char emulation_timeout_settings_text[3];
  17. snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
  18. variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text);
  19. nfc_playlist->settings.emulate_delay = default_emulate_delay;
  20. VariableItem* emulation_delay_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_Delay);
  21. variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay);
  22. char emulation_delay_settings_text[3];
  23. snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
  24. variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text);
  25. nfc_playlist->settings.emulate_led_indicator = default_emulate_led_indicator;
  26. VariableItem* emulation_led_indicator_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_LedIndicator);
  27. variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator);
  28. variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
  29. nfc_playlist->settings.hide_error = default_hide_error;
  30. VariableItem* hide_error_indicator_settings = variable_item_list_get(nfc_playlist->variable_item_list, NfcPlaylistSettings_HideError);
  31. variable_item_set_current_value_index(hide_error_indicator_settings, nfc_playlist->settings.hide_error);
  32. variable_item_set_current_value_text(hide_error_indicator_settings, nfc_playlist->settings.hide_error ? "ON" : "OFF");
  33. }
  34. }
  35. void nfc_playlist_settings_options_change_callback(VariableItem* item) {
  36. NfcPlaylist* nfc_playlist = variable_item_get_context(item);
  37. uint8_t current_option = variable_item_list_get_selected_item_index(nfc_playlist->variable_item_list);
  38. uint8_t option_value_index = variable_item_get_current_value_index(item);
  39. switch(current_option) {
  40. case NfcPlaylistSettings_Timeout: {
  41. nfc_playlist->settings.emulate_timeout = option_value_index;
  42. char emulate_timeout_text[3];
  43. snprintf(emulate_timeout_text, 3, "%ds", options_emulate_timeout[option_value_index]);
  44. variable_item_set_current_value_text(item, (char*)emulate_timeout_text);
  45. break;
  46. }
  47. case NfcPlaylistSettings_Delay: {
  48. nfc_playlist->settings.emulate_delay = option_value_index;
  49. char emulate_delay_text[3];
  50. snprintf(emulate_delay_text, 3, "%ds", options_emulate_delay[option_value_index]);
  51. variable_item_set_current_value_text(item, (char*)emulate_delay_text);
  52. break;
  53. }
  54. case NfcPlaylistSettings_LedIndicator:
  55. nfc_playlist->settings.emulate_led_indicator = option_value_index;
  56. variable_item_set_current_value_text(item, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
  57. break;
  58. case NfcPlaylistSettings_HideError:
  59. nfc_playlist->settings.hide_error = option_value_index;
  60. variable_item_set_current_value_text(item, nfc_playlist->settings.hide_error ? "ON" : "OFF");
  61. break;
  62. default:
  63. break;
  64. }
  65. }
  66. void nfc_playlist_settings_scene_on_enter(void* context) {
  67. NfcPlaylist* nfc_playlist = context;
  68. variable_item_list_set_header(nfc_playlist->variable_item_list, "Settings");
  69. VariableItem* emulation_timeout_settings = variable_item_list_add(
  70. nfc_playlist->variable_item_list,
  71. "Emulate time",
  72. (sizeof(options_emulate_timeout)/sizeof(options_emulate_timeout[0])),
  73. nfc_playlist_settings_options_change_callback,
  74. nfc_playlist);
  75. variable_item_set_current_value_index(emulation_timeout_settings, nfc_playlist->settings.emulate_timeout);
  76. char emulation_timeout_settings_text[3];
  77. snprintf(emulation_timeout_settings_text, 3, "%ds", options_emulate_timeout[nfc_playlist->settings.emulate_timeout]);
  78. variable_item_set_current_value_text(emulation_timeout_settings, (char*)emulation_timeout_settings_text);
  79. VariableItem* emulation_delay_settings = variable_item_list_add(
  80. nfc_playlist->variable_item_list,
  81. "Delay time",
  82. (sizeof(options_emulate_delay)/sizeof(options_emulate_delay[0])),
  83. nfc_playlist_settings_options_change_callback,
  84. nfc_playlist);
  85. variable_item_set_current_value_index(emulation_delay_settings, nfc_playlist->settings.emulate_delay);
  86. char emulation_delay_settings_text[3];
  87. snprintf(emulation_delay_settings_text, 3, "%ds", options_emulate_delay[nfc_playlist->settings.emulate_delay]);
  88. variable_item_set_current_value_text(emulation_delay_settings, (char*)emulation_delay_settings_text);
  89. VariableItem* emulation_led_indicator_settings = variable_item_list_add(
  90. nfc_playlist->variable_item_list,
  91. "LED Indicator",
  92. 2,
  93. nfc_playlist_settings_options_change_callback,
  94. nfc_playlist);
  95. variable_item_set_current_value_index(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator);
  96. variable_item_set_current_value_text(emulation_led_indicator_settings, nfc_playlist->settings.emulate_led_indicator ? "ON" : "OFF");
  97. VariableItem* hide_error_indicator_settings = variable_item_list_add(
  98. nfc_playlist->variable_item_list,
  99. "Hide error messages",
  100. 2,
  101. nfc_playlist_settings_options_change_callback,
  102. nfc_playlist);
  103. variable_item_set_current_value_index(hide_error_indicator_settings, nfc_playlist->settings.hide_error);
  104. variable_item_set_current_value_text(hide_error_indicator_settings, nfc_playlist->settings.hide_error ? "ON" : "OFF");
  105. variable_item_list_add(nfc_playlist->variable_item_list, "Reset settings", 0, NULL, NULL);
  106. variable_item_list_set_enter_callback(nfc_playlist->variable_item_list, nfc_playlist_settings_menu_callback, nfc_playlist);
  107. view_dispatcher_switch_to_view(nfc_playlist->view_dispatcher, NfcPlaylistView_Settings);
  108. }
  109. bool nfc_playlist_settings_scene_on_event(void* context, SceneManagerEvent event) {
  110. UNUSED(context);
  111. UNUSED(event);
  112. return false;
  113. }
  114. void nfc_playlist_settings_scene_on_exit(void* context) {
  115. NfcPlaylist* nfc_playlist = context;
  116. variable_item_list_reset(nfc_playlist->variable_item_list);
  117. }