mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-06-16 20:09:44 -07:00
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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];
|
||||
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;
|
||||
}
|
||||
@@ -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
|
||||
@@ -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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#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;
|
||||
}
|
||||
@@ -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_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
|
||||
Binary file not shown.
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
/* Объявление перечислений */
|
||||
//Единицы измерения температуры
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user