SensorActions_view.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. Unitemp - Universal temperature reader
  3. Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n)
  4. This program is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #include "UnitempViews.h"
  16. #include <gui/modules/variable_item_list.h>
  17. #include <stdio.h>
  18. //Текущий вид
  19. static View* view;
  20. //Список
  21. static VariableItemList* variable_item_list;
  22. //Текущий датчик
  23. static Sensor* current_sensor;
  24. typedef enum carousel_info {
  25. CAROUSEL_VALUES, //Отображение значений датчиков
  26. CAROUSEL_INFO, //Отображение информации о датчике
  27. } carousel_info;
  28. extern carousel_info carousel_info_selector;
  29. #define VIEW_ID UnitempViewSensorActions
  30. /**
  31. * @brief Функция обработки нажатия кнопки "Назад"
  32. *
  33. * @param context Указатель на данные приложения
  34. * @return ID вида в который нужно переключиться
  35. */
  36. static uint32_t _exit_callback(void* context) {
  37. UNUSED(context);
  38. //Возврат предыдущий вид
  39. return UnitempViewGeneral;
  40. }
  41. /**
  42. * @brief Функция обработки нажатия средней кнопки
  43. *
  44. * @param context Указатель на данные приложения
  45. * @param index На каком элементе списка была нажата кнопка
  46. */
  47. static void _enter_callback(void* context, uint32_t index) {
  48. UNUSED(context);
  49. switch(index) {
  50. case 0:
  51. carousel_info_selector = CAROUSEL_INFO;
  52. unitemp_General_switch();
  53. return;
  54. case 1:
  55. unitemp_SensorEdit_switch(current_sensor);
  56. break;
  57. case 2:
  58. unitemp_widget_delete_switch(current_sensor);
  59. break;
  60. case 3:
  61. unitemp_SensorsList_switch();
  62. break;
  63. case 4:
  64. unitemp_Settings_switch();
  65. break;
  66. case 5:
  67. unitemp_widget_help_switch();
  68. break;
  69. case 6:
  70. unitemp_widget_about_switch();
  71. break;
  72. }
  73. }
  74. /**
  75. * @brief Создание меню действий с датчиком
  76. */
  77. void unitemp_SensorActions_alloc(void) {
  78. variable_item_list = variable_item_list_alloc();
  79. //Сброс всех элементов меню
  80. variable_item_list_reset(variable_item_list);
  81. variable_item_list_add(variable_item_list, "Info", 1, NULL, NULL);
  82. variable_item_list_add(variable_item_list, "Edit", 1, NULL, NULL);
  83. variable_item_list_add(variable_item_list, "Delete", 1, NULL, NULL);
  84. variable_item_list_add(variable_item_list, "Add new sensor", 1, NULL, NULL);
  85. variable_item_list_add(variable_item_list, "Settings", 1, NULL, NULL);
  86. variable_item_list_add(variable_item_list, "Help", 1, NULL, NULL);
  87. variable_item_list_add(variable_item_list, "About", 1, NULL, NULL);
  88. //Добавление колбека на нажатие средней кнопки
  89. variable_item_list_set_enter_callback(variable_item_list, _enter_callback, app);
  90. //Создание вида из списка
  91. view = variable_item_list_get_view(variable_item_list);
  92. //Добавление колбека на нажатие кнопки "Назад"
  93. view_set_previous_callback(view, _exit_callback);
  94. //Добавление вида в диспетчер
  95. view_dispatcher_add_view(app->view_dispatcher, VIEW_ID, view);
  96. }
  97. void unitemp_SensorActions_switch(Sensor* sensor) {
  98. current_sensor = sensor;
  99. //Обнуление последнего выбранного пункта
  100. variable_item_list_set_selected_item(variable_item_list, 0);
  101. view_dispatcher_switch_to_view(app->view_dispatcher, VIEW_ID);
  102. }
  103. void unitemp_SensorActions_free(void) {
  104. //Удаление вида после обработки
  105. view_dispatcher_remove_view(app->view_dispatcher, VIEW_ID);
  106. //Очистка списка элементов
  107. variable_item_list_free(variable_item_list);
  108. }