mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-25 19:56:30 +00:00
Refactor I2C driver detection phase 2
This commit is contained in:
parent
e8b9823e6a
commit
f32b64d5de
66
API.md
66
API.md
@ -68,3 +68,69 @@ FUNC_DISPLAY_FONT_SIZE | | 6.1.1.7 |
|
|||||||
FUNC_DISPLAY_ROTATION | | 6.1.1.7 |
|
FUNC_DISPLAY_ROTATION | | 6.1.1.7 |
|
||||||
FUNC_DISPLAY_DRAW_STRING | | 6.1.1.7 |
|
FUNC_DISPLAY_DRAW_STRING | | 6.1.1.7 |
|
||||||
FUNC_DISPLAY_ONOFF | | 6.1.1.7 |
|
FUNC_DISPLAY_ONOFF | | 6.1.1.7 |
|
||||||
|
|
||||||
|
## Init sequence
|
||||||
|
The following list contains the callback init sequence
|
||||||
|
|
||||||
|
CFG: Loaded from flash at FB, Count 1581
|
||||||
|
xdrv - FUNC_SETTINGS_OVERRIDE
|
||||||
|
xdrv - FUNC_PIN_STATE
|
||||||
|
xsns - FUNC_PIN_STATE
|
||||||
|
xdrv - FUNC_MODULE_INIT
|
||||||
|
xlgt - FUNC_MODULE_INIT
|
||||||
|
xdrv - FUNC_PRE_INIT
|
||||||
|
xnrg - FUNC_PRE_INIT
|
||||||
|
SRC: Restart
|
||||||
|
xdrv - FUNC_SET_POWER
|
||||||
|
xlgt - FUNC_SET_CHANNELS
|
||||||
|
xdrv - FUNC_SET_DEVICE_POWER
|
||||||
|
Project tasmota Wemos 2 Version 7.0.0.3(tasmota)-STAGE
|
||||||
|
xdrv - FUNC_INIT
|
||||||
|
xsns - FUNC_INIT
|
||||||
|
I2C: ADS1115 found at 0x48
|
||||||
|
xdrv - FUNC_LOOP
|
||||||
|
xsns - FUNC_LOOP
|
||||||
|
xdrv - FUNC_EVERY_50_MSECOND
|
||||||
|
xlgt - FUNC_SET_CHANNELS
|
||||||
|
xsns - FUNC_EVERY_50_MSECOND
|
||||||
|
xdrv - FUNC_EVERY_100_MSECOND
|
||||||
|
xsns - FUNC_EVERY_100_MSECOND
|
||||||
|
xdrv - FUNC_EVERY_250_MSECOND
|
||||||
|
xsns - FUNC_EVERY_250_MSECOND
|
||||||
|
xdrv - FUNC_EVERY_SECOND
|
||||||
|
xsns - FUNC_EVERY_SECOND
|
||||||
|
WIF: Attempting connection...
|
||||||
|
WIF: Network (re)scan started...
|
||||||
|
WIF: Attempting connection...
|
||||||
|
WIF: Attempting connection...
|
||||||
|
WIF: Attempting connection...
|
||||||
|
WIF: Network 0, AP1, SSId indebuurt1, Channel 1, BSSId 24:D3:F2:97:C0:A1, RSSI -86, Encryption 1
|
||||||
|
WIF: Network 1, AP2, SSId indebuurt2, Channel 5, BSSId A0:AB:1B:7D:42:AC, RSSI -42, Encryption 1
|
||||||
|
WIF: Network 2, AP-, SSId indebuurt3, Channel 12, BSSId 60:E3:27:58:77:E6, RSSI -84, Encryption 1
|
||||||
|
WIF: Connecting to AP2 indebuurt2 in mode 11N as wemos2...
|
||||||
|
WIF: Attempting connection...
|
||||||
|
WIF: Attempting connection...
|
||||||
|
WIF: Attempting connection...
|
||||||
|
WIF: Connected
|
||||||
|
xdrv - FUNC_WEB_ADD_HANDLER
|
||||||
|
xsns - FUNC_WEB_ADD_HANDLER
|
||||||
|
HTP: Web server active on wemos2 with IP address 192.168.2.191
|
||||||
|
NTP: Drift 0, (UTC) Wed Nov 06 13:57:08 2019, (DST) Sun Mar 31 02:00:00 2019, (STD) Sun Oct 27 03:00:00 2019
|
||||||
|
APP: Boot Count 500
|
||||||
|
MQT: Attempting connection...
|
||||||
|
MQT: Connected
|
||||||
|
MQT: tele/wemos2/LWT = Online (retained)
|
||||||
|
MQT: cmnd/wemos2/POWER =
|
||||||
|
MQT: Subscribe to cmnd/wemos2/#
|
||||||
|
MQT: Subscribe to cmnd/sonoffs/#
|
||||||
|
MQT: Subscribe to cmnd/DVES_15568C_fb/#
|
||||||
|
xdrv - FUNC_MQTT_SUBSCRIBE
|
||||||
|
MQT: tele/wemos2/INFO1 = {"Module":"Generic","Version":"7.0.0.3(tasmota)","FallbackTopic":"cmnd/DVES_15568C_fb/","GroupTopic":"cmnd/sonoffs/"}
|
||||||
|
MQT: tele/wemos2/INFO2 = {"WebServerMode":"Admin","Hostname":"wemos2","IPAddress":"192.168.2.191"}
|
||||||
|
MQT: tele/wemos2/INFO3 = {"RestartReason":"Software/System restart"}
|
||||||
|
MQT: stat/wemos2/RESULT = {"POWER1":"OFF"}
|
||||||
|
MQT: stat/wemos2/POWER1 = OFF
|
||||||
|
MQT: stat/wemos2/RESULT = {"POWER2":"ON"}
|
||||||
|
MQT: stat/wemos2/POWER2 = ON
|
||||||
|
xdrv - FUNC_MQTT_INIT
|
||||||
|
CFG: Saved to flash at FA, Count 1582, Bytes 4096
|
@ -60,3 +60,6 @@ Index | Define | Driver | Device | Address(es) | Description
|
|||||||
34 | USE_PAJ7620 | xsns_50 | PAJ7620 | 0x73 | Gesture sensor
|
34 | USE_PAJ7620 | xsns_50 | PAJ7620 | 0x73 | Gesture sensor
|
||||||
35 | USE_INA226 | xsns_54 | INA226 | 0x40 - 0x41, 0x44 - 0x45 | Low voltage current sensor
|
35 | USE_INA226 | xsns_54 | INA226 | 0x40 - 0x41, 0x44 - 0x45 | Low voltage current sensor
|
||||||
36 | USE_HIH6 | xsns_55 | HIH6130 | 0x27 | Temperature and Humidity sensor
|
36 | USE_HIH6 | xsns_55 | HIH6130 | 0x27 | Temperature and Humidity sensor
|
||||||
|
37 | USE_24C256 | xdrv_10 | 24C256 | 0x50 | Scripter EEPROM storage
|
||||||
|
38 | USE_DISPLAY_ILI9488 | xdsp_08 | FT6236 | 0x38 | Touch panel controller
|
||||||
|
39 | USE_DISPLAY_RA8876 | xdsp_10 | FT5316 | 0x38 | Touch panel controller
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
* Initial support for I2C driver runtime control using command I2CDriver and document I2CDEVICES.md
|
* Initial support for I2C driver runtime control using command I2CDriver and document I2CDEVICES.md
|
||||||
* Fix random crash caused by UPNP flood
|
* Fix random crash caused by UPNP flood
|
||||||
* Add support for Honeywell HPMA115S0 particle concentration sensor by David Hunt (#6843)
|
* Add support for Honeywell HPMA115S0 particle concentration sensor by David Hunt (#6843)
|
||||||
|
* Remove driver xsns_12_ads1115_i2cdev replaced by xsns_12_ads1115
|
||||||
*
|
*
|
||||||
* 7.0.0.2 20191102
|
* 7.0.0.2 20191102
|
||||||
* Add command WebColor19 to control color of Module and Name (#6811)
|
* Add command WebColor19 to control color of Module and Name (#6811)
|
||||||
|
@ -1486,6 +1486,17 @@ void I2cScan(char *devs, unsigned int devs_len)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void I2cResetActive(uint32_t addr, uint32_t count = 1)
|
||||||
|
{
|
||||||
|
addr &= 0x7F; // Max I2C address is 127
|
||||||
|
count &= 0x7F; // Max 4 x 32 bits available
|
||||||
|
while (count-- && (addr < 128)) {
|
||||||
|
i2c_active[addr / 32] &= ~(1 << (addr % 32));
|
||||||
|
addr++;
|
||||||
|
}
|
||||||
|
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("I2C: Active %08X,%08X,%08X,%08X"), i2c_active[0], i2c_active[1], i2c_active[2], i2c_active[3]);
|
||||||
|
}
|
||||||
|
|
||||||
void I2cSetActive(uint32_t addr, uint32_t count = 1)
|
void I2cSetActive(uint32_t addr, uint32_t count = 1)
|
||||||
{
|
{
|
||||||
addr &= 0x7F; // Max I2C address is 127
|
addr &= 0x7F; // Max I2C address is 127
|
||||||
@ -1506,19 +1517,14 @@ bool I2cActive(uint32_t addr)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool I2cDevice(uint32_t addr)
|
bool I2cSetDevice(uint32_t addr)
|
||||||
{
|
{
|
||||||
addr &= 0x7F; // Max I2C address is 127
|
addr &= 0x7F; // Max I2C address is 127
|
||||||
if (I2cActive(addr)) {
|
if (I2cActive(addr)) {
|
||||||
return false; // If already active report as not present;
|
return false; // If already active report as not present;
|
||||||
}
|
}
|
||||||
Wire.beginTransmission((uint8_t)addr);
|
Wire.beginTransmission((uint8_t)addr);
|
||||||
return (0 == Wire.endTransmission());
|
bool result = (0 == Wire.endTransmission());
|
||||||
}
|
|
||||||
|
|
||||||
bool I2cSetDevice(uint32_t addr)
|
|
||||||
{
|
|
||||||
bool result = I2cDevice(addr);
|
|
||||||
if (result) {
|
if (result) {
|
||||||
I2cSetActive(addr, 1);
|
I2cSetActive(addr, 1);
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ keywords if then else endif, or, and are better readable for beginners (others m
|
|||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
#define XDRV_10 10
|
#define XDRV_10 10
|
||||||
|
#define XI2C_37 37 // See I2CDEVICES.md
|
||||||
|
|
||||||
#define SCRIPT_DEBUG 0
|
#define SCRIPT_DEBUG 0
|
||||||
|
|
||||||
@ -4729,8 +4730,8 @@ bool Xdrv10(uint8_t function)
|
|||||||
|
|
||||||
#ifdef USE_24C256
|
#ifdef USE_24C256
|
||||||
#ifndef USE_SCRIPT_FATFS
|
#ifndef USE_SCRIPT_FATFS
|
||||||
if (i2c_flg) {
|
if (I2cEnabled(XI2C_37)) {
|
||||||
if (I2cDevice(EEPROM_ADDRESS)) {
|
if (I2cSetDevice(EEPROM_ADDRESS)) {
|
||||||
// found 32kb eeprom
|
// found 32kb eeprom
|
||||||
char *script;
|
char *script;
|
||||||
script=(char*)calloc(EEP_SCRIPT_SIZE+4,1);
|
script=(char*)calloc(EEP_SCRIPT_SIZE+4,1);
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#ifdef USE_DISPLAY_ILI9488
|
#ifdef USE_DISPLAY_ILI9488
|
||||||
|
|
||||||
#define XDSP_08 8
|
#define XDSP_08 8
|
||||||
|
#define XI2C_38 38 // See I2CDEVICES.md
|
||||||
|
|
||||||
#define COLORED 1
|
#define COLORED 1
|
||||||
#define UNCOLORED 0
|
#define UNCOLORED 0
|
||||||
@ -112,7 +113,7 @@ void ILI9488_InitDriver()
|
|||||||
color_type = COLOR_COLOR;
|
color_type = COLOR_COLOR;
|
||||||
// start digitizer with fixed adress
|
// start digitizer with fixed adress
|
||||||
|
|
||||||
if (i2c_flg && I2cDevice(FT6236_address)) {
|
if (I2cEnabled(XI2C_38) && I2cSetDevice(FT6236_address)) {
|
||||||
FT6236begin(FT6236_address);
|
FT6236begin(FT6236_address);
|
||||||
FT6236_found=1;
|
FT6236_found=1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#ifdef USE_DISPLAY_RA8876
|
#ifdef USE_DISPLAY_RA8876
|
||||||
|
|
||||||
#define XDSP_10 10
|
#define XDSP_10 10
|
||||||
|
#define XI2C_39 39 // See I2CDEVICES.md
|
||||||
|
|
||||||
#define COLORED 1
|
#define COLORED 1
|
||||||
#define UNCOLORED 0
|
#define UNCOLORED 0
|
||||||
@ -97,7 +98,7 @@ void RA8876_InitDriver()
|
|||||||
#endif
|
#endif
|
||||||
color_type = COLOR_COLOR;
|
color_type = COLOR_COLOR;
|
||||||
|
|
||||||
if (i2c_flg && I2cDevice(FT5316_address)) {
|
if (I2cEnabled(XI2C_39) && I2cSetDevice(FT5316_address)) {
|
||||||
FT6236begin(FT5316_address);
|
FT6236begin(FT5316_address);
|
||||||
FT5316_found=1;
|
FT5316_found=1;
|
||||||
} else {
|
} else {
|
||||||
|
@ -226,10 +226,6 @@ bool Xsns07(uint8_t function)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (function) {
|
switch (function) {
|
||||||
// case FUNC_PREP_BEFORE_TELEPERIOD: // As this is not a real I2C device it may interfere with other sensors
|
|
||||||
case FUNC_INIT: // Move detection to restart only removing interference
|
|
||||||
ShtDetect();
|
|
||||||
break;
|
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
ShtEverySecond();
|
ShtEverySecond();
|
||||||
break;
|
break;
|
||||||
@ -241,6 +237,9 @@ bool Xsns07(uint8_t function)
|
|||||||
ShtShow(0);
|
ShtShow(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
case FUNC_INIT: // Move detection to restart only removing interference
|
||||||
|
ShtDetect();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -198,13 +198,14 @@ bool Ina219CommandSensor(void)
|
|||||||
|
|
||||||
void Ina219Detect(void)
|
void Ina219Detect(void)
|
||||||
{
|
{
|
||||||
for (int i=0; i<sizeof(ina219_type); i++) {
|
for (uint32_t i = 0; i < sizeof(ina219_type); i++) {
|
||||||
if (ina219_type[i])
|
if (ina219_type[i]) { continue; }
|
||||||
continue;
|
|
||||||
uint16_t addr = ina219_addresses[i];
|
uint16_t addr = ina219_addresses[i];
|
||||||
|
if (I2cActive(addr)) { continue; }
|
||||||
if (Ina219SetCalibration(Settings.ina219_mode, addr)) {
|
if (Ina219SetCalibration(Settings.ina219_mode, addr)) {
|
||||||
ina219_type[i] = 1;
|
I2cSetActive(addr);
|
||||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, ina219_types, addr);
|
ina219_type[i] = 1;
|
||||||
|
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, ina219_types, addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -286,9 +287,6 @@ bool Xsns13(uint8_t function)
|
|||||||
result = Ina219CommandSensor();
|
result = Ina219CommandSensor();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FUNC_INIT:
|
|
||||||
Ina219Detect();
|
|
||||||
break;
|
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
Ina219EverySecond();
|
Ina219EverySecond();
|
||||||
break;
|
break;
|
||||||
@ -300,6 +298,9 @@ bool Xsns13(uint8_t function)
|
|||||||
Ina219Show(0);
|
Ina219Show(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
case FUNC_INIT:
|
||||||
|
Ina219Detect();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,9 @@ void Sht3xDetect(void)
|
|||||||
float t;
|
float t;
|
||||||
float h;
|
float h;
|
||||||
for (uint32_t i = 0; i < SHT3X_MAX_SENSORS; i++) {
|
for (uint32_t i = 0; i < SHT3X_MAX_SENSORS; i++) {
|
||||||
|
if (I2cActive(sht3x_addresses[i])) { continue; }
|
||||||
if (Sht3xRead(t, h, sht3x_addresses[i])) {
|
if (Sht3xRead(t, h, sht3x_addresses[i])) {
|
||||||
|
I2cSetActive(sht3x_addresses[i]);
|
||||||
sht3x_sensors[sht3x_count].address = sht3x_addresses[i];
|
sht3x_sensors[sht3x_count].address = sht3x_addresses[i];
|
||||||
GetTextIndexed(sht3x_sensors[sht3x_count].types, sizeof(sht3x_sensors[sht3x_count].types), i, kShtTypes);
|
GetTextIndexed(sht3x_sensors[sht3x_count].types, sizeof(sht3x_sensors[sht3x_count].types), i, kShtTypes);
|
||||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, sht3x_sensors[sht3x_count].types, sht3x_sensors[sht3x_count].address);
|
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, sht3x_sensors[sht3x_count].types, sht3x_sensors[sht3x_count].address);
|
||||||
@ -144,9 +146,6 @@ bool Xsns14(uint8_t function)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_INIT:
|
|
||||||
Sht3xDetect();
|
|
||||||
break;
|
|
||||||
case FUNC_JSON_APPEND:
|
case FUNC_JSON_APPEND:
|
||||||
Sht3xShow(1);
|
Sht3xShow(1);
|
||||||
break;
|
break;
|
||||||
@ -155,6 +154,9 @@ bool Xsns14(uint8_t function)
|
|||||||
Sht3xShow(0);
|
Sht3xShow(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
case FUNC_INIT:
|
||||||
|
Sht3xDetect();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -67,12 +67,12 @@ void Tsl2561Detect(void)
|
|||||||
if (tsl2561_type) { return; }
|
if (tsl2561_type) { return; }
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
|
|
||||||
if (I2cDevice(0x29) || I2cDevice(0x39) || I2cDevice(0x49)) {
|
if (I2cSetDevice(0x29) || I2cSetDevice(0x39) || I2cSetDevice(0x49)) {
|
||||||
Tsl.begin();
|
Tsl.begin();
|
||||||
if (!Tsl.id(id)) return;
|
if (!Tsl.id(id)) return;
|
||||||
if (Tsl.on()) {
|
if (Tsl.on()) {
|
||||||
tsl2561_type = 1;
|
tsl2561_type = 1;
|
||||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, tsl2561_types, Tsl.address(), id);
|
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, tsl2561_types, Tsl.address());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,9 +127,6 @@ bool Xsns16(uint8_t function)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_INIT:
|
|
||||||
Tsl2561Detect();
|
|
||||||
break;
|
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
Tsl2561EverySecond();
|
Tsl2561EverySecond();
|
||||||
break;
|
break;
|
||||||
@ -141,6 +138,9 @@ bool Xsns16(uint8_t function)
|
|||||||
Tsl2561Show(0);
|
Tsl2561Show(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
case FUNC_INIT:
|
||||||
|
Tsl2561Detect();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -116,18 +116,12 @@ void MPU_6050SetAccelOffsets(int x, int y, int z)
|
|||||||
|
|
||||||
void MPU_6050Detect(void)
|
void MPU_6050Detect(void)
|
||||||
{
|
{
|
||||||
if (MPU_6050_found)
|
if (MPU_6050_found) { return; }
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (uint32_t i = 0; i < sizeof(MPU_6050_addresses); i++)
|
for (uint32_t i = 0; i < sizeof(MPU_6050_addresses); i++)
|
||||||
{
|
{
|
||||||
if(!I2cDevice(MPU_6050_addresses[i]))
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
MPU_6050_address = MPU_6050_addresses[i];
|
MPU_6050_address = MPU_6050_addresses[i];
|
||||||
|
if (!I2cSetDevice(MPU_6050_address)) { break; }
|
||||||
mpu6050.setAddr(MPU_6050_addresses[i]);
|
mpu6050.setAddr(MPU_6050_addresses[i]);
|
||||||
|
|
||||||
#ifdef USE_MPU6050_DMP
|
#ifdef USE_MPU6050_DMP
|
||||||
@ -231,9 +225,6 @@ bool Xsns32(uint8_t function)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_PREP_BEFORE_TELEPERIOD:
|
|
||||||
MPU_6050Detect();
|
|
||||||
break;
|
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
if (tele_period == Settings.tele_period -3) {
|
if (tele_period == Settings.tele_period -3) {
|
||||||
MPU_6050PerformReading();
|
MPU_6050PerformReading();
|
||||||
@ -248,6 +239,9 @@ bool Xsns32(uint8_t function)
|
|||||||
MPU_6050PerformReading();
|
MPU_6050PerformReading();
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
case FUNC_INIT:
|
||||||
|
MPU_6050Detect();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -127,11 +127,10 @@ unsigned char cmdb[6];
|
|||||||
Wire.endTransmission();
|
Wire.endTransmission();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SPS30_Detect() {
|
void SPS30_Detect(void)
|
||||||
|
{
|
||||||
|
if (!I2cSetDevice(SPS30_ADDR)) { return; }
|
||||||
|
|
||||||
if (!I2cDevice(SPS30_ADDR)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uint8_t dcode[32];
|
uint8_t dcode[32];
|
||||||
sps30_get_data(SPS_CMD_GET_SERIAL,dcode,sizeof(dcode));
|
sps30_get_data(SPS_CMD_GET_SERIAL,dcode,sizeof(dcode));
|
||||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("sps30 found with serial: %s"),dcode);
|
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("sps30 found with serial: %s"),dcode);
|
||||||
@ -289,25 +288,25 @@ bool Xsns44(byte function)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_INIT:
|
|
||||||
SPS30_Detect();
|
|
||||||
break;
|
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
SPS30_Every_Second();
|
SPS30_Every_Second();
|
||||||
break;
|
break;
|
||||||
case FUNC_JSON_APPEND:
|
case FUNC_JSON_APPEND:
|
||||||
SPS30_Show(1);
|
SPS30_Show(1);
|
||||||
break;
|
break;
|
||||||
case FUNC_COMMAND_SENSOR:
|
|
||||||
if (XSNS_44 == XdrvMailbox.index) {
|
|
||||||
result = SPS30_cmd();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
case FUNC_WEB_SENSOR:
|
case FUNC_WEB_SENSOR:
|
||||||
SPS30_Show(0);
|
SPS30_Show(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
case FUNC_COMMAND_SENSOR:
|
||||||
|
if (XSNS_44 == XdrvMailbox.index) {
|
||||||
|
result = SPS30_cmd();
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case FUNC_INIT:
|
||||||
|
SPS30_Detect();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -32,27 +32,17 @@ uint16_t vl53l0x_distance;
|
|||||||
uint16_t Vl53l0_buffer[5];
|
uint16_t Vl53l0_buffer[5];
|
||||||
uint8_t Vl53l0_index;
|
uint8_t Vl53l0_index;
|
||||||
|
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
void Vl53l0Detect()
|
void Vl53l0Detect(void)
|
||||||
{
|
{
|
||||||
|
if (vl53l0x_ready) { return; }
|
||||||
|
|
||||||
if (!I2cDevice(0x29)) {
|
if (!I2cSetDevice(0x29)) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (vl53l0x_ready) {
|
if (!sensor.init()) { return; }
|
||||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("VL53L1X is ready"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (sensor.init()==true) {
|
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "VL53L0X", sensor.getAddress());
|
||||||
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "VL53L0X", sensor.getAddress());
|
|
||||||
AddLog(LOG_LEVEL_DEBUG);
|
|
||||||
} else {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sensor.setTimeout(500);
|
sensor.setTimeout(500);
|
||||||
|
|
||||||
@ -64,11 +54,8 @@ void Vl53l0Detect()
|
|||||||
vl53l0x_ready = 1;
|
vl53l0x_ready = 1;
|
||||||
|
|
||||||
Vl53l0_index=0;
|
Vl53l0_index=0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define D_UNIT_MILLIMETER "mm"
|
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
const char HTTP_SNS_VL53L0X[] PROGMEM =
|
const char HTTP_SNS_VL53L0X[] PROGMEM =
|
||||||
"{s}VL53L0X " D_DISTANCE "{m}%d" D_UNIT_MILLIMETER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
"{s}VL53L0X " D_DISTANCE "{m}%d" D_UNIT_MILLIMETER "{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
||||||
@ -76,12 +63,13 @@ const char HTTP_SNS_VL53L0X[] PROGMEM =
|
|||||||
|
|
||||||
#define USE_VL_MEDIAN
|
#define USE_VL_MEDIAN
|
||||||
|
|
||||||
void Vl53l0Every_250MSecond() {
|
void Vl53l0Every_250MSecond(void)
|
||||||
|
{
|
||||||
|
if (!vl53l0x_ready) { return; }
|
||||||
|
|
||||||
uint16_t tbuff[5],tmp;
|
uint16_t tbuff[5],tmp;
|
||||||
uint8_t flag;
|
uint8_t flag;
|
||||||
|
|
||||||
if (!vl53l0x_ready) return;
|
|
||||||
|
|
||||||
// every 200 ms
|
// every 200 ms
|
||||||
uint16_t dist = sensor.readRangeContinuousMillimeters();
|
uint16_t dist = sensor.readRangeContinuousMillimeters();
|
||||||
if (dist==0 || dist>2000) {
|
if (dist==0 || dist>2000) {
|
||||||
@ -116,9 +104,7 @@ void Vl53l0Every_250MSecond() {
|
|||||||
|
|
||||||
void Vl53l0Show(boolean json)
|
void Vl53l0Show(boolean json)
|
||||||
{
|
{
|
||||||
if (!vl53l0x_ready) {
|
if (!vl53l0x_ready) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (json) {
|
if (json) {
|
||||||
ResponseAppend_P(PSTR(",\"VL53L0X\":{\"" D_JSON_DISTANCE "\":%d}"), vl53l0x_distance);
|
ResponseAppend_P(PSTR(",\"VL53L0X\":{\"" D_JSON_DISTANCE "\":%d}"), vl53l0x_distance);
|
||||||
@ -127,7 +113,6 @@ void Vl53l0Show(boolean json)
|
|||||||
WSContentSend_PD(HTTP_SNS_VL53L0X, vl53l0x_distance);
|
WSContentSend_PD(HTTP_SNS_VL53L0X, vl53l0x_distance);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
@ -141,9 +126,6 @@ bool Xsns45(byte function)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_INIT:
|
|
||||||
Vl53l0Detect();
|
|
||||||
break;
|
|
||||||
case FUNC_EVERY_250_MSECOND:
|
case FUNC_EVERY_250_MSECOND:
|
||||||
Vl53l0Every_250MSecond();
|
Vl53l0Every_250MSecond();
|
||||||
break;
|
break;
|
||||||
@ -155,6 +137,9 @@ bool Xsns45(byte function)
|
|||||||
Vl53l0Show(0);
|
Vl53l0Show(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
case FUNC_INIT:
|
||||||
|
Vl53l0Detect();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -29,13 +29,12 @@ uint8_t mlx_ready;
|
|||||||
float obj_temp;
|
float obj_temp;
|
||||||
float amb_temp;
|
float amb_temp;
|
||||||
|
|
||||||
void MLX90614_Init() {
|
void MLX90614_Init(void)
|
||||||
|
{
|
||||||
if (!I2cDevice(I2_ADR_IRT)) {
|
if (!I2cSetDevice(I2_ADR_IRT)) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mlx_ready=1;
|
mlx_ready=1;
|
||||||
|
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "MLX90614", I2_ADR_IRT);
|
||||||
|
|
||||||
// not needed on tasmota
|
// not needed on tasmota
|
||||||
//Wire.begin();
|
//Wire.begin();
|
||||||
@ -122,9 +121,6 @@ bool Xsns46(byte function)
|
|||||||
bool result = false;
|
bool result = false;
|
||||||
|
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_INIT:
|
|
||||||
MLX90614_Init();
|
|
||||||
break;
|
|
||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
MLX90614_Every_Second();
|
MLX90614_Every_Second();
|
||||||
break;
|
break;
|
||||||
@ -136,6 +132,9 @@ bool Xsns46(byte function)
|
|||||||
MLX90614_Show(0);
|
MLX90614_Show(0);
|
||||||
break;
|
break;
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
case FUNC_INIT:
|
||||||
|
MLX90614_Init();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -176,6 +176,19 @@ bool Ina226TestPresence(uint8_t device)
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Ina226ResetActive(void)
|
||||||
|
{
|
||||||
|
Ina226SlaveInfo_t *p = slaveInfo;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < INA226_MAX_ADDRESSES; i++) {
|
||||||
|
p = &slaveInfo[i];
|
||||||
|
// Address
|
||||||
|
uint8_t addr = p->address;
|
||||||
|
if (addr) {
|
||||||
|
I2cResetActive(addr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize INA226 devices
|
* Initialize INA226 devices
|
||||||
@ -183,20 +196,17 @@ bool Ina226TestPresence(uint8_t device)
|
|||||||
|
|
||||||
void Ina226Init()
|
void Ina226Init()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
slavesFound = 0;
|
slavesFound = 0;
|
||||||
|
|
||||||
Ina226SlaveInfo_t *p = slaveInfo;
|
Ina226SlaveInfo_t *p = slaveInfo;
|
||||||
|
|
||||||
|
|
||||||
//AddLog_P2( LOG_LEVEL_NONE, "Ina226Init");
|
//AddLog_P2( LOG_LEVEL_NONE, "Ina226Init");
|
||||||
AddLog_P2( LOG_LEVEL_NONE, "Size of Settings: %d bytes", sizeof(Settings));
|
// AddLog_P2( LOG_LEVEL_NONE, "Size of Settings: %d bytes", sizeof(Settings));
|
||||||
|
|
||||||
if (!i2c_flg)
|
// if (!i2c_flg)
|
||||||
AddLog_P2(LOG_LEVEL_DEBUG, "INA226: Initialization failed: No I2C support");
|
// AddLog_P2(LOG_LEVEL_DEBUG, "INA226: Initialization failed: No I2C support");
|
||||||
|
|
||||||
|
|
||||||
// Clear slave info data
|
// Clear slave info data
|
||||||
@ -209,9 +219,11 @@ void Ina226Init()
|
|||||||
|
|
||||||
// Detect devices
|
// Detect devices
|
||||||
|
|
||||||
for (i = 0; (i < INA226_MAX_ADDRESSES); i++){
|
for (i = 0; i < INA226_MAX_ADDRESSES; i++){
|
||||||
uint8_t addr = pgm_read_byte(probeAddresses + i);
|
uint8_t addr = pgm_read_byte(probeAddresses + i);
|
||||||
|
|
||||||
|
if (I2cActive(addr)) { continue; }
|
||||||
|
|
||||||
// Skip device probing if the full scale current is zero
|
// Skip device probing if the full scale current is zero
|
||||||
|
|
||||||
//AddLog_P2( LOG_LEVEL_NONE, "fs_i[%d]: %d", i, Settings.ina226_i_fs[i]);
|
//AddLog_P2( LOG_LEVEL_NONE, "fs_i[%d]: %d", i, Settings.ina226_i_fs[i]);
|
||||||
@ -246,6 +258,8 @@ void Ina226Init()
|
|||||||
|
|
||||||
// store data in slave info struct.
|
// store data in slave info struct.
|
||||||
|
|
||||||
|
I2cSetActive(addr);
|
||||||
|
|
||||||
p = &slaveInfo[i];
|
p = &slaveInfo[i];
|
||||||
// Address
|
// Address
|
||||||
p->address = addr;
|
p->address = addr;
|
||||||
@ -399,6 +413,7 @@ bool Ina226CommandSensor()
|
|||||||
// Device-less commands
|
// Device-less commands
|
||||||
switch (p1){
|
switch (p1){
|
||||||
case 1: // Rerun init
|
case 1: // Rerun init
|
||||||
|
Ina226ResetActive();
|
||||||
Ina226Init();
|
Ina226Init();
|
||||||
Response_P(PSTR("{\"Sensor54-Command-Result\":{\"SlavesFound\":%d}}"),slavesFound);
|
Response_P(PSTR("{\"Sensor54-Command-Result\":{\"SlavesFound\":%d}}"),slavesFound);
|
||||||
break;
|
break;
|
||||||
@ -542,9 +557,6 @@ bool Xsns54(byte callback_id)
|
|||||||
case FUNC_EVERY_SECOND:
|
case FUNC_EVERY_SECOND:
|
||||||
Ina226EverySecond();
|
Ina226EverySecond();
|
||||||
break;
|
break;
|
||||||
case FUNC_INIT:
|
|
||||||
Ina226Init();
|
|
||||||
break;
|
|
||||||
case FUNC_JSON_APPEND:
|
case FUNC_JSON_APPEND:
|
||||||
Ina226Show(1);
|
Ina226Show(1);
|
||||||
break;
|
break;
|
||||||
@ -558,6 +570,9 @@ bool Xsns54(byte callback_id)
|
|||||||
result = Ina226CommandSensor();
|
result = Ina226CommandSensor();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case FUNC_INIT:
|
||||||
|
Ina226Init();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
// Return boolean result
|
// Return boolean result
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user