diff --git a/applications/plugins/unitemp/README.md b/applications/plugins/unitemp/README.md index c40ed520a..257e8a8ae 100644 --- a/applications/plugins/unitemp/README.md +++ b/applications/plugins/unitemp/README.md @@ -4,6 +4,6 @@ [![GitHub](https://img.shields.io/github/license/quen0n/unitemp-flipperzero)](https://github.com/quen0n/unitemp-flipperzero/blob/dev/LICENSE.md) [Flipper Zero](https://flipperzero.one/) application for reading temperature, humidity and pressure sensors using Onewire, Singlewire, I2C protocols. ## List of supported sensors (supplemented) -![image](https://user-images.githubusercontent.com/10090793/208763931-d15e9883-1016-4add-bd00-14d7842fd82d.png) +![image](https://user-images.githubusercontent.com/10090793/209491886-f4c5ef6e-38b2-45b8-a8e7-4aeca9e155f2.png) ## Installation Copy the contents of the repository to the `applications/plugins/unitemp` folder and build the project. Flash FZ along with resources. [More...](https://github.com/flipperdevices/flipperzero-firmware/blob/dev/documentation/fbt.md) diff --git a/applications/plugins/unitemp/Sensors.c b/applications/plugins/unitemp/Sensors.c index f81daa827..f202794f4 100644 --- a/applications/plugins/unitemp/Sensors.c +++ b/applications/plugins/unitemp/Sensors.c @@ -81,6 +81,8 @@ static const SensorType* sensorTypes[] = { &AM2320_SW, &AM2320_I2C, &AHT10, + &SHT30, + &GXHT30, &LM75, &BMP280, &BME280}; diff --git a/applications/plugins/unitemp/Sensors.h b/applications/plugins/unitemp/Sensors.h index cb98e1783..0643ffb1f 100644 --- a/applications/plugins/unitemp/Sensors.h +++ b/applications/plugins/unitemp/Sensors.h @@ -322,4 +322,5 @@ const GPIO* #include "./sensors/BMx280.h" #include "./sensors/AM2320.h" #include "./sensors/DHT20.h" +#include "./sensors/SHT30.h" #endif diff --git a/applications/plugins/unitemp/sensors/SHT30.c b/applications/plugins/unitemp/sensors/SHT30.c new file mode 100644 index 000000000..700a54dec --- /dev/null +++ b/applications/plugins/unitemp/sensors/SHT30.c @@ -0,0 +1,90 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#include "SHT30.h" +#include "../interfaces/I2CSensor.h" + +const SensorType SHT30 = { + .typename = "SHT30", + .altname = "SHT30/31/35", + .interface = &I2C, + .datatype = UT_TEMPERATURE | UT_HUMIDITY, + .pollingInterval = 1000, + .allocator = unitemp_SHT30_I2C_alloc, + .mem_releaser = unitemp_SHT30_I2C_free, + .initializer = unitemp_SHT30_init, + .deinitializer = unitemp_SHT30_I2C_deinit, + .updater = unitemp_SHT30_I2C_update}; +const SensorType GXHT30 = { + .typename = "GXHT30", + .altname = "GXHT30/31/35", + .interface = &I2C, + .datatype = UT_TEMPERATURE | UT_HUMIDITY, + .pollingInterval = 1000, + .allocator = unitemp_SHT30_I2C_alloc, + .mem_releaser = unitemp_SHT30_I2C_free, + .initializer = unitemp_GXHT30_init, + .deinitializer = unitemp_SHT30_I2C_deinit, + .updater = unitemp_SHT30_I2C_update}; + +bool unitemp_SHT30_I2C_alloc(Sensor* sensor, char* args) { + UNUSED(args); + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + + //Адреса на шине I2C (7 бит) + i2c_sensor->minI2CAdr = 0x44 << 1; + i2c_sensor->maxI2CAdr = 0x45 << 1; + return true; +} + +bool unitemp_SHT30_I2C_free(Sensor* sensor) { + //Нечего высвобождать, так как ничего не было выделено + UNUSED(sensor); + return true; +} + +bool unitemp_SHT30_init(Sensor* sensor) { + UNUSED(sensor); + return true; +} + +bool unitemp_GXHT30_init(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + //Включение режима автоматического преобразования 2 раза в сек + uint8_t data[2] = {0x22, 0x36}; + if(!unitemp_i2c_writeArray(i2c_sensor, 2, data)) return false; + return true; +} + +bool unitemp_SHT30_I2C_deinit(Sensor* sensor) { + //Нечего деинициализировать + UNUSED(sensor); + return true; +} + +UnitempStatus unitemp_SHT30_I2C_update(Sensor* sensor) { + I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance; + //Получение данных + uint8_t data[6] = {0xE0, 0x00}; + if(!unitemp_i2c_writeArray(i2c_sensor, 2, data)) return UT_SENSORSTATUS_TIMEOUT; + if(!unitemp_i2c_readArray(i2c_sensor, 6, data)) return UT_SENSORSTATUS_TIMEOUT; + + sensor->temp = -45 + 175 * (((uint16_t)(data[0] << 8) | data[1]) / 65535.0f); + sensor->hum = 100 * (((uint16_t)(data[3] << 8) | data[4]) / 65535.0f); + + return UT_SENSORSTATUS_OK; +} diff --git a/applications/plugins/unitemp/sensors/SHT30.h b/applications/plugins/unitemp/sensors/SHT30.h new file mode 100644 index 000000000..93e9d05f2 --- /dev/null +++ b/applications/plugins/unitemp/sensors/SHT30.h @@ -0,0 +1,70 @@ +/* + Unitemp - Universal temperature reader + Copyright (C) 2022 Victor Nikitchuk (https://github.com/quen0n) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ +#ifndef UNITEMP_SHT30 +#define UNITEMP_SHT30 + +#include "../unitemp.h" +#include "../Sensors.h" +extern const SensorType SHT30; +extern const SensorType GXHT30; +/** + * @brief Выделение памяти и установка начальных значений датчика SHT30 + * + * @param sensor Указатель на создаваемый датчик + * @return Истина при успехе + */ +bool unitemp_SHT30_I2C_alloc(Sensor* sensor, char* args); + +/** + * @brief Инициализации датчика SHT30 + * + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_SHT30_init(Sensor* sensor); +/** + * @brief Инициализации датчика GXHT30 + * + * @param sensor Указатель на датчик + * @return Истина если инициализация упспешная + */ +bool unitemp_GXHT30_init(Sensor* sensor); + +/** + * @brief Деинициализация датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_SHT30_I2C_deinit(Sensor* sensor); + +/** + * @brief Обновление значений из датчика + * + * @param sensor Указатель на датчик + * @return Статус обновления + */ +UnitempStatus unitemp_SHT30_I2C_update(Sensor* sensor); + +/** + * @brief Высвободить память датчика + * + * @param sensor Указатель на датчик + */ +bool unitemp_SHT30_I2C_free(Sensor* sensor); + +#endif \ No newline at end of file diff --git a/applications/plugins/unitemp/sensors/Sensors.xlsx b/applications/plugins/unitemp/sensors/Sensors.xlsx index 03522a643..b139b1b00 100644 Binary files a/applications/plugins/unitemp/sensors/Sensors.xlsx and b/applications/plugins/unitemp/sensors/Sensors.xlsx differ diff --git a/applications/plugins/unitemp/views/Widgets_view.c b/applications/plugins/unitemp/views/Widgets_view.c index 6d8702ca1..892b31f98 100644 --- a/applications/plugins/unitemp/views/Widgets_view.c +++ b/applications/plugins/unitemp/views/Widgets_view.c @@ -132,7 +132,7 @@ void unitemp_widget_delete_switch(Sensor* sensor) { app->buff, BUFF_SIZE, "\e#I2C addr:\e# 0x%02X", - ((I2CSensor*)current_sensor->instance)->currentI2CAdr); + ((I2CSensor*)current_sensor->instance)->currentI2CAdr >> 1); widget_add_text_box_element( app->widget, 0, 28, 128, 23, AlignLeft, AlignTop, app->buff, false); }