diff --git a/CODE_OWNERS.md b/CODE_OWNERS.md index 034922cb2..b71fd38fc 100644 --- a/CODE_OWNERS.md +++ b/CODE_OWNERS.md @@ -136,7 +136,7 @@ In addition to @arendst the following code is mainly owned by: | xsns_22_sr04 | Nuno Ferreira, @arendst | xsns_23_me007 | Mathias Buder | xsns_24_si1145 | -| xsns_25 | +| xsns_25_spl06-007_sensor | @rai68 | xsns_26_lm75ad | Andre Thomas | xsns_27_apds9960 | Shawn Hymel | xsns_28 | diff --git a/I2CDEVICES.md b/I2CDEVICES.md index de2bccf31..acc51435d 100644 --- a/I2CDEVICES.md +++ b/I2CDEVICES.md @@ -125,5 +125,5 @@ Index | Define | Driver | Device | Address(es) | Bus2 | Descrip 85 | USE_ENS210 | xsns_112 | ENS210 | 0x43 - 0x44 | | Temperature and humidity sensor 86 | USE_AMSX915 | xsns_114 | AMS5915 | 0x28 | | Pressure (absolute/differential) and temperature sensor 86 | USE_AMSX915 | xsns_114 | AMS6915 | 0x28 | | Pressure (absolute/differential) and temperature sensor - + 95 | USE_SPL06_007 | xsns_126 | SPL06-007 | 0x76 | | Pressure and temperature sensor NOTE: Bus2 supported on ESP32 only. diff --git a/lib/lib_i2c/SPL06_007/README.md b/lib/lib_i2c/SPL06_007/README.md new file mode 100644 index 000000000..541b511cf --- /dev/null +++ b/lib/lib_i2c/SPL06_007/README.md @@ -0,0 +1,7 @@ +# SPL06-007 +Ardino SPL06-007 Library + +This is a work in progress to create a working Arduino library for the SPL06-007 pressure sensor. I am able to get the coefficents, pressure, and temperature readings from the sensor. Need to convert to a standard Arduino library format. Code was developed and tested on an ESP32 microcontroller. + +Link to datasheet +https://datasheet.lcsc.com/szlcsc/1912111437_Goertek-SPL06-007_C233787.pdf diff --git a/lib/lib_i2c/SPL06_007/datasheets/1912111437_Goertek-SPL06-007_C233787.pdf b/lib/lib_i2c/SPL06_007/datasheets/1912111437_Goertek-SPL06-007_C233787.pdf new file mode 100644 index 000000000..163475e78 Binary files /dev/null and b/lib/lib_i2c/SPL06_007/datasheets/1912111437_Goertek-SPL06-007_C233787.pdf differ diff --git a/lib/lib_i2c/SPL06_007/examples/Pressure_Info/Pressure_Info.ino b/lib/lib_i2c/SPL06_007/examples/Pressure_Info/Pressure_Info.ino new file mode 100644 index 000000000..f6e913307 --- /dev/null +++ b/lib/lib_i2c/SPL06_007/examples/Pressure_Info/Pressure_Info.ino @@ -0,0 +1,119 @@ +#include +#include + +//#define Serial SerialUSB + +void setup() { + Wire.begin(); // begin Wire(I2C) + Serial.begin(115200); // begin Serial + + Serial.println("\nGoertek-SPL06-007 Demo\n"); + + SPL_init(); // Setup initial SPL chip registers - default i2c address 0x76 + // SPL_init(0x77); // Uncomment for alternate I2C address 0x77 +} + +void loop() { + + // ---- Register Values ---------------- + Serial.print("ID: "); + Serial.println(get_spl_id()); + + Serial.print("PRS_CFG: "); + Serial.println(get_spl_prs_cfg(),BIN); + + Serial.print("TMP_CFG: "); + Serial.println(get_spl_tmp_cfg(),BIN); + + Serial.print("MEAS_CFG: "); + Serial.println(get_spl_meas_cfg(),BIN); + + Serial.print("CFG_REG: "); + Serial.println(get_spl_cfg_reg(),BIN); + + Serial.print("INT_STS: "); + Serial.println(get_spl_int_sts(),BIN); + + Serial.print("FIFO_STS: "); + Serial.println(get_spl_fifo_sts(),BIN); + + + // ---- Coefficients ---------------- + Serial.print("c0: "); + Serial.println(get_c0()); + + Serial.print("c1: "); + Serial.println(get_c1()); + + Serial.print("c00: "); + Serial.println(get_c00()); + + Serial.print("c10: "); + Serial.println(get_c10()); + + Serial.print("c01: "); + Serial.println(get_c01()); + + Serial.print("c11: "); + Serial.println(get_c11()); + + Serial.print("c20: "); + Serial.println(get_c20()); + + Serial.print("c21: "); + Serial.println(get_c21()); + + Serial.print("c30: "); + Serial.println(get_c30()); + + + // ---- Temperature Values ---------------- + Serial.print("traw: "); + Serial.println(get_traw()); + + Serial.print("traw_sc: "); + Serial.println(get_traw_sc(),3); + + Serial.print("Temperature: "); + Serial.print(get_temp_c()); + Serial.println(" C"); + + Serial.print("Temperature: "); + Serial.print(get_temp_f()); + Serial.println(" F"); + + + // ---- Pressure Values ---------------- + Serial.print("praw: "); + Serial.println(get_praw()); + + Serial.print("praw_sc: "); + Serial.println(get_praw_sc(),3); + + Serial.print("pcomp: "); + Serial.println(get_pcomp(),2); + + Serial.print("Measured Air Pressure: "); + Serial.print(get_pressure(),2); + Serial.println(" mb"); + + + // ---- Altitude Values ---------------- + double local_pressure = 1011.3; // Look up local sea level pressure on google // Local pressure from airport website 8/22 + Serial.print("Local Airport Sea Level Pressure: "); + Serial.print(local_pressure,2); + Serial.println(" mb"); + + Serial.print("altitude: "); + Serial.print(get_altitude(get_pressure(),local_pressure),1); + Serial.println(" m"); + + Serial.print("altitude: "); + Serial.print(get_altitude_f(get_pressure(),local_pressure),1); // convert from meters to feet + Serial.println(" ft"); + + + + Serial.println("\n"); + delay(2000); +} diff --git a/lib/lib_i2c/SPL06_007/keywords.txt b/lib/lib_i2c/SPL06_007/keywords.txt new file mode 100644 index 000000000..b70bce924 --- /dev/null +++ b/lib/lib_i2c/SPL06_007/keywords.txt @@ -0,0 +1,57 @@ +####################################### +# Syntax Coloring Map For SHT21 +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +SPL06-007 KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +SPL_init KEYWORD2 +get_spl_id KEYWORD2 +get_spl_prs_cfg KEYWORD2 +get_spl_tmp_cfg KEYWORD2 +get_spl_meas_cfg KEYWORD2 +get_spl_cfg_reg KEYWORD2 +get_spl_int_sts KEYWORD2 +get_spl_fifo_sts KEYWORD2 + +get_traw KEYWORD2 +get_traw_sc KEYWORD2 +get_temp_c KEYWORD2 +get_temperature_scale_factor KEYWORD2 + + +get_pressure_scale_factor KEYWORD2 +get_pcomp KEYWORD2 +get_praw_sc KEYWORD2 +get_praw KEYWORD2 +get_pressure KEYWORD2 + +get_c0 KEYWORD2 +get_c1 KEYWORD2 +get_c00 KEYWORD2 +get_c10 KEYWORD2 +get_c01 KEYWORD2 +get_c11 KEYWORD2 +get_c20 KEYWORD2 +get_c21 KEYWORD2 +get_c30 KEYWORD2 +i2c_eeprom_write_uint8_t KEYWORD2 +i2c_eeprom_read_uint8_t KEYWORD2 + +####################################### +# Instances (KEYWORD2) +####################################### + + + + +####################################### +# Constants (LITERAL1) +####################################### diff --git a/lib/lib_i2c/SPL06_007/library.properties b/lib/lib_i2c/SPL06_007/library.properties new file mode 100644 index 000000000..74a199a35 --- /dev/null +++ b/lib/lib_i2c/SPL06_007/library.properties @@ -0,0 +1,11 @@ +name=SPL06-007 +version=0.1.0 +author=rv701 +maintainer=rv701 +sentence=SPL06-007 library for Arduino processors +paragraph=Supports SPL06-007 I2C pressure sensor. +category=Sensors +url=https://github.com/rv701/SPL06-007 +architectures=* +includes=SPL06-007.h + diff --git a/lib/lib_i2c/SPL06_007/src/SPL06-007.cpp b/lib/lib_i2c/SPL06_007/src/SPL06-007.cpp new file mode 100644 index 000000000..33ce591c7 --- /dev/null +++ b/lib/lib_i2c/SPL06_007/src/SPL06-007.cpp @@ -0,0 +1,371 @@ +#include "SPL06-007.h" +#include "Wire.h" + +uint8_t SPL_CHIP_ADDRESS = 0x76; + +void SPL_init(uint8_t spl_address) +{ + if(spl_address == 0x77) + SPL_CHIP_ADDRESS = 0x77; + + // ---- Oversampling of >8x for temperature or pressuse requires FIFO operational mode which is not implemented --- + // ---- Use rates of 8x or less until feature is implemented --- + i2c_eeprom_write_uint8_t(SPL_CHIP_ADDRESS, 0X06, 0x03); // Pressure 8x oversampling + + i2c_eeprom_write_uint8_t(SPL_CHIP_ADDRESS, 0X07, 0X83); // Temperature 8x oversampling + + i2c_eeprom_write_uint8_t(SPL_CHIP_ADDRESS, 0X08, 0B0111); // continuous temp and pressure measurement + + i2c_eeprom_write_uint8_t(SPL_CHIP_ADDRESS, 0X09, 0X00); // FIFO Pressure measurement +} + +uint8_t get_spl_id() +{ + return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x0D); +} + +uint8_t get_spl_prs_cfg() +{ + return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x06); +} + +uint8_t get_spl_tmp_cfg() +{ + return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x07); +} + +uint8_t get_spl_meas_cfg() +{ + return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x08); +} + +uint8_t get_spl_cfg_reg() +{ + return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x09); +} + +uint8_t get_spl_int_sts() +{ + return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x0A); +} + +uint8_t get_spl_fifo_sts() +{ + return i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0x0B); +} + +float get_traw_sc() { + int32_t traw = get_traw(); + return (float(traw)/get_temperature_scale_factor()); +} + +float get_temp_c() { + int16_t c0,c1; + c0 = get_c0(); + c1 = get_c1(); + float traw_sc = get_traw_sc(); + return (float(c0) * 0.5f) + (float(c1) * traw_sc); +} + +float get_temperature_scale_factor() +{ + float k; + uint8_t tmp_Byte; + tmp_Byte = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X07); // MSB + //tmp_Byte = tmp_Byte >> 4; //Focus on bits 6-4 + tmp_Byte = tmp_Byte & 0B00000111; + + switch (tmp_Byte) + { + case 0B000: + k = 524288.0f; + break; + + case 0B001: + k = 1572864.0f; + break; + + case 0B010: + k = 3670016.0f; + break; + + case 0B011: + k = 7864320.0f; + break; + + case 0B100: + k = 253952.0f; + break; + + case 0B101: + k = 516096.0f; + break; + + case 0B110: + k = 1040384.0f; + break; + + case 0B111: + k = 2088960.0f; + break; + } + return k; +} + + +int32_t get_traw() +{ + int32_t tmp; + uint8_t tmp_MSB,tmp_LSB,tmp_XLSB; + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X03); // MSB + + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X04); // LSB + + tmp_XLSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X05); // XLSB + + tmp = (tmp_MSB << 8) | tmp_LSB; + tmp = (tmp << 8) | tmp_XLSB; + + if(tmp & (1 << 23)) + tmp = tmp | 0XFF000000; // Set left bits to one for 2's complement conversion of negitive number + return tmp; +} + +float get_praw_sc() +{ + int32_t praw = get_praw(); + return (float(praw)/get_pressure_scale_factor()); +} + +float get_pcomp() +{ + int32_t c00,c10; + int16_t c01,c11,c20,c21,c30; + c00 = get_c00(); + c10 = get_c10(); + c01 = get_c01(); + c11 = get_c11(); + c20 = get_c20(); + c21 = get_c21(); + c30 = get_c30(); + float traw_sc = get_traw_sc(); + float praw_sc = get_praw_sc(); + return float(c00) + praw_sc * (float(c10) + praw_sc * (float(c20) + praw_sc * float(c30))) + traw_sc * float(c01) + traw_sc * praw_sc * ( float(c11) + praw_sc * float(c21)); +} + +float get_pressure() +{ + return get_pcomp() / 100; // convert to mb +} + +float get_pressure_scale_factor() +{ + float k; + + uint8_t tmp_Byte; + tmp_Byte = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X06); // MSB + + tmp_Byte = tmp_Byte & 0B00000111; // Focus on 2-0 oversampling rate + + + switch (tmp_Byte) // oversampling rate + { + case 0B000: + k = 524288.0f; + break; + + case 0B001: + k = 1572864.0f; + break; + + case 0B010: + k = 3670016.0f; + break; + + case 0B011: + k = 7864320.0f; + break; + + case 0B100: + k = 253952.0f; + break; + + case 0B101: + k = 516096.0f; + break; + + case 0B110: + k = 1040384.0f; + break; + + case 0B111: + k = 2088960.0f; + break; + } + + return k; +} + +int32_t get_praw() +{ + int32_t tmp; + uint8_t tmp_MSB,tmp_LSB,tmp_XLSB; + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X00); // MSB + + + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X01); // LSB + + + tmp_XLSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X02); // XLSB + + + tmp = (tmp_MSB << 8) | tmp_LSB; + tmp = (tmp << 8) | tmp_XLSB; + + if(tmp & (1 << 23)) + tmp = tmp | 0XFF000000; // Set left bits to one for 2's complement conversion of negitive number + + + return tmp; +} + +int16_t get_c0() +{ + int16_t tmp; + uint8_t tmp_MSB,tmp_LSB; + + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X10); + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X11); + + tmp_LSB = tmp_LSB >> 4; + + tmp = (tmp_MSB << 4) | tmp_LSB; + + if(tmp & (1 << 11)) // Check for 2's complement negative number + tmp = tmp | 0XF000; // Set left bits to one for 2's complement conversion of negitive number + return tmp; +} + +int16_t get_c1() +{ + int16_t tmp; + uint8_t tmp_MSB,tmp_LSB; + + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X11); + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X12); + + tmp_MSB = tmp_MSB & 0XF; + + tmp = (tmp_MSB << 8) | tmp_LSB; + + if(tmp & (1 << 11)) // Check for 2's complement negative number + tmp = tmp | 0XF000; // Set left bits to one for 2's complement conversion of negitive number + + return tmp; +} + +int32_t get_c00() +{ + int32_t tmp; + uint8_t tmp_MSB,tmp_LSB,tmp_XLSB; + + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X13); + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X14); + tmp_XLSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X15); + tmp = (tmp_MSB & 0x80 ? 0xFFF00000 : 0) | ((uint32_t)tmp_MSB << 12) | ((uint32_t)tmp_LSB << 4) | (((uint32_t)tmp_XLSB & 0xF0) >> 4); + return tmp; +} + +int32_t get_c10() +{ + int32_t tmp; + uint8_t tmp_MSB,tmp_LSB,tmp_XLSB; + + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X15); // 4 bits + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X16); // 8 bits + tmp_XLSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X17); // 8 bits + tmp = (tmp_MSB & 0x8 ? 0xFFF00000 : 0) | (((uint32_t)tmp_MSB & 0x0F) << 16) | ((uint32_t)tmp_LSB << 8) | (uint32_t)tmp_XLSB; + return tmp; +} + +int16_t get_c01() +{ + int16_t tmp; + uint8_t tmp_MSB,tmp_LSB; + + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X18); + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X19); + + tmp = (tmp_MSB << 8) | tmp_LSB; + return tmp; +} + +int16_t get_c11() +{ + int16_t tmp; + uint8_t tmp_MSB,tmp_LSB; + + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1A); + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1B); + + tmp = (tmp_MSB << 8) | tmp_LSB; + return tmp; +} + +int16_t get_c20() +{ + int16_t tmp; + uint8_t tmp_MSB,tmp_LSB; + + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1C); + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1D); + + tmp = (tmp_MSB << 8) | tmp_LSB; + return tmp; +} + +int16_t get_c21() +{ + int16_t tmp; + uint8_t tmp_MSB,tmp_LSB; + + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1E); + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X1F); + + tmp = (tmp_MSB << 8) | tmp_LSB; + return tmp; +} + +int16_t get_c30() +{ + int16_t tmp; + uint8_t tmp_MSB,tmp_LSB; + + tmp_MSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X20); + tmp_LSB = i2c_eeprom_read_uint8_t(SPL_CHIP_ADDRESS, 0X21); + + tmp = (tmp_MSB << 8) | tmp_LSB; + return tmp; +} + +void i2c_eeprom_write_uint8_t( uint8_t deviceaddress, uint8_t eeaddress, uint8_t data ) +{ + uint8_t rdata = data; + delay(5); // Make sure to delay log enough for EEPROM I2C refresh time + Wire.beginTransmission(deviceaddress); + Wire.write((uint8_t)(eeaddress)); + Wire.write(rdata); + Wire.endTransmission(); +} + +uint8_t i2c_eeprom_read_uint8_t( uint8_t deviceaddress, uint8_t eeaddress ) +{ + uint8_t rdata = 0xFF; + Wire.beginTransmission(deviceaddress); + Wire.write(eeaddress); + Wire.endTransmission(false); // false to not release the line + + Wire.requestFrom(deviceaddress,1); + if (Wire.available()) rdata = Wire.read(); + return rdata; +} diff --git a/lib/lib_i2c/SPL06_007/src/SPL06-007.h b/lib/lib_i2c/SPL06_007/src/SPL06-007.h new file mode 100644 index 000000000..807ff5b27 --- /dev/null +++ b/lib/lib_i2c/SPL06_007/src/SPL06-007.h @@ -0,0 +1,37 @@ +#include "Arduino.h" + +void SPL_init(uint8_t spl_address=0x76); + +uint8_t get_spl_id(); // Get ID Register 0x0D +uint8_t get_spl_prs_cfg(); // Get PRS_CFG Register 0x06 +uint8_t get_spl_tmp_cfg(); // Get TMP_CFG Register 0x07 +uint8_t get_spl_meas_cfg(); // Get MEAS_CFG Register 0x08 +uint8_t get_spl_cfg_reg(); // Get CFG_REG Register 0x09 +uint8_t get_spl_int_sts(); // Get INT_STS Register 0x0A +uint8_t get_spl_fifo_sts(); // Get FIFO_STS Register 0x0B + + +int32_t get_traw(); +float get_traw_sc(); +float get_temp_c(); +float get_temperature_scale_factor(); + +int32_t get_praw(); +float get_praw_sc(); +float get_pcomp(); +float get_pressure_scale_factor(); +float get_pressure(); + +int16_t get_c0(); +int16_t get_c1(); +int32_t get_c00(); +int32_t get_c10(); +int16_t get_c01(); +int16_t get_c11(); +int16_t get_c20(); +int16_t get_c21(); +int16_t get_c30(); + +void i2c_eeprom_write_uint8_t( uint8_t deviceaddress, uint8_t eeaddress, uint8_t data ); +uint8_t i2c_eeprom_read_uint8_t( uint8_t deviceaddress, uint8_t eeaddress ); + diff --git a/tasmota/include/tasmota_configurations.h b/tasmota/include/tasmota_configurations.h index 6c17a1fdc..61c805bfb 100644 --- a/tasmota/include/tasmota_configurations.h +++ b/tasmota/include/tasmota_configurations.h @@ -258,6 +258,7 @@ #define USE_LOX_O2 // Add support for LuminOx LOX O2 Sensor (+0k8 code) #undef DEBUG_THEO // Disable debug code #undef USE_DEBUG_DRIVER // Disable debug code +//#define USE_SPL06_007 // Adds support for SPL06_007 (+10k2 code) #endif // FIRMWARE_SENSORS /*********************************************************************************************\ diff --git a/tasmota/tasmota_support/support_features.ino b/tasmota/tasmota_support/support_features.ino index 8489f8fe5..673b442ab 100644 --- a/tasmota/tasmota_support/support_features.ino +++ b/tasmota/tasmota_support/support_features.ino @@ -916,6 +916,9 @@ constexpr uint32_t feature[] = { #if defined(USE_SPI) && defined(USE_SPI_LORA) 0x00000010 | // xdrv_73_9_lora.ino #endif +#if defined(USE_I2C) && defined(USE_SPL06_007) + 0x10000000 | // xsns_25_spl006-7_sensor.ino +#endif // 0x00000020 | // // 0x00000040 | // // 0x00000080 | // diff --git a/tasmota/tasmota_xsns_sensor/xsns_25_spl06-007_sensor.ino b/tasmota/tasmota_xsns_sensor/xsns_25_spl06-007_sensor.ino new file mode 100644 index 000000000..5d2fe0b75 --- /dev/null +++ b/tasmota/tasmota_xsns_sensor/xsns_25_spl06-007_sensor.ino @@ -0,0 +1,133 @@ +/* + xsns_25_spl06-007_sensor.ino - SPL06-007 Temperature and Pressure sensor support for Tasmota + + Copyright (C) 2024 rai68 + + 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 . +*/ + +#ifdef USE_I2C +#ifdef USE_SPL06_007 + +/*********************************************************************************************\ + * SPL006/7 Temperature and Pressure sensor support for Tasmota + * + * Source: rv701 + * + * I2C Address: 0x76 +\*********************************************************************************************/ + +#define XSNS_25 25 +#define XI2C_95 95 // See I2CDEVICES.md + +#include "SPL06-007.h" + +#define SPL007_ADDRESS 0x76 + +struct SPL007 { + float temperature = NAN; + float pressure = NAN; + uint8_t address; + bool valid = false; +} spl007_s; + +/********************************************************************************************/ + +void spl007Detect(void) +{ + if (!I2cActive(SPL007_ADDRESS)) + { + SPL_init(); + if (get_spl_id() != 16) { + AddLog(LOG_LEVEL_ERROR, PSTR("SPL06-007:@%02X not found error!"), SPL007_ADDRESS); + return; + } + spl007_s.valid = true; + I2cSetActiveFound(SPL007_ADDRESS, "SPL06-007"); + } +} + +void spl007Update(void) // Perform every n second +{ + spl007_s.temperature = ConvertTemp(get_temp_c()); + spl007_s.pressure = ConvertPressure(get_pressure()); +} + +void spl007Show(bool json) +{ + + float sealevel = ConvertPressureForSeaLevel(spl007_s.pressure); + char sea_pressure[33]; + dtostrfd(sealevel, Settings->flag2.pressure_resolution, sea_pressure); + + char str_pressure[33]; + dtostrfd(spl007_s.pressure, Settings->flag2.pressure_resolution, str_pressure); + + if (json) { + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%*_f,\"" D_JSON_PRESSURE "\":%s"), + "SPL06-007", Settings->flag2.temperature_resolution, &spl007_s.temperature, str_pressure); + if (Settings->altitude != 0) { + ResponseAppend_P(PSTR(",\"" D_JSON_PRESSUREATSEALEVEL "\":%s"), sea_pressure); + } + ResponseJsonEnd(); +#ifdef USE_DOMOTICZ + // Domoticz and knx only support one temp sensor + if ((0 == TasmotaGlobal.tele_period)) { + DomoticzFloatSensor(DZ_TEMP, spl007_s.temperature); + } +#endif // USE_DOMOTICZ +#ifdef USE_WEBSERVER + } else { + + WSContentSend_Temp("SPL06-007", spl007_s.temperature); + WSContentSend_PD(HTTP_SNS_PRESSURE, "SPL06-007", str_pressure, PressureUnit().c_str()); + if (Settings->altitude != 0) { + WSContentSend_PD(HTTP_SNS_SEAPRESSURE, "SPL06-007", sea_pressure, PressureUnit().c_str()); + } +#endif // USE_WEBSERVER + } +} + +/*********************************************************************************************\ + * Interface +\*********************************************************************************************/ + +bool Xsns25(uint32_t function) +{ + if (!I2cEnabled(XI2C_95)) { return false; } + bool result = false; + + if (FUNC_INIT == function) { + spl007Detect(); + } + else if (spl007_s.valid) { + switch (function) { + case FUNC_EVERY_SECOND: + spl007Update(); + break; + case FUNC_JSON_APPEND: + spl007Show(1); + break; +#ifdef USE_WEBSERVER + case FUNC_WEB_SENSOR: + spl007Show(0); + break; +#endif // USE_WEBSERVER + } + } + return result; +} + +#endif // USE_SPL06_007 +#endif // USE_I2C diff --git a/tools/decode-status.py b/tools/decode-status.py index d4fd60e45..2b000d999 100755 --- a/tools/decode-status.py +++ b/tools/decode-status.py @@ -305,7 +305,7 @@ a_features = [[ "USE_HC8","USE_HDMI_CEC","USE_BLE_ESP32","USE_MATTER_DEVICE" ],[ "USE_MAGIC_SWITCH","USE_PIPSOLAR","USE_GPIO_VIEWER","USE_AMSX915", - "USE_SPI_LORA","","","", + "USE_SPI_LORA","USE_SPL06_007","","", "","","","", "","","","", "","","","",