From bc99538ca82cee08260a4fb589de0693798e217a Mon Sep 17 00:00:00 2001
From: MX <10697207+xMasterX@users.noreply.github.com>
Date: Sat, 7 Jan 2023 18:42:38 +0300
Subject: [PATCH] Update UniTemp
https://github.com/quen0n/unitemp-flipperzero
---
applications/plugins/unitemp/README.md | 4 +-
applications/plugins/unitemp/Sensors.c | 34 ++----
applications/plugins/unitemp/Sensors.h | 2 +
.../unitemp/interfaces/OneWireSensor.c | 29 ++---
applications/plugins/unitemp/sensors/BMP180.c | 6 +-
applications/plugins/unitemp/sensors/BMx280.c | 17 +--
.../plugins/unitemp/sensors/HDC1080.c | 94 ++++++++++++++++
.../plugins/unitemp/sensors/HDC1080.h | 62 +++++++++++
applications/plugins/unitemp/sensors/HTU21x.c | 105 ++++++++++++++++++
applications/plugins/unitemp/sensors/HTU21x.h | 62 +++++++++++
.../plugins/unitemp/sensors/Sensors.xlsx | Bin 12336 -> 12455 bytes
applications/plugins/unitemp/unitemp.c | 4 +-
applications/plugins/unitemp/unitemp.h | 12 +-
.../plugins/unitemp/views/SensorEdit_view.c | 16 +--
14 files changed, 368 insertions(+), 79 deletions(-)
create mode 100644 applications/plugins/unitemp/sensors/HDC1080.c
create mode 100644 applications/plugins/unitemp/sensors/HDC1080.h
create mode 100644 applications/plugins/unitemp/sensors/HTU21x.c
create mode 100644 applications/plugins/unitemp/sensors/HTU21x.h
diff --git a/applications/plugins/unitemp/README.md b/applications/plugins/unitemp/README.md
index 80a296e9b..817f6f481 100644
--- a/applications/plugins/unitemp/README.md
+++ b/applications/plugins/unitemp/README.md
@@ -3,9 +3,9 @@
[](https://github.com/quen0n/unitemp-flipperzero/releases/)
[](https://github.com/quen0n/unitemp-flipperzero/blob/dev/LICENSE.md)
[](https://github.com/quen0n/unitemp-flipperzero/actions/workflows/build_dev.yml)
-[Flipper Zero](https://flipperzero.one/) application for reading temperature, humidity and pressure sensors using Onewire, Singlewire, I2C protocols.
+[Flipper Zero](https://flipperzero.one/) application for reading temperature, humidity and pressure sensors like a DHT11/22, DS18B20, BMP280, HTU21 and more.
## List of supported sensors (supplemented)
-
+
## 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)
## Some community photos
diff --git a/applications/plugins/unitemp/Sensors.c b/applications/plugins/unitemp/Sensors.c
index 33f62b201..87a218fe0 100644
--- a/applications/plugins/unitemp/Sensors.c
+++ b/applications/plugins/unitemp/Sensors.c
@@ -79,10 +79,12 @@ static const SensorType* sensorTypes[] = {
&Dallas,
&AM2320_SW,
&AM2320_I2C,
+ &HTU21x,
&AHT10,
&SHT30,
&GXHT30,
&LM75,
+ &HDC1080,
&BMP180,
&BMP280,
&BME280};
@@ -281,9 +283,7 @@ void unitemp_sensors_add(Sensor* sensor) {
}
bool unitemp_sensors_load(void) {
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "Loading sensors...");
-#endif
+ UNITEMP_DEBUG("Loading sensors...");
//Выделение памяти на поток
app->file_stream = file_stream_alloc(app->storage);
@@ -392,9 +392,7 @@ bool unitemp_sensors_load(void) {
}
bool unitemp_sensors_save(void) {
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "Saving sensors...");
-#endif
+ UNITEMP_DEBUG("Saving sensors...");
//Выделение памяти для потока
app->file_stream = file_stream_alloc(app->storage);
@@ -540,15 +538,12 @@ void unitemp_sensor_free(Sensor* sensor) {
bool status = false;
//Высвобождение памяти под инстанс
status = sensor->type->interface->mem_releaser(sensor);
- UNUSED(status);
-#ifdef UNITEMP_DEBUG
if(status) {
- FURI_LOG_D(APP_NAME, "Sensor %s memory successfully released", sensor->name);
+ UNITEMP_DEBUG("Sensor %s memory successfully released", sensor->name);
} else {
FURI_LOG_E(APP_NAME, "Sensor %s memory is not released", sensor->name);
}
-#endif
free(sensor->name);
//free(sensor);
}
@@ -569,9 +564,7 @@ bool unitemp_sensors_init(void) {
//Может пропасть при отключении USB
if(furi_hal_power_is_otg_enabled() != true) {
furi_hal_power_enable_otg();
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "OTG enabled");
-#endif
+ UNITEMP_DEBUG("OTG enabled");
}
if(!(*app->sensors[i]->type->initializer)(app->sensors[i])) {
FURI_LOG_E(
@@ -580,9 +573,7 @@ bool unitemp_sensors_init(void) {
app->sensors[i]->name);
result = false;
}
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "Sensor %s successfully initialized", app->sensors[i]->name);
-#endif
+ UNITEMP_DEBUG("Sensor %s successfully initialized", app->sensors[i]->name);
}
app->sensors_ready = true;
return result;
@@ -593,9 +584,7 @@ bool unitemp_sensors_deInit(void) {
//Выключение 5 В если до этого оно не было включено
if(app->settings.lastOTGState != true) {
furi_hal_power_disable_otg();
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "OTG disabled");
-#endif
+ UNITEMP_DEBUG("OTG disabled");
}
//Перебор датчиков из списка
@@ -631,10 +620,9 @@ UnitempStatus unitemp_sensor_updateData(Sensor* sensor) {
sensor->status = sensor->type->interface->updater(sensor);
-#ifdef UNITEMP_DEBUG
- if(sensor->status != UT_SENSORSTATUS_OK && sensor->status != UT_SENSORSTATUS_POLLING)
- FURI_LOG_D(APP_NAME, "Sensor %s update status %d", sensor->name, sensor->status);
-#endif
+ if(sensor->status != UT_SENSORSTATUS_OK && sensor->status != UT_SENSORSTATUS_POLLING) {
+ UNITEMP_DEBUG("Sensor %s update status %d", sensor->name, sensor->status);
+ }
if(app->settings.temp_unit == UT_TEMP_FAHRENHEIT && sensor->status == UT_SENSORSTATUS_OK)
uintemp_celsiumToFarengate(sensor);
diff --git a/applications/plugins/unitemp/Sensors.h b/applications/plugins/unitemp/Sensors.h
index 2193ce466..fcbb395fa 100644
--- a/applications/plugins/unitemp/Sensors.h
+++ b/applications/plugins/unitemp/Sensors.h
@@ -324,4 +324,6 @@ const GPIO*
#include "./sensors/DHT20.h"
#include "./sensors/SHT30.h"
#include "./sensors/BMP180.h"
+#include "./sensors/HTU21x.h"
+#include "./sensors/HDC1080.h"
#endif
diff --git a/applications/plugins/unitemp/interfaces/OneWireSensor.c b/applications/plugins/unitemp/interfaces/OneWireSensor.c
index 740ba3365..4d5db5d0e 100644
--- a/applications/plugins/unitemp/interfaces/OneWireSensor.c
+++ b/applications/plugins/unitemp/interfaces/OneWireSensor.c
@@ -58,9 +58,7 @@ OneWireBus* uintemp_onewire_bus_alloc(const GPIO* gpio) {
bus->device_count = 0;
bus->gpio = gpio;
bus->powerMode = PWR_PASSIVE;
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "one wire bus (port %d) allocated", gpio->num);
-#endif
+ UNITEMP_DEBUG("one wire bus (port %d) allocated", gpio->num);
return bus;
}
@@ -84,9 +82,7 @@ bool unitemp_onewire_bus_init(OneWireBus* bus) {
return true;
}
bool unitemp_onewire_bus_deinit(OneWireBus* bus) {
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "devices on wire %d: %d", bus->gpio->num, bus->device_count);
-#endif
+ UNITEMP_DEBUG("devices on wire %d: %d", bus->gpio->num, bus->device_count);
bus->device_count--;
if(bus->device_count <= 0) {
bus->device_count = 0;
@@ -236,15 +232,11 @@ void unitemp_onewire_bus_enum_init(void) {
uint8_t* unitemp_onewire_bus_enum_next(OneWireBus* bus) {
furi_delay_ms(10);
if(!onewire_enum_fork_bit) { // Если на предыдущем шаге уже не было разногласий
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "All devices on wire %d is found", unitemp_gpio_toInt(bus->gpio));
-#endif
+ UNITEMP_DEBUG("All devices on wire %d is found", unitemp_gpio_toInt(bus->gpio));
return 0; // то просто выходим ничего не возвращая
}
if(!unitemp_onewire_bus_start(bus)) {
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "Wire %d is empty", unitemp_gpio_toInt(bus->gpio));
-#endif
+ UNITEMP_DEBUG("Wire %d is empty", unitemp_gpio_toInt(bus->gpio));
return 0;
}
uint8_t bp = 8;
@@ -278,9 +270,8 @@ uint8_t* unitemp_onewire_bus_enum_next(OneWireBus* bus) {
if(!not1) { // Присутствует единица
next |= 0x80;
} else { // Нет ни нулей ни единиц - ошибочная ситуация
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "Wrong wire %d situation", unitemp_gpio_toInt(bus->gpio));
-#endif
+
+ UNITEMP_DEBUG("Wrong wire %d situation", unitemp_gpio_toInt(bus->gpio));
return 0;
}
}
@@ -421,9 +412,7 @@ UnitempStatus unitemp_onewire_sensor_update(Sensor* sensor) {
unitemp_onewire_bus_send_byte(instance->bus, 0xBE); // Read Scratch-pad
unitemp_onewire_bus_read_byteArray(instance->bus, buff, 9);
if(!unitemp_onewire_CRC_check(buff, 9)) {
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "Sensor %s is not found", sensor->name);
-#endif
+ UNITEMP_DEBUG("Sensor %s is not found", sensor->name);
return UT_SENSORSTATUS_TIMEOUT;
}
}
@@ -462,9 +451,7 @@ UnitempStatus unitemp_onewire_sensor_update(Sensor* sensor) {
unitemp_onewire_bus_send_byte(instance->bus, 0xBE); // Read Scratch-pad
unitemp_onewire_bus_read_byteArray(instance->bus, buff, 9);
if(!unitemp_onewire_CRC_check(buff, 9)) {
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "Failed CRC check: %s", sensor->name);
-#endif
+ UNITEMP_DEBUG("Failed CRC check: %s", sensor->name);
return UT_SENSORSTATUS_BADCRC;
}
int16_t raw = buff[0] | ((int16_t)buff[1] << 8);
diff --git a/applications/plugins/unitemp/sensors/BMP180.c b/applications/plugins/unitemp/sensors/BMP180.c
index 6fd5f2fa5..d17e78c09 100644
--- a/applications/plugins/unitemp/sensors/BMP180.c
+++ b/applications/plugins/unitemp/sensors/BMP180.c
@@ -101,9 +101,8 @@ bool unitemp_BMP180_init(Sensor* sensor) {
bmp180_instance->bmp180_cal.MC = (buff[18] << 8) | buff[19];
bmp180_instance->bmp180_cal.MD = (buff[20] << 8) | buff[21];
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(
- APP_NAME,
+
+UNITEMP_DEBUG(
"Sensor BMP180 (0x%02X) calibration values: %d, %d, %d, %d, %d, %d, %d, %d, %d, %d, %d",
i2c_sensor->currentI2CAdr,
bmp180_instance->bmp180_cal.AC1,
@@ -117,7 +116,6 @@ bool unitemp_BMP180_init(Sensor* sensor) {
bmp180_instance->bmp180_cal.MB,
bmp180_instance->bmp180_cal.MC,
bmp180_instance->bmp180_cal.MD);
-#endif
return true;
}
diff --git a/applications/plugins/unitemp/sensors/BMx280.c b/applications/plugins/unitemp/sensors/BMx280.c
index a64daaa1d..d572f09c3 100644
--- a/applications/plugins/unitemp/sensors/BMx280.c
+++ b/applications/plugins/unitemp/sensors/BMx280.c
@@ -180,22 +180,19 @@ static bool bmx280_readCalValues(I2CSensor* i2c_sensor) {
if(!unitemp_i2c_readRegArray(
i2c_sensor, TEMP_CAL_START_ADDR, 6, (uint8_t*)&bmx280_instance->temp_cal))
return false;
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(
- APP_NAME,
+
+ UNITEMP_DEBUG(
"Sensor BMx280 (0x%02X) T1-T3: %d, %d, %d",
i2c_sensor->currentI2CAdr,
bmx280_instance->temp_cal.dig_T1,
bmx280_instance->temp_cal.dig_T2,
bmx280_instance->temp_cal.dig_T3);
-#endif
if(!unitemp_i2c_readRegArray(
i2c_sensor, PRESS_CAL_START_ADDR, 18, (uint8_t*)&bmx280_instance->press_cal))
return false;
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(
- APP_NAME,
+
+ UNITEMP_DEBUG(
"Sensor BMx280 (0x%02X): P1-P9: %d, %d, %d, %d, %d, %d, %d, %d, %d",
i2c_sensor->currentI2CAdr,
bmx280_instance->press_cal.dig_P1,
@@ -207,7 +204,6 @@ static bool bmx280_readCalValues(I2CSensor* i2c_sensor) {
bmx280_instance->press_cal.dig_P7,
bmx280_instance->press_cal.dig_P8,
bmx280_instance->press_cal.dig_P9);
-#endif
if(bmx280_instance->chip_id == BME280_ID) {
uint8_t buff[7] = {0};
@@ -221,9 +217,7 @@ static bool bmx280_readCalValues(I2CSensor* i2c_sensor) {
bmx280_instance->hum_cal.dig_H5 = (buff[4] & 0x0F) | ((int16_t)buff[5] << 4);
bmx280_instance->hum_cal.dig_H6 = buff[6];
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(
- APP_NAME,
+ UNITEMP_DEBUG(
"Sensor BMx280 (0x%02X): H1-H6: %d, %d, %d, %d, %d, %d",
i2c_sensor->currentI2CAdr,
bmx280_instance->hum_cal.dig_H1,
@@ -232,7 +226,6 @@ static bool bmx280_readCalValues(I2CSensor* i2c_sensor) {
bmx280_instance->hum_cal.dig_H4,
bmx280_instance->hum_cal.dig_H5,
bmx280_instance->hum_cal.dig_H6);
-#endif
}
bmx280_instance->last_cal_update_time = furi_get_tick();
diff --git a/applications/plugins/unitemp/sensors/HDC1080.c b/applications/plugins/unitemp/sensors/HDC1080.c
new file mode 100644
index 000000000..5f2c59b24
--- /dev/null
+++ b/applications/plugins/unitemp/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 .
+*/
+#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];
+ if(!unitemp_i2c_readRegArray(i2c_sensor, 0xFF, 2, data)) return UT_SENSORSTATUS_TIMEOUT;
+ 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;
+ //Установка режима работы и разрядности измерений
+ if(!unitemp_i2c_writeRegArray(i2c_sensor, 0x02, 2, data)) return UT_SENSORSTATUS_TIMEOUT;
+
+ 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};
+ //Запуск измерения
+ if(!unitemp_i2c_writeArray(i2c_sensor, 1, data)) return UT_SENSORSTATUS_TIMEOUT;
+ furi_delay_ms(10);
+ if(!unitemp_i2c_readArray(i2c_sensor, 2, data)) return UT_SENSORSTATUS_TIMEOUT;
+
+ sensor->temp = ((float)(((uint16_t)data[0] << 8) | data[1]) / 65536) * 165 - 40;
+
+ data[0] = 1;
+ if(!unitemp_i2c_writeArray(i2c_sensor, 1, data)) return UT_SENSORSTATUS_TIMEOUT;
+ furi_delay_ms(10);
+ if(!unitemp_i2c_readArray(i2c_sensor, 2, data)) return UT_SENSORSTATUS_TIMEOUT;
+ sensor->hum = ((float)(((uint16_t)data[0] << 8) | data[1]) / 65536) * 100;
+
+ return UT_SENSORSTATUS_OK;
+}
diff --git a/applications/plugins/unitemp/sensors/HDC1080.h b/applications/plugins/unitemp/sensors/HDC1080.h
new file mode 100644
index 000000000..59ba0673c
--- /dev/null
+++ b/applications/plugins/unitemp/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 .
+*/
+#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
\ No newline at end of file
diff --git a/applications/plugins/unitemp/sensors/HTU21x.c b/applications/plugins/unitemp/sensors/HTU21x.c
new file mode 100644
index 000000000..74fc47d5d
--- /dev/null
+++ b/applications/plugins/unitemp/sensors/HTU21x.c
@@ -0,0 +1,105 @@
+/*
+ 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 .
+*/
+#include "HTU21x.h"
+#include "../interfaces/I2CSensor.h"
+
+const SensorType HTU21x = {
+ .typename = "HTU21x",
+ .interface = &I2C,
+ .datatype = UT_DATA_TYPE_TEMP_HUM,
+ .pollingInterval = 250,
+ .allocator = unitemp_HTU21x_alloc,
+ .mem_releaser = unitemp_HTU21x_free,
+ .initializer = unitemp_HTU21x_init,
+ .deinitializer = unitemp_HTU21x_deinit,
+ .updater = unitemp_HTU21x_update};
+
+static uint8_t checkCRC(uint16_t data) {
+ for(uint8_t i = 0; i < 16; i++) {
+ if(data & 0x8000)
+ data = (data << 1) ^ 0x13100;
+ else
+ data <<= 1;
+ }
+ return (data >> 8);
+}
+
+bool unitemp_HTU21x_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_HTU21x_free(Sensor* sensor) {
+ //Нечего высвобождать, так как ничего не было выделено
+ UNUSED(sensor);
+ return true;
+}
+
+bool unitemp_HTU21x_init(Sensor* sensor) {
+ I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance;
+
+ UNUSED(i2c_sensor);
+ return true;
+}
+
+bool unitemp_HTU21x_deinit(Sensor* sensor) {
+ I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance;
+ UNUSED(i2c_sensor);
+ return true;
+}
+
+UnitempStatus unitemp_HTU21x_update(Sensor* sensor) {
+ I2CSensor* i2c_sensor = (I2CSensor*)sensor->instance;
+
+ //Датчик может быть всего один, так что норм
+ static bool temp_hum = false;
+
+ uint8_t data[3];
+
+ if(sensor->status == UT_SENSORSTATUS_POLLING) {
+ if(!unitemp_i2c_readArray(i2c_sensor, 3, data)) return UT_SENSORSTATUS_TIMEOUT;
+
+ uint16_t raw = ((uint16_t)data[0] << 8) | data[1];
+ if(checkCRC(raw) != data[2]) return UT_SENSORSTATUS_BADCRC;
+
+ if(temp_hum) {
+ sensor->temp = (0.002681f * raw - 46.85f);
+ } else {
+ sensor->hum = ((0.001907 * (raw ^ 0x02)) - 6);
+ }
+ temp_hum = !temp_hum;
+ return UT_SENSORSTATUS_OK;
+ }
+
+ if(temp_hum) {
+ //Запрос температуры
+ data[0] = 0xF3;
+ if(!unitemp_i2c_writeArray(i2c_sensor, 1, data)) return UT_SENSORSTATUS_TIMEOUT;
+ } else {
+ //Запрос влажности
+ data[0] = 0xF5;
+ if(!unitemp_i2c_writeArray(i2c_sensor, 1, data)) return UT_SENSORSTATUS_TIMEOUT;
+ }
+
+ return UT_SENSORSTATUS_POLLING;
+}
diff --git a/applications/plugins/unitemp/sensors/HTU21x.h b/applications/plugins/unitemp/sensors/HTU21x.h
new file mode 100644
index 000000000..ffe062a24
--- /dev/null
+++ b/applications/plugins/unitemp/sensors/HTU21x.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 .
+*/
+#ifndef UNITEMP_HTU21x
+#define UNITEMP_HTU21x
+
+#include "../unitemp.h"
+#include "../Sensors.h"
+extern const SensorType HTU21x;
+/**
+ * @brief Выделение памяти и установка начальных значений датчика HTU21x
+ *
+ * @param sensor Указатель на создаваемый датчик
+ * @return Истина при успехе
+ */
+bool unitemp_HTU21x_alloc(Sensor* sensor, char* args);
+
+/**
+ * @brief Инициализации датчика HTU21x
+ *
+ * @param sensor Указатель на датчик
+ * @return Истина если инициализация упспешная
+ */
+bool unitemp_HTU21x_init(Sensor* sensor);
+
+/**
+ * @brief Деинициализация датчика
+ *
+ * @param sensor Указатель на датчик
+ */
+bool unitemp_HTU21x_deinit(Sensor* sensor);
+
+/**
+ * @brief Обновление значений из датчика
+ *
+ * @param sensor Указатель на датчик
+ * @return Статус обновления
+ */
+UnitempStatus unitemp_HTU21x_update(Sensor* sensor);
+
+/**
+ * @brief Высвободить память датчика
+ *
+ * @param sensor Указатель на датчик
+ */
+bool unitemp_HTU21x_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 9983aeb6ea1201003aa27a9ca54218e19e5f20c7..bd47d4948316b9b3797bc4a39106149a3724db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(1Gs#cj{)FvNg>tTf;&L+
zA2-+VPSwmJG9(x!#P8Z~4}c>vI$Ds>aoFkmc&+TN8#OavS|YJtb2QXJYnD>jNzEV`
zimu%LICrblPr)QVW*?~2nMoA*wx2|r;=rFito(_CVMg|cV_UwZwoq=Z?q!~I~|&OQ6e_^Y`4adNM2_xKDz^TiP|X&4!s56)QcFR#WS729ZG1@bmB
zS=vXc^6oK?;gEXul>ulmNtlfmFS*lop<7{?T8am6FWrj7xa`=o?2xiagQevd2z@AULMpBXW6KsE1
zslT?XNO#uRGw|vHs^gu6e6lHcf>izTQZo_$^OaxpV^zpv&NlP;Kd~-{YLHU>PrHx1
z5J!+?;`AiMIsSk1@TaExcYMXANvM-~#7PK=;viCB&cC0S1OSKy0sxHv2Za^JsY=}1Sk$*f9?Gj
DMKjj{
diff --git a/applications/plugins/unitemp/unitemp.c b/applications/plugins/unitemp/unitemp.c
index 9ff108395..31ab057d6 100644
--- a/applications/plugins/unitemp/unitemp.c
+++ b/applications/plugins/unitemp/unitemp.c
@@ -78,9 +78,7 @@ bool unitemp_saveSettings(void) {
}
bool unitemp_loadSettings(void) {
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(APP_NAME, "Loading settings...");
-#endif
+ UNITEMP_DEBUG("Loading settings...");
//Выделение памяти на поток
app->file_stream = file_stream_alloc(app->storage);
diff --git a/applications/plugins/unitemp/unitemp.h b/applications/plugins/unitemp/unitemp.h
index 144780968..5947a3e3c 100644
--- a/applications/plugins/unitemp/unitemp.h
+++ b/applications/plugins/unitemp/unitemp.h
@@ -39,19 +39,25 @@
/* Объявление макроподстановок */
//Имя приложения
#define APP_NAME "Unitemp"
+//Версия приложения
+#define UNITEMP_APP_VER "1.1"
//Путь хранения файлов плагина
#define APP_PATH_FOLDER "/ext/unitemp"
//Имя файла с настройками
#define APP_FILENAME_SETTINGS "settings.cfg"
//Имя файла с датчиками
#define APP_FILENAME_SENSORS "sensors.cfg"
-//Версия приложения
-#define UNITEMP_APP_VER "1.0"
//Размер буффера текста
#define BUFF_SIZE 32
-#define UNITEMP_DEBUG
+#define UNITEMP_D
+
+#ifdef FURI_DEBUG
+#define UNITEMP_DEBUG(msg, ...) FURI_LOG_D(APP_NAME, msg, ##__VA_ARGS__)
+#else
+#define UNITEMP_DEBUG(msg, ...)
+#endif
/* Объявление перечислений */
//Единицы измерения температуры
diff --git a/applications/plugins/unitemp/views/SensorEdit_view.c b/applications/plugins/unitemp/views/SensorEdit_view.c
index d1660bc2e..f1de4ff11 100644
--- a/applications/plugins/unitemp/views/SensorEdit_view.c
+++ b/applications/plugins/unitemp/views/SensorEdit_view.c
@@ -63,13 +63,9 @@ bool _onewire_id_exist(uint8_t* id) {
static void _onewire_scan(void) {
OneWireSensor* ow_sensor = editable_sensor->instance;
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(
- APP_NAME,
- "devices on wire %d: %d",
- ow_sensor->bus->gpio->num,
- ow_sensor->bus->device_count);
-#endif
+
+ UNITEMP_DEBUG(
+ "devices on wire %d: %d", ow_sensor->bus->gpio->num, ow_sensor->bus->device_count);
//Сканирование шины one wire
unitemp_onewire_bus_init(ow_sensor->bus);
@@ -101,9 +97,8 @@ static void _onewire_scan(void) {
memcpy(ow_sensor->deviceID, id, 8);
ow_sensor->familyCode = id[0];
-#ifdef UNITEMP_DEBUG
- FURI_LOG_D(
- APP_NAME,
+
+ UNITEMP_DEBUG(
"Found sensor's ID: %02X%02X%02X%02X%02X%02X%02X%02X",
id[0],
id[1],
@@ -113,7 +108,6 @@ static void _onewire_scan(void) {
id[5],
id[6],
id[7]);
-#endif
if(ow_sensor->familyCode != 0) {
char id_buff[10];