Settings_view.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. #include "UnitempViews.h"
  2. #include <gui/modules/variable_item_list.h>
  3. //Текущий вид
  4. static View* view;
  5. //Список
  6. static VariableItemList* variable_item_list;
  7. static const char states[2][9] = {"Auto", "Infinity"};
  8. static const char units[2][3] = {"*C", "*F"};
  9. //Элемент списка - бесконечная подсветка
  10. VariableItem* infinity_backlight_item;
  11. //Единица измерения температуры
  12. VariableItem* temperature_unit_item;
  13. #define VIEW_ID UnitempViewSettings
  14. /**
  15. * @brief Функция обработки нажатия кнопки "Назад"
  16. *
  17. * @param context Указатель на данные приложения
  18. * @return ID вида в который нужно переключиться
  19. */
  20. static uint32_t _exit_callback(void* context) {
  21. UNUSED(context);
  22. //Костыль с зависающей подсветкой
  23. if((bool)variable_item_get_current_value_index(infinity_backlight_item) !=
  24. app->settings.infinityBacklight) {
  25. if((bool)variable_item_get_current_value_index(infinity_backlight_item)) {
  26. notification_message(app->notifications, &sequence_display_backlight_enforce_on);
  27. } else {
  28. notification_message(app->notifications, &sequence_display_backlight_enforce_auto);
  29. }
  30. }
  31. app->settings.infinityBacklight =
  32. (bool)variable_item_get_current_value_index(infinity_backlight_item);
  33. app->settings.unit = (bool)variable_item_get_current_value_index(temperature_unit_item);
  34. unitemp_saveSettings();
  35. unitemp_loadSettings();
  36. //Возврат предыдущий вид
  37. return UnitempViewMainMenu;
  38. }
  39. /**
  40. * @brief Функция обработки нажатия средней кнопки
  41. *
  42. * @param context Указатель на данные приложения
  43. * @param index На каком элементе списка была нажата кнопка
  44. */
  45. static void _enter_callback(void* context, uint32_t index) {
  46. UNUSED(context);
  47. UNUSED(index);
  48. }
  49. static void _setting_change_callback(VariableItem* item) {
  50. if(item == infinity_backlight_item) {
  51. variable_item_set_current_value_text(
  52. infinity_backlight_item,
  53. states[variable_item_get_current_value_index(infinity_backlight_item)]);
  54. }
  55. if(item == temperature_unit_item) {
  56. variable_item_set_current_value_text(
  57. temperature_unit_item,
  58. units[variable_item_get_current_value_index(temperature_unit_item)]);
  59. }
  60. }
  61. /**
  62. * @brief Создание меню редактирования настроек
  63. */
  64. void unitemp_Settings_alloc(void) {
  65. variable_item_list = variable_item_list_alloc();
  66. //Сброс всех элементов меню
  67. variable_item_list_reset(variable_item_list);
  68. infinity_backlight_item = variable_item_list_add(
  69. variable_item_list, "Backlight time", 2, _setting_change_callback, app);
  70. temperature_unit_item =
  71. variable_item_list_add(variable_item_list, "Temp. unit", 2, _setting_change_callback, app);
  72. //Добавление колбека на нажатие средней кнопки
  73. variable_item_list_set_enter_callback(variable_item_list, _enter_callback, app);
  74. //Создание вида из списка
  75. view = variable_item_list_get_view(variable_item_list);
  76. //Добавление колбека на нажатие кнопки "Назад"
  77. view_set_previous_callback(view, _exit_callback);
  78. //Добавление вида в диспетчер
  79. view_dispatcher_add_view(app->view_dispatcher, VIEW_ID, view);
  80. }
  81. void unitemp_Settings_switch(void) {
  82. //Обнуление последнего выбранного пункта
  83. variable_item_list_set_selected_item(variable_item_list, 0);
  84. variable_item_set_current_value_index(
  85. infinity_backlight_item, (uint8_t)app->settings.infinityBacklight);
  86. variable_item_set_current_value_text(
  87. infinity_backlight_item,
  88. states[variable_item_get_current_value_index(infinity_backlight_item)]);
  89. variable_item_set_current_value_index(temperature_unit_item, (uint8_t)app->settings.unit);
  90. variable_item_set_current_value_text(
  91. temperature_unit_item,
  92. units[variable_item_get_current_value_index(temperature_unit_item)]);
  93. view_dispatcher_switch_to_view(app->view_dispatcher, VIEW_ID);
  94. }
  95. void unitemp_Settings_free(void) {
  96. //Очистка списка элементов
  97. variable_item_list_free(variable_item_list);
  98. //Очистка вида
  99. view_free(view);
  100. //Удаление вида после обработки
  101. view_dispatcher_remove_view(app->view_dispatcher, VIEW_ID);
  102. }