Merge pull request #7269 from BASM/development

Added support DS1624 and DS1621 termometer sensor (multiply and hotplug)
This commit is contained in:
Theo Arends 2019-12-27 21:06:38 +01:00 committed by GitHub
commit 9ffbf81fea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 208 additions and 2 deletions

View File

@ -107,6 +107,7 @@
| USE_PCF8574 | - | - | - | - | - | - | - | | USE_PCF8574 | - | - | - | - | - | - | - |
| USE_HIH6 | - | - | - | - | x | - | - | | USE_HIH6 | - | - | - | - | x | - | - |
| USE_DHT12 | - | - | - | - | x | - | - | | USE_DHT12 | - | - | - | - | x | - | - |
| USE_DS1624 | - | - | - | - | x | - | - |
| | | | | | | | | | | | | | | | | |
| Feature or Sensor | minimal | lite | tasmota | knx | sensors | ir | display | Remarks | Feature or Sensor | minimal | lite | tasmota | knx | sensors | ir | display | Remarks
| USE_SPI | - | - | - | - | - | - | x | | USE_SPI | - | - | - | - | - | - | x |
@ -148,4 +149,4 @@
| USE_DISPLAY_EPAPER_42 | - | - | - | - | - | - | x | | USE_DISPLAY_EPAPER_42 | - | - | - | - | - | - | x |
| USE_DISPLAY_ILI9488 | - | - | - | - | - | - | - | | USE_DISPLAY_ILI9488 | - | - | - | - | - | - | - |
| USE_DISPLAY_SSD1351 | - | - | - | - | - | - | - | | USE_DISPLAY_SSD1351 | - | - | - | - | - | - | - |
| USE_DISPLAY_RA8876 | - | - | - | - | - | - | - | | USE_DISPLAY_RA8876 | - | - | - | - | - | - | - |

View File

@ -62,4 +62,6 @@ Index | Define | Driver | Device | Address(es) | Description
39 | USE_DISPLAY_RA8876 | xdsp_10 | FT5316 | 0x38 | Touch panel controller 39 | USE_DISPLAY_RA8876 | xdsp_10 | FT5316 | 0x38 | Touch panel controller
40 | USE_TSL2591 | xsns_57 | TLS2591 | 0x29 | Light intensity sensor 40 | USE_TSL2591 | xsns_57 | TLS2591 | 0x29 | Light intensity sensor
41 | USE_DHT12 | xsns_58 | DHT12 | 0x5C | Temperature and humidity sensor 41 | USE_DHT12 | xsns_58 | DHT12 | 0x5C | Temperature and humidity sensor
42 | USE_DS1624 | xsns_59 | DS1621 | 0x48 - 0x4F | Temperature sensor
42 | USE_DS1624 | xsns_59 | DS1624 | 0x48 - 0x4F | Temperature sensor

View File

@ -50,6 +50,8 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
[Complete list](BUILDS.md) of available feature and sensors. [Complete list](BUILDS.md) of available feature and sensors.
For merge for Changelog:
- Add support for DS1624, DS1621 Temperature sensor by Leonid Myravjev
## Changelog ## Changelog
### Version 8.1.0.1 ### Version 8.1.0.1

View File

