scene_settings.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. #include <furi.h>
  2. #include <gui/view_dispatcher.h>
  3. #include <gui/scene_manager.h>
  4. #include <gui/modules/variable_item_list.h>
  5. #include <toolbox/value_index.h>
  6. #include "quac.h"
  7. #include "scenes.h"
  8. #include "scene_settings.h"
  9. #include "../actions/action.h"
  10. #include "../views/action_menu.h"
  11. #include "../quac_settings.h"
  12. #include <lib/toolbox/path.h>
  13. // Unfortunately, the VariableItemList does not provide a method to query the length
  14. // of the list. Since we intend to place "About" last, it would be convenient to
  15. // dynamically know it's list index for our on_event method. However, we'll need to
  16. // hardcode the value..
  17. #define SCENE_SETTINGS_ABOUT 9 // 10 items in our Settings list, so last index is 9
  18. static const char* const layout_text[2] = {"Vert", "Horiz"};
  19. static const uint32_t layout_value[2] = {QUAC_APP_PORTRAIT, QUAC_APP_LANDSCAPE};
  20. static const char* const show_offon_text[2] = {"OFF", "ON"};
  21. static const uint32_t show_offon_value[2] = {false, true};
  22. #define V_DURATION_COUNT 8
  23. static const char* const duration_text[V_DURATION_COUNT] = {
  24. "500 ms",
  25. "1 sec",
  26. "1.5 sec",
  27. "2 sec",
  28. "2.5 sec",
  29. "3 sec",
  30. "5 sec",
  31. "10 sec",
  32. };
  33. static const uint32_t duration_value[V_DURATION_COUNT] = {
  34. 500,
  35. 1000,
  36. 1500,
  37. 2000,
  38. 2500,
  39. 3000,
  40. 5000,
  41. 10000,
  42. };
  43. #define V_REPEAT_COUNT 9
  44. static const char* const repeat_text[V_REPEAT_COUNT] = {
  45. "1",
  46. "2",
  47. "3",
  48. "5",
  49. "8",
  50. "10", // default
  51. "15",
  52. "20",
  53. "50"};
  54. static const uint32_t repeat_value[V_REPEAT_COUNT] = {1, 2, 3, 5, 8, 10, 15, 20, 50};
  55. static const char* const disabled_enabled_text[2] = {"Disabled", "Enabled"};
  56. static const uint32_t disabled_enabled_value[2] = {false, true};
  57. static void scene_settings_layout_changed(VariableItem* item) {
  58. App* app = variable_item_get_context(item);
  59. uint8_t index = variable_item_get_current_value_index(item);
  60. variable_item_set_current_value_text(item, layout_text[index]);
  61. app->settings.layout = layout_value[index];
  62. }
  63. static void scene_settings_show_icons_changed(VariableItem* item) {
  64. App* app = variable_item_get_context(item);
  65. uint8_t index = variable_item_get_current_value_index(item);
  66. variable_item_set_current_value_text(item, show_offon_text[index]);
  67. app->settings.show_icons = show_offon_value[index];
  68. }
  69. static void scene_settings_show_headers_changed(VariableItem* item) {
  70. App* app = variable_item_get_context(item);
  71. uint8_t index = variable_item_get_current_value_index(item);
  72. variable_item_set_current_value_text(item, show_offon_text[index]);
  73. app->settings.show_headers = show_offon_value[index];
  74. }
  75. static void scene_settings_rfid_duration_changed(VariableItem* item) {
  76. App* app = variable_item_get_context(item);
  77. uint8_t index = variable_item_get_current_value_index(item);
  78. variable_item_set_current_value_text(item, duration_text[index]);
  79. app->settings.rfid_duration = duration_value[index];
  80. }
  81. static void scene_settings_nfc_duration_changed(VariableItem* item) {
  82. App* app = variable_item_get_context(item);
  83. uint8_t index = variable_item_get_current_value_index(item);
  84. variable_item_set_current_value_text(item, duration_text[index]);
  85. app->settings.nfc_duration = duration_value[index];
  86. }
  87. static void scene_settings_subghz_repeat_changed(VariableItem* item) {
  88. App* app = variable_item_get_context(item);
  89. uint8_t index = variable_item_get_current_value_index(item);
  90. variable_item_set_current_value_text(item, repeat_text[index]);
  91. app->settings.subghz_repeat = repeat_value[index];
  92. }
  93. static void scene_settings_subghz_ext_changed(VariableItem* item) {
  94. App* app = variable_item_get_context(item);
  95. uint8_t index = variable_item_get_current_value_index(item);
  96. variable_item_set_current_value_text(item, disabled_enabled_text[index]);
  97. app->settings.subghz_use_ext_antenna = disabled_enabled_value[index];
  98. }
  99. static void scene_settings_ir_ext_changed(VariableItem* item) {
  100. App* app = variable_item_get_context(item);
  101. uint8_t index = variable_item_get_current_value_index(item);
  102. variable_item_set_current_value_text(item, disabled_enabled_text[index]);
  103. app->settings.ir_use_ext_module = disabled_enabled_value[index];
  104. }
  105. static void scene_settings_show_hidden_changed(VariableItem* item) {
  106. App* app = variable_item_get_context(item);
  107. uint8_t index = variable_item_get_current_value_index(item);
  108. variable_item_set_current_value_text(item, show_offon_text[index]);
  109. app->settings.show_hidden = show_offon_value[index];
  110. }
  111. static void scene_settings_enter_callback(void* context, uint32_t index) {
  112. App* app = context;
  113. view_dispatcher_send_custom_event(app->view_dispatcher, index);
  114. }
  115. // For each scene, implement handler callbacks
  116. void scene_settings_on_enter(void* context) {
  117. App* app = context;
  118. VariableItemList* vil = app->vil_settings;
  119. variable_item_list_reset(vil);
  120. VariableItem* item;
  121. uint8_t value_index;
  122. item = variable_item_list_add(vil, "Layout", 2, scene_settings_layout_changed, app);
  123. value_index = value_index_uint32(app->settings.layout, layout_value, 2);
  124. variable_item_set_current_value_index(item, value_index);
  125. variable_item_set_current_value_text(item, layout_text[value_index]);
  126. item = variable_item_list_add(vil, "Show Icons", 2, scene_settings_show_icons_changed, app);
  127. value_index = value_index_uint32(app->settings.show_icons, show_offon_value, 2);
  128. variable_item_set_current_value_index(item, value_index);
  129. variable_item_set_current_value_text(item, show_offon_text[value_index]);
  130. item =
  131. variable_item_list_add(vil, "Show Headers", 2, scene_settings_show_headers_changed, app);
  132. value_index = value_index_uint32(app->settings.show_headers, show_offon_value, 2);
  133. variable_item_set_current_value_index(item, value_index);
  134. variable_item_set_current_value_text(item, show_offon_text[value_index]);
  135. item = variable_item_list_add(
  136. vil, "RFID Duration", V_DURATION_COUNT, scene_settings_rfid_duration_changed, app);
  137. value_index =
  138. value_index_uint32(app->settings.rfid_duration, duration_value, V_DURATION_COUNT);
  139. variable_item_set_current_value_index(item, value_index);
  140. variable_item_set_current_value_text(item, duration_text[value_index]);
  141. item = variable_item_list_add(
  142. vil, "NFC Duration", V_DURATION_COUNT, scene_settings_nfc_duration_changed, app);
  143. value_index = value_index_uint32(app->settings.nfc_duration, duration_value, V_DURATION_COUNT);
  144. variable_item_set_current_value_index(item, value_index);
  145. variable_item_set_current_value_text(item, duration_text[value_index]);
  146. item = variable_item_list_add(
  147. vil, "SubGHz Repeat", V_REPEAT_COUNT, scene_settings_subghz_repeat_changed, app);
  148. value_index = value_index_uint32(app->settings.subghz_repeat, repeat_value, V_REPEAT_COUNT);
  149. variable_item_set_current_value_index(item, value_index);
  150. variable_item_set_current_value_text(item, repeat_text[value_index]);
  151. item =
  152. variable_item_list_add(vil, "SubGHz Ext Ant", 2, scene_settings_subghz_ext_changed, app);
  153. value_index =
  154. value_index_uint32(app->settings.subghz_use_ext_antenna, disabled_enabled_value, 2);
  155. variable_item_set_current_value_index(item, value_index);
  156. variable_item_set_current_value_text(item, disabled_enabled_text[value_index]);
  157. item = variable_item_list_add(vil, "IR Ext Module", 2, scene_settings_ir_ext_changed, app);
  158. value_index = value_index_uint32(app->settings.ir_use_ext_module, disabled_enabled_value, 2);
  159. variable_item_set_current_value_index(item, value_index);
  160. variable_item_set_current_value_text(item, disabled_enabled_text[value_index]);
  161. item = variable_item_list_add(vil, "Show Hidden", 2, scene_settings_show_hidden_changed, app);
  162. value_index = value_index_uint32(app->settings.show_hidden, show_offon_value, 2);
  163. variable_item_set_current_value_index(item, value_index);
  164. variable_item_set_current_value_text(item, show_offon_text[value_index]);
  165. // Last item is always "About"
  166. item = variable_item_list_add(vil, "About", 1, NULL, NULL);
  167. variable_item_list_set_enter_callback(vil, scene_settings_enter_callback, app);
  168. view_dispatcher_switch_to_view(app->view_dispatcher, QView_Settings);
  169. }
  170. bool scene_settings_on_event(void* context, SceneManagerEvent event) {
  171. App* app = context;
  172. bool consumed = false;
  173. if(event.type == SceneManagerEventTypeCustom) {
  174. switch(event.event) {
  175. case SCENE_SETTINGS_ABOUT:
  176. consumed = true;
  177. scene_manager_next_scene(app->scene_manager, QScene_About);
  178. break;
  179. default:
  180. break;
  181. }
  182. }
  183. return consumed;
  184. }
  185. void scene_settings_on_exit(void* context) {
  186. App* app = context;
  187. VariableItemList* vil = app->vil_settings;
  188. variable_item_list_reset(vil);
  189. quac_save_settings(app);
  190. }