scene_settings.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. static const char* const layout_text[2] = {"Vert", "Horiz"};
  14. static const uint32_t layout_value[2] = {QUAC_APP_PORTRAIT, QUAC_APP_LANDSCAPE};
  15. static const char* const show_icons_text[2] = {"OFF", "ON"};
  16. static const uint32_t show_icons_value[2] = {false, true};
  17. static const char* const show_headers_text[2] = {"OFF", "ON"};
  18. static const uint32_t show_headers_value[2] = {false, true};
  19. #define V_RFID_DURATION_COUNT 8
  20. static const char* const rfid_duration_text[V_RFID_DURATION_COUNT] = {
  21. "500 ms",
  22. "1 sec",
  23. "1.5 sec",
  24. "2 sec",
  25. "2.5 sec",
  26. "3 sec",
  27. "5 sec",
  28. "10 sec",
  29. };
  30. static const uint32_t rfid_duration_value[V_RFID_DURATION_COUNT] = {
  31. 500,
  32. 1000,
  33. 1500,
  34. 2000,
  35. 2500,
  36. 3000,
  37. 5000,
  38. 10000,
  39. };
  40. static void scene_settings_layout_changed(VariableItem* item) {
  41. App* app = variable_item_get_context(item);
  42. uint8_t index = variable_item_get_current_value_index(item);
  43. variable_item_set_current_value_text(item, layout_text[index]);
  44. app->settings.layout = layout_value[index];
  45. }
  46. static void scene_settings_show_icons_changed(VariableItem* item) {
  47. App* app = variable_item_get_context(item);
  48. uint8_t index = variable_item_get_current_value_index(item);
  49. variable_item_set_current_value_text(item, show_icons_text[index]);
  50. app->settings.show_icons = show_icons_value[index];
  51. }
  52. static void scene_settings_show_headers_changed(VariableItem* item) {
  53. App* app = variable_item_get_context(item);
  54. uint8_t index = variable_item_get_current_value_index(item);
  55. variable_item_set_current_value_text(item, show_headers_text[index]);
  56. app->settings.show_headers = show_headers_value[index];
  57. }
  58. static void scene_settings_rfid_duration_changed(VariableItem* item) {
  59. App* app = variable_item_get_context(item);
  60. uint8_t index = variable_item_get_current_value_index(item);
  61. variable_item_set_current_value_text(item, rfid_duration_text[index]);
  62. app->settings.rfid_duration = rfid_duration_value[index];
  63. }
  64. // For each scene, implement handler callbacks
  65. void scene_settings_on_enter(void* context) {
  66. App* app = context;
  67. VariableItemList* vil = app->vil_settings;
  68. variable_item_list_reset(vil);
  69. VariableItem* item;
  70. uint8_t value_index;
  71. item = variable_item_list_add(vil, "Layout", 2, scene_settings_layout_changed, app);
  72. value_index = value_index_uint32(app->settings.layout, layout_value, 2);
  73. variable_item_set_current_value_index(item, value_index);
  74. variable_item_set_current_value_text(item, layout_text[value_index]);
  75. item = variable_item_list_add(vil, "Show Icons", 2, scene_settings_show_icons_changed, app);
  76. value_index = value_index_uint32(app->settings.show_icons, show_icons_value, 2);
  77. variable_item_set_current_value_index(item, value_index);
  78. variable_item_set_current_value_text(item, show_icons_text[value_index]);
  79. item =
  80. variable_item_list_add(vil, "Show Headers", 2, scene_settings_show_headers_changed, app);
  81. value_index = value_index_uint32(app->settings.show_headers, show_headers_value, 2);
  82. variable_item_set_current_value_index(item, value_index);
  83. variable_item_set_current_value_text(item, show_headers_text[value_index]);
  84. item = variable_item_list_add(
  85. vil, "RFID Duration", V_RFID_DURATION_COUNT, scene_settings_rfid_duration_changed, app);
  86. value_index = value_index_uint32(
  87. app->settings.rfid_duration, rfid_duration_value, V_RFID_DURATION_COUNT);
  88. variable_item_set_current_value_index(item, value_index);
  89. variable_item_set_current_value_text(item, rfid_duration_text[value_index]);
  90. // TODO: Set Enter callback here - why?? All settings have custom callbacks
  91. // variable_item_list_set_enter_callback(vil, my_cb, app);
  92. view_dispatcher_switch_to_view(app->view_dispatcher, Q_Settings);
  93. }
  94. bool scene_settings_on_event(void* context, SceneManagerEvent event) {
  95. UNUSED(context);
  96. UNUSED(event);
  97. return false;
  98. }
  99. void scene_settings_on_exit(void* context) {
  100. App* app = context;
  101. VariableItemList* vil = app->vil_settings;
  102. variable_item_list_reset(vil);
  103. quac_save_settings(app);
  104. }