Просмотр исходного кода

Added new sensors SHT30/31/35, GXHT30/31/35

Victor 3 лет назад
Родитель
Сommit
9a50f0b8bd
6 измененных файлов с 164 добавлено и 1 удалено
  1. 1 1
      README.md
  2. 2 0
      Sensors.c
  3. 1 0
      Sensors.h
  4. 90 0
      sensors/SHT30.c
  5. 70 0
      sensors/SHT30.h
  6. BIN
      sensors/Sensors.xlsx

+ 1 - 1
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)

+ 2 - 0
Sensors.c

@@ -81,6 +81,8 @@ static const SensorType* sensorTypes[] = {
     &AM2320_SW,
     &AM2320_I2C,
     &AHT10,
+    &SHT30,
+    &GXHT30,
     &LM75,
     &BMP280,
     &BME280};

+ 1 - 0
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

+ 90 - 0
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 <https://www.gnu.org/licenses/>.
+*/
+#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;
+}

+ 70 - 0
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 <https://www.gnu.org/licenses/>.
+*/
+#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

BIN
sensors/Sensors.xlsx