فهرست منبع

Added new sensor - HDC1080

Victor 3 سال پیش
والد
کامیت
accb279d8e
5فایلهای تغییر یافته به همراه159 افزوده شده و 1 حذف شده
  1. 1 0
      Sensors.c
  2. 1 0
      Sensors.h
  3. 94 0
      sensors/HDC1080.c
  4. 62 0
      sensors/HDC1080.h
  5. 1 1
      unitemp.h

+ 1 - 0
Sensors.c

@@ -84,6 +84,7 @@ static const SensorType* sensorTypes[] = {
     &SHT30,
     &GXHT30,
     &LM75,
+    &HDC1080,
     &BMP180,
     &BMP280,
     &BME280};

+ 1 - 0
Sensors.h

@@ -325,4 +325,5 @@ const GPIO*
 #include "./sensors/SHT30.h"
 #include "./sensors/BMP180.h"
 #include "./sensors/HTU21x.h"
+#include "./sensors/HDC1080.h"
 #endif

+ 94 - 0
sensors/HDC1080.c

@@ -0,0 +1,94 @@
+/*
+    Unitemp - Universal temperature reader
+    Copyright (C) 2023  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 "HDC1080.h"
+#include "../interfaces/I2CSensor.h"
+
+const SensorType HDC1080 = {
+    .typename = "HDC1080",
+    .interface = &I2C,
+    .datatype = UT_DATA_TYPE_TEMP_HUM,
+    .pollingInterval = 250,
+    .allocator = unitemp_HDC1080_alloc,
+    .mem_releaser = unitemp_HDC1080_free,
+    .initializer = unitemp_HDC1080_init,
+    .deinitializer = unitemp_HDC1080_deinit,
+    .updater = unitemp_HDC1080_update};
+
+bool unitemp_HDC1080_alloc(Sensor* sensor, char* args) {
+    UNUSED(args);
+    I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance;
+
+    //Адреса на шине I2C (7 бит)
+    i2c_sensor->minI2CAdr = 0x40 << 1;
+    i2c_sensor->maxI2CAdr = 0x40 << 1;
+    return true;
+}
+
+bool unitemp_HDC1080_free(Sensor* sensor) {
+    //Нечего высвобождать, так как ничего не было выделено
+    UNUSED(sensor);
+    return true;
+}
+
+bool unitemp_HDC1080_init(Sensor* sensor) {
+    I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance;
+
+    uint8_t data[2]; // = {0b0001000};
+    unitemp_i2c_readRegArray(i2c_sensor, 0xFF, 2, data);
+    uint16_t device_id = ((uint16_t)data[0] << 8) | data[1];
+    if(device_id != 0x1050) {
+        FURI_LOG_E(
+            APP_NAME,
+            "Sensor %s returned wrong ID 0x%02X, expected 0x1050",
+            sensor->name,
+            device_id);
+        return false;
+    }
+    data[0] = 0b0001000;
+    data[1] = 0;
+    //Установка режима работы и разрядности измерений
+    unitemp_i2c_writeRegArray(i2c_sensor, 0x02, 2, data);
+
+    return true;
+}
+
+bool unitemp_HDC1080_deinit(Sensor* sensor) {
+    I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance;
+    UNUSED(i2c_sensor);
+    return true;
+}
+
+UnitempStatus unitemp_HDC1080_update(Sensor* sensor) {
+    I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance;
+
+    uint8_t data[2] = {0};
+    //Запуск измерения
+    unitemp_i2c_writeArray(i2c_sensor, 1, data);
+    furi_delay_ms(10);
+    unitemp_i2c_readArray(i2c_sensor, 2, data);
+
+    sensor->temp = ((float)(((uint16_t)data[0] << 8) | data[1]) / 65536) * 165 - 40;
+
+    data[0] = 1;
+    unitemp_i2c_writeArray(i2c_sensor, 1, data);
+    furi_delay_ms(10);
+    unitemp_i2c_readArray(i2c_sensor, 2, data);
+    sensor->hum = ((float)(((uint16_t)data[0] << 8) | data[1]) / 65536) * 100;
+
+    return UT_SENSORSTATUS_OK;
+}

+ 62 - 0
sensors/HDC1080.h

@@ -0,0 +1,62 @@
+/*
+    Unitemp - Universal temperature reader
+    Copyright (C) 2023  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_HDC1080
+#define UNITEMP_HDC1080
+
+#include "../unitemp.h"
+#include "../Sensors.h"
+extern const SensorType HDC1080;
+/**
+ * @brief Выделение памяти и установка начальных значений датчика HDC1080
+ *
+ * @param sensor Указатель на создаваемый датчик
+ * @return Истина при успехе
+ */
+bool unitemp_HDC1080_alloc(Sensor* sensor, char* args);
+
+/**
+ * @brief Инициализации датчика HDC1080
+ *
+ * @param sensor Указатель на датчик
+ * @return Истина если инициализация упспешная
+ */
+bool unitemp_HDC1080_init(Sensor* sensor);
+
+/**
+ * @brief Деинициализация датчика
+ *
+ * @param sensor Указатель на датчик
+ */
+bool unitemp_HDC1080_deinit(Sensor* sensor);
+
+/**
+ * @brief Обновление значений из датчика
+ *
+ * @param sensor Указатель на датчик
+ * @return Статус обновления
+ */
+UnitempStatus unitemp_HDC1080_update(Sensor* sensor);
+
+/**
+ * @brief Высвободить память датчика
+ *
+ * @param sensor Указатель на датчик
+ */
+bool unitemp_HDC1080_free(Sensor* sensor);
+
+#endif

+ 1 - 1
unitemp.h

@@ -40,7 +40,7 @@
 //Имя приложения
 #define APP_NAME "Unitemp"
 //Версия приложения
-#define UNITEMP_APP_VER "1.0.2-dev"
+#define UNITEMP_APP_VER "1.0.3-dev"
 //Путь хранения файлов плагина
 #define APP_PATH_FOLDER "/ext/unitemp"
 //Имя файла с настройками