Add support for sensor SCD30

* Add support for sensor SCD30 (#5434)
 * Add support for commands in sensor drivers
This commit is contained in:
Theo Arends 2019-03-10 13:33:32 +01:00
parent 7488a49ba9
commit 37e1b31937
16 changed files with 41 additions and 48 deletions

2
API.md
View File

@ -23,6 +23,8 @@ FUNC_JSON_APPEND | | | | x | | Extend tele
FUNC_WEB_APPEND | | | | x | | Extend webgui ajax info
FUNC_SAVE_BEFORE_RESTART | | | | x | | Just before a planned restart
FUNC_COMMAND | x | | x | x | | When a command is not recognized
FUNC_COMMAND_DRIVER | x | 6.4.1.21 | x | | | When command Driver\<id\> is executed
FUNC_COMMAND_SENSOR | x | 6.4.1.21 | | x | | When command Sensor\<id\> is executed
FUNC_MQTT_SUBSCRIBE | | 5.12.0k | x | | | At end of MQTT subscriptions
FUNC_MQTT_INIT | | 5.12.0k | x | | | Once at end of MQTT connection
FUNC_MQTT_DATA | x | 5.12.0k | x | | | Before decoding command

View File

@ -1,5 +1,7 @@
/* 6.4.1.21 20190309
* Fix exception on GUI Configure Logging and Configure Other (#5424)
* Add support for sensor SCD30 (#5434)
* Add support for commands in sensor drivers
*
* 6.4.1.20 20190304
* Changed webserver content handling from single String to small Chunks increasing RAM

View File

@ -331,6 +331,7 @@
// #define USE_RTC_ADDR 0x68 // Default I2C address 0x68
// #define USE_MGC3130 // Enable MGC3130 Electric Field Effect Sensor (I2C address 0x42) (+2k7 code, 0k3 mem)
// #define USE_MAX44009 // Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code)
// #define USE_SCD30 // Enable Sensiron SCd30 CO2 sensor (I2C address 0x61) (+3k3 code)
// #define USE_DISPLAY // Add I2C Display Support (+2k code)
#define USE_DISPLAY_MODES1TO5 // Enable display mode 1 to 5 in addition to mode 0

View File

@ -252,7 +252,7 @@ enum LightSchemes {LS_POWER, LS_WAKEUP, LS_CYCLEUP, LS_CYCLEDN, LS_RANDOM, LS_MA
enum XsnsFunctions {FUNC_SETTINGS_OVERRIDE, FUNC_MODULE_INIT, FUNC_PRE_INIT, FUNC_INIT,
FUNC_LOOP, FUNC_EVERY_50_MSECOND, FUNC_EVERY_100_MSECOND, FUNC_EVERY_200_MSECOND, FUNC_EVERY_250_MSECOND, FUNC_EVERY_SECOND,
FUNC_PREP_BEFORE_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART, FUNC_COMMAND,
FUNC_PREP_BEFORE_TELEPERIOD, FUNC_JSON_APPEND, FUNC_WEB_APPEND, FUNC_SAVE_BEFORE_RESTART, FUNC_COMMAND, FUNC_COMMAND_SENSOR, FUNC_COMMAND_DRIVER,
FUNC_MQTT_SUBSCRIBE, FUNC_MQTT_INIT, FUNC_MQTT_DATA,
FUNC_SET_POWER, FUNC_SET_DEVICE_POWER, FUNC_SHOW_SENSOR,
FUNC_RULES_PROCESS, FUNC_SERIAL, FUNC_FREE_MEM, FUNC_BUTTON_PRESSED,

View File

@ -527,8 +527,18 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
int command_code = GetCommandCode(command, sizeof(command), type, kTasmotaCommands);
if (-1 == command_code) {
if (!XdrvCommand(grpflg, type, index, dataBuf, data_len, payload, payload16)) {
type = NULL; // Unknown command
// XdrvMailbox.valid = 1;
XdrvMailbox.index = index;
XdrvMailbox.data_len = data_len;
XdrvMailbox.payload16 = payload16;
XdrvMailbox.payload = payload;
XdrvMailbox.grpflg = grpflg;
XdrvMailbox.topic = type;
XdrvMailbox.data = dataBuf;
if (!XdrvCall(FUNC_COMMAND)) {
if (!XsnsCall(FUNC_COMMAND)) {
type = NULL; // Unknown command
}
}
}
else if (CMND_BACKLOG == command_code) {
@ -711,9 +721,9 @@ void MqttDataHandler(char* topic, uint8_t* data, unsigned int data_len)
XdrvMailbox.topic = command;
XdrvMailbox.data = dataBuf;
if (CMND_SENSOR == command_code) {
XsnsCall(FUNC_COMMAND);
XsnsCall(FUNC_COMMAND_SENSOR);
} else {
XdrvCall(FUNC_COMMAND);
XdrvCall(FUNC_COMMAND_DRIVER);
}
}
else if ((CMND_SETOPTION == command_code) && (index < 82)) {

View File

@ -92,10 +92,10 @@ void KNX_CB_Action(message_t const &msg, void *arg);
//#define USE_MPU6050 // Enable MPU6050 sensor (I2C address 0x68 AD0 low or 0x69 AD0 high) (+2k6 code)
//#define USE_DS3231 // Enable DS3231 external RTC in case no Wifi is avaliable. See docs in the source file (+1k2 code)
//#define USE_MGC3130 // Enable MGC3130 Electric Field Effect Sensor (I2C address 0x42) (+2k7 code, 0k3 mem)
//#define USE_MAX44009 // Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code)
//#define USE_MAX44009 // Enable MAX44009 Ambient Light sensor (I2C addresses 0x4A and 0x4B) (+0k8 code)
#define USE_SCD30 // Enable Sensiron SCd30 CO2 sensor (I2C address 0x61) (+3k3 code)
#define USE_MHZ19 // Add support for MH-Z19 CO2 sensor (+2k code)
#define USE_SENSEAIR // Add support for SenseAir K30, K70 and S8 CO2 sensor (+2k3 code)
#define USE_SCD30 // Add support for Sensiron SCd30 CO2 sensor (+3k6 code)
#ifndef CO2_LOW
#define CO2_LOW 800 // Below this CO2 value show green light (needs PWM or WS2812 RG(B) led and enable with SetOption18 1)
#endif

View File

@ -192,20 +192,6 @@ bool (* const xdrv_func_ptr[])(uint8_t) = { // Driver Function Pointers
const uint8_t xdrv_present = sizeof(xdrv_func_ptr) / sizeof(xdrv_func_ptr[0]); // Number of drivers found
bool XdrvCommand(bool grpflg, char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload, uint16_t payload16)
{
// XdrvMailbox.valid = 1;
XdrvMailbox.index = index;
XdrvMailbox.data_len = data_len;
XdrvMailbox.payload16 = payload16;
XdrvMailbox.payload = payload;
XdrvMailbox.grpflg = grpflg;
XdrvMailbox.topic = type;
XdrvMailbox.data = dataBuf;
return XdrvCall(FUNC_COMMAND);
}
bool XdrvMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t sdataBuf)
{
XdrvMailbox.index = stopicBuf;
@ -242,6 +228,7 @@ bool XdrvCall(uint8_t Function)
result = xdrv_func_ptr[x](Function);
if (result && ((FUNC_COMMAND == Function) ||
(FUNC_COMMAND_DRIVER == Function) ||
(FUNC_MQTT_DATA == Function) ||
(FUNC_RULES_PROCESS == Function) ||
(FUNC_BUTTON_PRESSED == Function) ||

View File

@ -266,7 +266,7 @@ bool Xsns13(uint8_t function)
if (i2c_flg) {
switch (function) {
case FUNC_COMMAND:
case FUNC_COMMAND_SENSOR:
if ((XSNS_13 == XdrvMailbox.index) && (ina219_type)) {
result = Ina219CommandSensor();
}

View File

@ -373,7 +373,7 @@ bool Xsns15(uint8_t function)
case FUNC_EVERY_SECOND:
MhzEverySecond();
break;
case FUNC_COMMAND:
case FUNC_COMMAND_SENSOR:
if (XSNS_15 == XdrvMailbox.index) {
result = MhzCommandSensor();
}

View File

@ -2046,7 +2046,7 @@ bool Xsns27(uint8_t function)
case FUNC_EVERY_50_MSECOND:
APDS9960_loop();
break;
case FUNC_COMMAND:
case FUNC_COMMAND_SENSOR:
if (XSNS_27 == XdrvMailbox.index) {
result = APDS9960CommandSensor();
}

View File

@ -814,7 +814,7 @@ bool Xsns29(uint8_t function)
case FUNC_JSON_APPEND:
MCP230xx_Show(1);
break;
case FUNC_COMMAND:
case FUNC_COMMAND_SENSOR:
if (XSNS_29 == XdrvMailbox.index) {
result = MCP230xx_Command();
}

View File

@ -476,7 +476,7 @@ bool Xsns34(uint8_t function)
case FUNC_EVERY_100_MSECOND:
HxEvery100mSecond();
break;
case FUNC_COMMAND:
case FUNC_COMMAND_SENSOR:
if (XSNS_34 == XdrvMailbox.index) {
result = HxCommand();
}

View File

@ -613,7 +613,7 @@ bool Xsns36(uint8_t function)
case FUNC_EVERY_50_MSECOND:
MGC3130_loop();
break;
case FUNC_COMMAND:
case FUNC_COMMAND_SENSOR:
if (XSNS_36 == XdrvMailbox.index) {
result = MGC3130CommandSensor();
}

View File

@ -593,7 +593,7 @@ bool Xsns40(uint8_t function)
case FUNC_EVERY_SECOND:
break;
#ifdef USE_PN532_DATA_FUNCTION
case FUNC_COMMAND:
case FUNC_COMMAND_SENSOR:
if (XSNS_40 == XdrvMailbox.index) {
result = PN532_Command();
}

View File

@ -1,5 +1,5 @@
/*
xdrv_92_scd30.ino - SC30 CO2 sensor support for Sonoff-Tasmota
xsns_42_scd30.ino - SC30 CO2 sensor support for Sonoff-Tasmota
Copyright (C) 2019 Frogmore42
@ -20,8 +20,8 @@
#ifdef USE_I2C
#ifdef USE_SCD30
#define XDRV_92 92
#define XSNS_92 92
#define XSNS_42 42
#define SCD30_MAX_MISSED_READS 3
#define SONOFF_SCD30_STATE_NO_ERROR 0
#define SONOFF_SCD30_STATE_ERROR_DATA_CRC 1
@ -465,21 +465,7 @@ void Scd30Show(bool json)
* Interface
\*********************************************************************************************/
bool Xdrv92(byte function)
{
bool result = false;
if (i2c_flg) {
switch (function) {
case FUNC_COMMAND:
result = Scd30CommandSensor();
break;
}
}
return result;
}
bool Xsns92(byte function)
bool Xsns42(byte function)
{
bool result = false;
@ -488,6 +474,9 @@ bool Xsns92(byte function)
case FUNC_EVERY_SECOND:
Scd30Update();
break;
case FUNC_COMMAND:
result = Scd30CommandSensor();
break;
case FUNC_JSON_APPEND:
Scd30Show(1);
break;

View File

@ -310,7 +310,9 @@ bool XsnsCall(uint8_t Function)
}
#endif // PROFILE_XSNS_SENSOR_EVERY_SECOND
if (result && (FUNC_COMMAND == Function)) {
if (result && ((FUNC_COMMAND == Function) ||
(FUNC_COMMAND_SENSOR == Function)
)) {
break;
}
#ifdef USE_DEBUG_DRIVER