unitemp.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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. #ifndef UNITEMP
  16. #define UNITEMP
  17. /* Подключение стандартных библиотек */
  18. /* Подключение API Flipper Zero */
  19. //Файловый поток
  20. #include <toolbox/stream/file_stream.h>
  21. //Экран
  22. #include <gui/gui.h>
  23. #include <gui/view_dispatcher.h>
  24. #include <gui/modules/widget.h>
  25. #include <gui/modules/popup.h>
  26. //Уведомления
  27. #include <notification/notification.h>
  28. #include <notification/notification_messages.h>
  29. /* Внутренние библиотеки */
  30. //Интерфейсы подключения датчиков
  31. #include "Sensors.h"
  32. /* Объявление макроподстановок */
  33. //Имя приложения
  34. #define APP_NAME "Unitemp"
  35. //Версия приложения
  36. #define UNITEMP_APP_VER "1.4-store"
  37. //Путь хранения файлов плагина
  38. #define APP_PATH_FOLDER EXT_PATH("apps_data/unitemp")
  39. //Имя файла с настройками
  40. #define APP_FILENAME_SETTINGS "settings.cfg"
  41. //Имя файла с датчиками
  42. #define APP_FILENAME_SENSORS "sensors.cfg"
  43. //Размер буффера текста
  44. #define BUFF_SIZE 32
  45. #define UNITEMP_D
  46. #ifdef FURI_DEBUG
  47. #define UNITEMP_DEBUG(msg, ...) FURI_LOG_D(APP_NAME, msg, ##__VA_ARGS__)
  48. #else
  49. #define UNITEMP_DEBUG(msg, ...)
  50. #endif
  51. /* Объявление перечислений */
  52. //Единицы измерения температуры
  53. typedef enum {
  54. UT_TEMP_CELSIUS,
  55. UT_TEMP_FAHRENHEIT,
  56. UT_TEMP_COUNT
  57. } tempMeasureUnit;
  58. //Единицы измерения давления
  59. typedef enum {
  60. UT_PRESSURE_MM_HG,
  61. UT_PRESSURE_IN_HG,
  62. UT_PRESSURE_KPA,
  63. UT_PRESSURE_HPA,
  64. UT_PRESSURE_COUNT
  65. } pressureMeasureUnit;
  66. /* Объявление структур */
  67. //Настройки плагина
  68. typedef struct {
  69. //Бесконечная работа подсветки
  70. bool infinityBacklight;
  71. //Единица измерения температуры
  72. tempMeasureUnit temp_unit;
  73. //Единица измерения давления
  74. pressureMeasureUnit pressure_unit;
  75. // Do calculate and show heat index
  76. bool heat_index;
  77. //Последнее состояние OTG
  78. bool lastOTGState;
  79. } UnitempSettings;
  80. //Основная структура плагина
  81. typedef struct {
  82. //Система
  83. bool processing; //Флаг работы приложения. При ложном значении приложение закрывается
  84. bool sensors_ready; //Флаг готовности датчиков к опросу
  85. //Основные настройки
  86. UnitempSettings settings;
  87. //Массив указателей на датчики
  88. Sensor** sensors;
  89. //Количество загруженных датчиков
  90. uint8_t sensors_count;
  91. //SD-карта
  92. Storage* storage; //Хранилище
  93. Stream* file_stream; //Файловый поток
  94. //Экран
  95. Gui* gui;
  96. ViewPort* view_port;
  97. ViewDispatcher* view_dispatcher;
  98. NotificationApp* notifications;
  99. Widget* widget;
  100. Popup* popup;
  101. //Буффер для различного текста
  102. char* buff;
  103. } Unitemp;
  104. /* Объявление прототипов функций */
  105. /**
  106. * @brief Calculates the heat index in Celsius from the temperature and humidity and stores it in the sensor heat_index field
  107. *
  108. * @param sensor The sensor struct, with temperature in Celcius and humidity in percent
  109. */
  110. void unitemp_calculate_heat_index(Sensor* sensor);
  111. /**
  112. * @brief Перевод значения температуры датчика из Цельсия в Фаренгейты
  113. *
  114. * @param sensor Указатель на датчик
  115. */
  116. void uintemp_celsiumToFarengate(Sensor* sensor);
  117. /**
  118. * @brief Конвертация давления из паскалей в мм рт.ст.
  119. *
  120. * @param sensor Указатель на датчик
  121. */
  122. void unitemp_pascalToMmHg(Sensor* sensor);
  123. /**
  124. * @brief Конвертация давления из паскалей в килопаскали
  125. *
  126. * @param sensor Указатель на датчик
  127. */
  128. void unitemp_pascalToKPa(Sensor* sensor);
  129. /**
  130. * @brief Конвертация давления из паскалей в дюйм рт.ст.
  131. *
  132. * @param sensor Указатель на датчик
  133. */
  134. void unitemp_pascalToHPa(Sensor* sensor);
  135. /**
  136. *
  137. * Mod BySepa - linktr.ee/BySepa
  138. *
  139. */
  140. void unitemp_pascalToInHg(Sensor* sensor);
  141. /**
  142. * @brief Сохранение настроек на SD-карту
  143. *
  144. * @return Истина если сохранение успешное
  145. */
  146. bool unitemp_saveSettings(void);
  147. /**
  148. * @brief Загрузка настроек с SD-карты
  149. *
  150. * @return Истина если загрузка успешная
  151. */
  152. bool unitemp_loadSettings(void);
  153. extern Unitemp* app;
  154. #endif