@ -137,6 +137,7 @@ extern "C" void custom_crash_callback(struct rst_info * rst_info, uint32_t stack
//#define USE_SI1145 // Add I2C code for SI1145/46/47 sensor (+1k code) //#define USE_SI1145 // Add I2C code for SI1145/46/47 sensor (+1k code)
#define USE_LM75AD // Add I2C code for LM75AD sensor (+0k5 code) #define USE_LM75AD // Add I2C code for LM75AD sensor (+0k5 code)
#define USE_DHT12 // Add I2C code for DHT12 temperature and humidity sensor (+0k7 code) #define USE_DHT12 // Add I2C code for DHT12 temperature and humidity sensor (+0k7 code)
#define USE_DS1624 // Add I2C code for DS1624, DS1621 sensor
//#define USE_APDS9960 // Add I2C code for APDS9960 Proximity Sensor. Disables SHT and VEML6070 (+4k7 code) //#define USE_APDS9960 // Add I2C code for APDS9960 Proximity Sensor. Disables SHT and VEML6070 (+4k7 code)
//#define USE_MCP230xx // Enable MCP23008/MCP23017 - Must define I2C Address in #define USE_MCP230xx_ADDR below - range 0x20 - 0x27 (+4k7 code) //#define USE_MCP230xx // Enable MCP23008/MCP23017 - Must define I2C Address in #define USE_MCP230xx_ADDR below - range 0x20 - 0x27 (+4k7 code)
// #define USE_MCP230xx_ADDR 0x20 // Enable MCP23008/MCP23017 I2C Address to use (Must be within range 0x20 through 0x27 - set according to your wired setup) // #define USE_MCP230xx_ADDR 0x20 // Enable MCP23008/MCP23017 I2C Address to use (Must be within range 0x20 through 0x27 - set according to your wired setup)

200
tasmota/xsns_59_ds1624.ino Normal file
View File

@ -0,0 +1,200 @@
/*
xsns_59_ds1624.ino - Support for I2C DS1624 Temperature Sensor
Copyright (C) 2019 Leonid Myravjev <asm@asm.pp.ru>
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 <http://www.gnu.org/licenses/>.
*/
#ifdef USE_I2C
#ifdef USE_DS1624
/*********************************************************************************************\
* DS1624,DS1621 - Temperature
*
* I2C Address: 0x48 - 0x4F
\*********************************************************************************************/
#define XSNS_59 59
#define XI2C_42 42 // See I2CDEVICES.md
#define DS1624_MEM_REGISTER 0x17 //only for ds1624, don't exists on 1621
#define DS1624_CONF_REGISTER 0xAC
#define DS1624_TEMP_REGISTER 0xAA
#define DS1624_START_REGISTER 0xEE
#define DS1624_STOP_REGISTER 0x22
#define DS1621_COUNTER_REGISTER 0xA8 //exists on 1621 and 1624(undocumented)
#define DS1621_SLOPE_REGISTER 0xA9 //exists on 1624 and 1624(undocumented)
enum {
DS1624_TYPE_DS1624,
DS1624_TYPE_DS1621
};
#define DS1624_MAX_SENSORS 8
bool ds1624_init=false;
struct {
bool valid;
float value;
int type;
char name[9];
} ds1624_sns[DS1624_MAX_SENSORS];
uint32_t DS1624_Idx2Addr(int idx) {
return 0x48 + idx;
}
void DS1624_HotPlugUp(int idx) {
uint32_t addr;
uint8_t config,tmp;
addr = DS1624_Idx2Addr(idx);
if (I2cActive(addr)) return;
if (!I2cSetDevice(addr)) return;
if (I2cValidRead8(&config, addr, DS1624_CONF_REGISTER)) {
if (I2cValidRead8(&tmp, addr, DS1624_MEM_REGISTER))
ds1624_sns[idx].type=DS1624_TYPE_DS1624;
else ds1624_sns[idx].type=DS1624_TYPE_DS1621;
if (ds1624_sns[idx].type==DS1624_TYPE_DS1621)
snprintf_P(ds1624_sns[idx].name, sizeof(ds1624_sns[idx].name), PSTR("DS1621_%d"), idx);
else snprintf_P(ds1624_sns[idx].name, sizeof(ds1624_sns[idx].name), PSTR("DS1624_%d"), idx);
I2cSetActiveFound(addr, ds1624_sns[idx].name);
ds1624_sns[idx].valid=true;
if ((config & 1) == 1) {
config &= 0xfe;
I2cWrite8(addr, DS1624_CONF_REGISTER, config); //1show off
delay(10);// by spec after writing
}
I2cValidRead(addr, DS1624_START_REGISTER, 1); //FIXME 0 must read, but 0 isn't work for tasmota
AddLog_P2(LOG_LEVEL_INFO, "Hot Plug %s addr %x config: %x", ds1624_sns[idx].name, addr, config);
}
}
void DS1624_HotPlugDown(int idx) {
uint32_t addr=DS1624_Idx2Addr(idx);
if (I2cActive(addr)==false) return;
I2cResetActive(addr);
ds1624_sns[idx].valid=false;
AddLog_P2(LOG_LEVEL_INFO, "Hot UnPlug %s", ds1624_sns[idx].name);
}
bool DS1624GetTemp(float *value, int idx)
{
uint16_t t;
bool result;
uint32_t addr=DS1624_Idx2Addr(idx);
if (!I2cValidRead16(&t, DS1624_Idx2Addr(idx), DS1624_TEMP_REGISTER)) return false;
*value = ConvertTemp(((float)(int8_t)(t>>8)) + ((t>>4)&0xf)*0.0625);
if (ds1624_sns[idx].type==DS1624_TYPE_DS1621) { // Higher resolution
uint8_t perc,remain;
if (I2cValidRead8(&remain, addr, DS1621_COUNTER_REGISTER)==false) return true;
if (I2cValidRead8(&perc, addr, DS1621_SLOPE_REGISTER)==false) return true;
*value += ((float)perc - (float)remain)/((float)perc) - 0.25;
}
return true;
}
void DS1624HotPlugScan(void)
{
uint16_t t;
for (int idx = 0; idx < DS1624_MAX_SENSORS; idx++) {
uint32_t addr=DS1624_Idx2Addr(idx);
if ((I2cActive(addr)==true) && (ds1624_sns[idx].valid==false))
continue; // is busy by another driver
if (!I2cValidRead16(&t, DS1624_Idx2Addr(idx), DS1624_TEMP_REGISTER)) {
DS1624_HotPlugDown(idx);
continue; }
DS1624_HotPlugUp(idx);
}
}
void DS1624EverySecond(void)
{
float t;
for (int i = 0; i < DS1624_MAX_SENSORS; i++) {
if (ds1624_sns[i].valid==false) continue;
if (!DS1624GetTemp(&t, i)) continue;
ds1624_sns[i].value=t;
}
}
void DS1624Show(bool json)
{
int i;
char temperature[33];
for (i = 0; i < DS1624_MAX_SENSORS; i++) {
if (ds1624_sns[i].valid==false) continue;
dtostrfd(ds1624_sns[i].value, Settings.flag2.temperature_resolution, temperature);
if (json) {
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}"), ds1624_sns[i].name, temperature);
if (0 == tele_period) { //FIXME 0==i WTF?
#ifdef USE_DOMOTICZ
DomoticzSensor(DZ_TEMP, temperature);
#endif // USE_DOMOTICZ
#ifdef USE_KNX
KnxSensor(KNX_TEMPERATURE, temperature);
#endif // USE_KNX
}
#ifdef USE_WEBSERVER
} else {
WSContentSend_PD(HTTP_SNS_TEMP, ds1624_sns[i].name, temperature, TempUnit());
#endif // USE_WEBSERVER
}
}
}
/*********************************************************************************************\
* Interface
\*********************************************************************************************/
#define FUNC_HOTPLUG_SCAN 999 // FIXME remove it after HOTPLUG supported
bool Xsns59(uint8_t function)
{
if (!I2cEnabled(XI2C_20)) { return false; }
bool result = false;
if (FUNC_INIT == function) {
if (ds1624_init==false) {
memset(ds1624_sns, 0, sizeof(ds1624_sns));
ds1624_init=true;
DS1624HotPlugScan(); //If HotPlug is off
}
}
switch (function) {
case FUNC_HOTPLUG_SCAN:
DS1624HotPlugScan();
break;
case FUNC_EVERY_SECOND:
DS1624EverySecond();
break;
case FUNC_JSON_APPEND:
DS1624Show(1);
break;
#ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR:
DS1624Show(0);
break;
#endif // USE_WEBSERVER
}
return result;
}
#endif // USE_DS1624
#endif // USE_I2C

View File

@ -188,7 +188,7 @@ a_features = [[
"USE_SHUTTER","USE_PCF8574","USE_DDSU666","USE_DEEPSLEEP", "USE_SHUTTER","USE_PCF8574","USE_DDSU666","USE_DEEPSLEEP",
"USE_SONOFF_SC","USE_SONOFF_RF","USE_SONOFF_L1","USE_EXS_DIMMER", "USE_SONOFF_SC","USE_SONOFF_RF","USE_SONOFF_L1","USE_EXS_DIMMER",
"USE_ARDUINO_SLAVE","USE_HIH6","USE_HPMA","USE_TSL2591", "USE_ARDUINO_SLAVE","USE_HIH6","USE_HPMA","USE_TSL2591",
"USE_DHT12","","USE_GPS","", "USE_DHT12","USE_DS1624","USE_GPS","",
"","","","", "","","","",
"","","","" "","","",""
]] ]]