unitemp.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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"
  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 { UT_TEMP_CELSIUS, UT_TEMP_FAHRENHEIT, UT_TEMP_COUNT } tempMeasureUnit;
  54. //Единицы измерения давления
  55. typedef enum {
  56. UT_PRESSURE_MM_HG,
  57. UT_PRESSURE_IN_HG,
  58. UT_PRESSURE_KPA,
  59. UT_PRESSURE_HPA,
  60. UT_PRESSURE_COUNT
  61. } pressureMeasureUnit;
  62. /* Объявление структур */
  63. //Настройки плагина
  64. typedef struct {
  65. //Бесконечная работа подсветки
  66. bool infinityBacklight;
  67. //Единица измерения температуры
  68. tempMeasureUnit temp_unit;
  69. //Единица измерения давления
  70. pressureMeasureUnit pressure_unit;
  71. // Do calculate and show heat index
  72. bool heat_index;
  73. //Последнее состояние OTG
  74. bool lastOTGState;
  75. } UnitempSettings;
  76. //Основная структура плагина
  77. typedef struct {
  78. //Система
  79. bool processing; //Флаг работы приложения. При ложном значении приложение закрывается
  80. bool sensors_ready; //Флаг готовности датчиков к опросу
  81. //Основные настройки
  82. UnitempSettings settings;
  83. //Массив указателей на датчики
  84. Sensor** sensors;
  85. //Количество загруженных датчиков
  86. uint8_t sensors_count;
  87. //SD-карта
  88. Storage* storage; //Хранилище
  89. Stream* file_stream; //Файловый поток
  90. //Экран
  91. Gui* gui;
  92. ViewDispatcher* view_dispatcher;
  93. NotificationApp* notifications;
  94. Widget* widget;
  95. Popup* popup;
  96. //Буффер для различного текста
  97. char* buff;
  98. } Unitemp;
  99. /* Объявление прототипов функций */
  100. /**
  101. * @brief Calculates the heat index in Celsius from the temperature and humidity and stores it in the sensor heat_index field
  102. *
  103. * @param sensor The sensor struct, with temperature in Celcius and humidity in percent
  104. */
  105. void unitemp_calculate_heat_index(Sensor* sensor);
  106. /**
  107. * @brief Перевод значения температуры датчика из Цельсия в Фаренгейты
  108. *
  109. * @param sensor Указатель на датчик
  110. */
  111. void uintemp_celsiumToFarengate(Sensor* sensor);
  112. /**
  113. * @brief Конвертация давления из паскалей в мм рт.ст.
  114. *
  115. * @param sensor Указатель на датчик
  116. */
  117. void unitemp_pascalToMmHg(Sensor* sensor);
  118. /**
  119. * @brief Конвертация давления из паскалей в килопаскали
  120. *
  121. * @param sensor Указатель на датчик
  122. */
  123. void unitemp_pascalToKPa(Sensor* sensor);
  124. /**
  125. * @brief Конвертация давления из паскалей в дюйм рт.ст.
  126. *
  127. * @param sensor Указатель на датчик
  128. */
  129. void unitemp_pascalToHPa(Sensor* sensor);
  130. /**
  131. *
  132. * Mod BySepa - linktr.ee/BySepa
  133. *
  134. */
  135. void unitemp_pascalToInHg(Sensor* sensor);
  136. /**
  137. * @brief Сохранение настроек на SD-карту
  138. *
  139. * @return Истина если сохранение успешное
  140. */
  141. bool unitemp_saveSettings(void);
  142. /**
  143. * @brief Загрузка настроек с SD-карты
  144. *
  145. * @return Истина если загрузка успешная
  146. */
  147. bool unitemp_loadSettings(void);
  148. extern Unitemp* app;
  149. #endif