mirror of https://github.com/arendst/Tasmota.git
Refactor I2C driver detection phase 4
This commit is contained in:
parent
cc235941cb
commit
492260cb7e
|
@ -1508,6 +1508,12 @@ void I2cSetActive(uint32_t addr, uint32_t count = 1)
|
|||
// 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 I2cSetActiveFound(uint32_t addr, const char *types)
|
||||
{
|
||||
I2cSetActive(addr);
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, types, addr);
|
||||
}
|
||||
|
||||
bool I2cActive(uint32_t addr)
|
||||
{
|
||||
addr &= 0x7F; // Max I2C address is 127
|
||||
|
|
|
@ -53,9 +53,8 @@ void PCA9685_Detect(void)
|
|||
I2cWrite8(USE_PCA9685_ADDR, PCA9685_REG_MODE1, 0x20);
|
||||
if (I2cValidRead8(&buffer, USE_PCA9685_ADDR, PCA9685_REG_MODE1)) {
|
||||
if (0x20 == buffer) {
|
||||
I2cSetActive(USE_PCA9685_ADDR);
|
||||
pca9685_detected = 1;
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "PCA9685", USE_PCA9685_ADDR);
|
||||
I2cSetActiveFound(USE_PCA9685_ADDR, "PCA9685");
|
||||
PCA9685_Reset(); // Reset the controller
|
||||
}
|
||||
}
|
||||
|
|
|
@ -91,7 +91,7 @@ void Pcf8574Init()
|
|||
if (pcf8574_address >= PCF8574_ADDR2) {
|
||||
strcpy(Pcf8574.stype, "PCF8574A");
|
||||
}
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, Pcf8574.stype, pcf8574_address);
|
||||
I2cSetActiveFound(pcf8574_address, Pcf8574.stype);
|
||||
}
|
||||
|
||||
pcf8574_address++;
|
||||
|
|
|
@ -69,7 +69,7 @@ void LcdInitDriver(void)
|
|||
}
|
||||
|
||||
if (XDSP_01 == Settings.display_model) {
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "LCD", Settings.display_address[0]);
|
||||
I2cSetActiveFound(Settings.display_address[0], "LCD");
|
||||
|
||||
Settings.display_width = Settings.display_cols[0];
|
||||
Settings.display_height = Settings.display_rows;
|
||||
|
|
|
@ -61,7 +61,7 @@ void SSD1306InitDriver()
|
|||
}
|
||||
|
||||
if (XDSP_02 == Settings.display_model) {
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "OLED", Settings.display_address[0]);
|
||||
I2cSetActiveFound(Settings.display_address[0], "SSD1306");
|
||||
|
||||
if ((Settings.display_width != 64) && (Settings.display_width != 96) && (Settings.display_width != 128)) {
|
||||
Settings.display_width = 128;
|
||||
|
|
|
@ -208,7 +208,7 @@ void MatrixInitDriver(void)
|
|||
mtx_state = 1;
|
||||
for (mtx_matrices = 0; mtx_matrices < 8; mtx_matrices++) {
|
||||
if (Settings.display_address[mtx_matrices]) {
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "8x8Matrix", Settings.display_address[mtx_matrices]);
|
||||
I2cSetActiveFound(Settings.display_address[mtx_matrices], "8x8Matrix");
|
||||
matrix[mtx_matrices] = new Adafruit_8x8matrix();
|
||||
matrix[mtx_matrices]->begin(Settings.display_address[mtx_matrices]);
|
||||
} else {
|
||||
|
|
|
@ -62,7 +62,7 @@ void SH1106InitDriver()
|
|||
}
|
||||
|
||||
if (XDSP_07 == Settings.display_model) {
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "OLED", Settings.display_address[0]);
|
||||
I2cSetActiveFound(Settings.display_address[0], "SH1106");
|
||||
|
||||
if (Settings.display_width != SH1106_LCDWIDTH) {
|
||||
Settings.display_width = SH1106_LCDWIDTH;
|
||||
|
|
|
@ -207,7 +207,7 @@ void Ade7953DrvInit(void)
|
|||
Settings.energy_voltage_calibration = ADE7953_UREF;
|
||||
Settings.energy_current_calibration = ADE7953_IREF;
|
||||
}
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "ADE7953", ADE7953_ADDR);
|
||||
I2cSetActiveFound(ADE7953_ADDR, "ADE7953");
|
||||
Ade7953.init_step = 2;
|
||||
|
||||
Energy.phase_count = 2; // Handle two channels as two phases
|
||||
|
|
|
@ -204,7 +204,6 @@ void HtuDetect(void)
|
|||
|
||||
htu_type = HtuReadDeviceId();
|
||||
if (htu_type) {
|
||||
I2cSetActive(htu_address);
|
||||
uint8_t index = 0;
|
||||
HtuInit();
|
||||
switch (htu_type) {
|
||||
|
@ -227,7 +226,7 @@ void HtuDetect(void)
|
|||
htu_delay_humidity = 23;
|
||||
}
|
||||
GetTextIndexed(htu_types, sizeof(htu_types), index, kHtuTypes);
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, htu_types, htu_address);
|
||||
I2cSetActiveFound(htu_address, htu_types);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -483,9 +483,8 @@ void BmpDetect(void)
|
|||
#endif // USE_BME680
|
||||
}
|
||||
if (success) {
|
||||
I2cSetActive(bmp_sensors[bmp_count].bmp_address);
|
||||
GetTextIndexed(bmp_sensors[bmp_count].bmp_name, sizeof(bmp_sensors[bmp_count].bmp_name), bmp_sensors[bmp_count].bmp_model, kBmpTypes);
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, bmp_sensors[bmp_count].bmp_name, bmp_sensors[bmp_count].bmp_address);
|
||||
I2cSetActiveFound(bmp_sensors[bmp_count].bmp_address, bmp_sensors[bmp_count].bmp_name);
|
||||
bmp_count++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,9 +64,8 @@ void Bh1750Detect(void)
|
|||
Wire.beginTransmission(bh1750_address);
|
||||
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
||||
if (!Wire.endTransmission()) {
|
||||
I2cSetActive(bh1750_address);
|
||||
bh1750_type = 1;
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, bh1750_types, bh1750_address);
|
||||
I2cSetActiveFound(bh1750_address, bh1750_types);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -138,12 +138,11 @@ void Veml6070Detect(void)
|
|||
uint8_t status = Wire.endTransmission();
|
||||
// action on status
|
||||
if (!status) {
|
||||
I2cSetActive(VEML6070_ADDR_L);
|
||||
veml6070_type = 1;
|
||||
Veml6070UvTableInit(); // 1[ms], initalize the UV compare table only once
|
||||
uint8_t veml_model = 0;
|
||||
GetTextIndexed(veml6070_name, sizeof(veml6070_name), veml_model, kVemlTypes);
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "VEML6070", VEML6070_ADDR_L);
|
||||
I2cSetActiveFound(VEML6070_ADDR_L, "VEML6070");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,7 +199,7 @@ void Veml6070ModeCmd(bool mode_cmd)
|
|||
uint8_t status = Wire.endTransmission();
|
||||
// action on status
|
||||
if (!status) {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "VEML6070 mode_cmd", VEML6070_ADDR_L);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "VEML6070 mode_cmd"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -173,10 +173,9 @@ void Ads1115Detect(void)
|
|||
if (I2cValidRead16(&buffer, Ads1115.address, ADS1115_REG_POINTER_CONVERT) &&
|
||||
I2cValidRead16(&buffer, Ads1115.address, ADS1115_REG_POINTER_CONFIG)) {
|
||||
Ads1115StartComparator(i, ADS1115_REG_CONFIG_MODE_CONTIN);
|
||||
I2cSetActive(Ads1115.address);
|
||||
Ads1115.count++;
|
||||
Ads1115.found[i] = 1;
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "ADS1115", Ads1115.address);
|
||||
I2cSetActiveFound(Ads1115.address, "ADS1115");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -203,9 +203,8 @@ void Ina219Detect(void)
|
|||
uint16_t addr = ina219_addresses[i];
|
||||
if (I2cActive(addr)) { continue; }
|
||||
if (Ina219SetCalibration(Settings.ina219_mode, addr)) {
|
||||
I2cSetActive(addr);
|
||||
ina219_type[i] = 1;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, ina219_types, addr);
|
||||
I2cSetActiveFound(addr, ina219_types);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -86,10 +86,9 @@ void Sht3xDetect(void)
|
|||
for (uint32_t i = 0; i < SHT3X_MAX_SENSORS; i++) {
|
||||
if (I2cActive(sht3x_addresses[i])) { continue; }
|
||||
if (Sht3xRead(t, h, sht3x_addresses[i])) {
|
||||
I2cSetActive(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);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, sht3x_sensors[sht3x_count].types, sht3x_sensors[sht3x_count].address);
|
||||
I2cSetActiveFound(sht3x_sensors[sht3x_count].address, sht3x_sensors[sht3x_count].types);
|
||||
sht3x_count++;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ void Tsl2561Detect(void)
|
|||
if (!Tsl.id(id)) return;
|
||||
if (Tsl.on()) {
|
||||
tsl2561_type = 1;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, tsl2561_types, Tsl.address());
|
||||
I2cSetActiveFound(Tsl.address(), tsl2561_types);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,8 +49,7 @@ void MGSPrepare(void)
|
|||
|
||||
gas.begin(MGS_SENSOR_ADDR);
|
||||
if (!gas.isError()) {
|
||||
I2cSetActive(MGS_SENSOR_ADDR);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "MultiGasSensor", MGS_SENSOR_ADDR);
|
||||
I2cSetActiveFound(MGS_SENSOR_ADDR, "MultiGas");
|
||||
mgs_detected = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,22 +30,25 @@
|
|||
#define XSNS_21 21
|
||||
#define XI2C_18 18 // See I2CDEVICES.md
|
||||
|
||||
#define SGP30_ADDRESS 0x58
|
||||
|
||||
#include "Adafruit_SGP30.h"
|
||||
Adafruit_SGP30 sgp;
|
||||
|
||||
uint8_t sgp30_type = 0;
|
||||
uint8_t sgp30_ready = 0;
|
||||
bool sgp30_type = false;
|
||||
bool sgp30_ready = false;
|
||||
float sgp30_abshum;
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void sgp30_Init(void) {
|
||||
void sgp30_Init(void)
|
||||
{
|
||||
if (sgp30_type || I2cActive(SGP30_ADDRESS)) { return; }
|
||||
|
||||
if (sgp.begin()) {
|
||||
sgp30_type = 1;
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("SGP: Serialnumber 0x%04X-0x%04X-0x%04X"), sgp.serialnumber[0], sgp.serialnumber[1], sgp.serialnumber[2]);
|
||||
// AddLog(LOG_LEVEL_DEBUG);
|
||||
snprintf_P(log_data, sizeof(log_data), S_LOG_I2C_FOUND_AT, "SGP30", 0x58);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
sgp30_type = true;
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SGP: Serialnumber 0x%04X-0x%04X-0x%04X"), sgp.serialnumber[0], sgp.serialnumber[1], sgp.serialnumber[2]);
|
||||
I2cSetActiveFound(SGP30_ADDRESS, "SGP30");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,13 +70,11 @@ float sgp30_AbsoluteHumidity(float temperature, float humidity,char tempUnit) {
|
|||
}
|
||||
|
||||
if (tempUnit != 'C') {
|
||||
temperature = (temperature - 32.0) * (5.0 / 9.0); /*conversion to [°C]*/
|
||||
temperature = (temperature - 32.0) * (5.0 / 9.0); /*conversion to [°C]*/
|
||||
}
|
||||
|
||||
temp = POW_FUNC(2.718281828, (17.67 * temperature) / (temperature + 243.5));
|
||||
|
||||
|
||||
|
||||
//return (6.112 * temp * humidity * 2.1674) / (273.15 + temperature); //simplified version
|
||||
return (6.112 * temp * humidity * mw) / ((273.15 + temperature) * r); //long version
|
||||
}
|
||||
|
@ -82,40 +83,39 @@ float sgp30_AbsoluteHumidity(float temperature, float humidity,char tempUnit) {
|
|||
|
||||
void Sgp30Update(void) // Perform every second to ensure proper operation of the baseline compensation algorithm
|
||||
{
|
||||
sgp30_ready = 0;
|
||||
if (!sgp.IAQmeasure() || !sgp30_type) {
|
||||
// retry to init every 100 seconds
|
||||
if (!sgp30_type) {
|
||||
if (21 == (uptime %100)) {
|
||||
sgp30_Init();
|
||||
}
|
||||
return; // Measurement failed
|
||||
}
|
||||
if (global_update && global_humidity>0 && global_temperature!=9999) {
|
||||
// abs hum in mg/m3
|
||||
sgp30_abshum=sgp30_AbsoluteHumidity(global_temperature,global_humidity,TempUnit());
|
||||
sgp.setHumidity(sgp30_abshum*1000);
|
||||
}
|
||||
sgp30_ready = 1;
|
||||
} else {
|
||||
sgp30_ready = false;
|
||||
if (!sgp.IAQmeasure()) {
|
||||
return; // Measurement failed
|
||||
}
|
||||
if (global_update && (global_humidity > 0) && (global_temperature != 9999)) {
|
||||
// abs hum in mg/m3
|
||||
sgp30_abshum=sgp30_AbsoluteHumidity(global_temperature,global_humidity,TempUnit());
|
||||
sgp.setHumidity(sgp30_abshum*1000);
|
||||
}
|
||||
sgp30_ready = true;
|
||||
|
||||
// these should normally be stored permanently and used for fast restart
|
||||
if (!(uptime%SAVE_PERIOD)) {
|
||||
// store settings every N seconds
|
||||
uint16_t TVOC_base;
|
||||
uint16_t eCO2_base;
|
||||
|
||||
if (!sgp.getIAQBaseline(&eCO2_base, &TVOC_base)) return; // Failed to get baseline readings
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("SGP: Baseline values eCO2 0x%04X, TVOC 0x%04X"), eCO2_base, TVOC_base);
|
||||
// AddLog(LOG_LEVEL_DEBUG);
|
||||
// these should normally be stored permanently and used for fast restart
|
||||
if (!(uptime%SAVE_PERIOD)) {
|
||||
// store settings every N seconds
|
||||
uint16_t TVOC_base;
|
||||
uint16_t eCO2_base;
|
||||
|
||||
if (!sgp.getIAQBaseline(&eCO2_base, &TVOC_base)) return; // Failed to get baseline readings
|
||||
// AddLog_P2(LOG_LEVEL_DEBUG, PSTR("SGP: Baseline values eCO2 0x%04X, TVOC 0x%04X"), eCO2_base, TVOC_base);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
const char HTTP_SNS_SGP30[] PROGMEM =
|
||||
"{s}SGP30 " D_ECO2 "{m}%d " D_UNIT_PARTS_PER_MILLION "{e}" // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
||||
"{s}SGP30 " D_TVOC "{m}%d " D_UNIT_PARTS_PER_BILLION "{e}";
|
||||
const char HTTP_SNS_AHUM[] PROGMEM = "{s}SGP30 " "Abs Humidity" "{m}%s g/m3{e}";
|
||||
const char HTTP_SNS_AHUM[] PROGMEM = "{s}SGP30 Abs Humidity{m}%s g/m3{e}";
|
||||
#endif
|
||||
|
||||
#define D_JSON_AHUM "aHumidity"
|
||||
|
@ -147,7 +147,6 @@ void Sgp30Show(bool json)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Interface
|
||||
\*********************************************************************************************/
|
||||
|
@ -159,9 +158,6 @@ bool Xsns21(uint8_t function)
|
|||
bool result = false;
|
||||
|
||||
switch (function) {
|
||||
case FUNC_INIT:
|
||||
sgp30_Init();
|
||||
break;
|
||||
case FUNC_EVERY_SECOND:
|
||||
Sgp30Update();
|
||||
break;
|
||||
|
@ -173,6 +169,9 @@ bool Xsns21(uint8_t function)
|
|||
Sgp30Show(0);
|
||||
break;
|
||||
#endif // USE_WEBSERVER
|
||||
case FUNC_INIT:
|
||||
sgp30_Init();
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -183,7 +183,7 @@
|
|||
#define SI114X_IRQEN_PS2 0x08
|
||||
#define SI114X_IRQEN_PS3 0x10
|
||||
|
||||
uint8_t si1145_type = 0;
|
||||
bool si1145_type = false;
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
|
@ -308,11 +308,11 @@ uint16_t Si1145ReadIR(void)
|
|||
|
||||
void Si1145Update(void)
|
||||
{
|
||||
if (!si1145_type) {
|
||||
if (Si1145Begin()) {
|
||||
si1145_type = 1;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "SI1145", SI114X_ADDR);
|
||||
}
|
||||
if (si1145_type || I2cActive(SI114X_ADDR)) { return; }
|
||||
|
||||
if (Si1145Begin()) {
|
||||
si1145_type = true;
|
||||
I2cSetActiveFound(SI114X_ADDR, "SI1145");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -341,7 +341,10 @@ void Si1145Show(bool json)
|
|||
#endif
|
||||
}
|
||||
} else {
|
||||
si1145_type = 0;
|
||||
if (si1145_type) {
|
||||
I2cResetActive(SI114X_ADDR);
|
||||
}
|
||||
si1145_type = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,13 +53,14 @@ void LM75ADDetect(void)
|
|||
{
|
||||
if (lm75ad_type) { return; }
|
||||
|
||||
uint16_t buffer;
|
||||
for (uint32_t i = 0; i < sizeof(lm75ad_addresses); i++) {
|
||||
lm75ad_address = lm75ad_addresses[i];
|
||||
if (I2cActive(lm75ad_address)) { continue; }
|
||||
uint16_t buffer;
|
||||
if (I2cValidRead16(&buffer, lm75ad_address, LM75_THYST_REGISTER)) {
|
||||
if (buffer == 0x4B00) {
|
||||
lm75ad_type = 1;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "LM75AD", lm75ad_address);
|
||||
I2cSetActiveFound(lm75ad_address, "LM75AD");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
|
||||
uint8_t APDS9960addr;
|
||||
uint8_t APDS9960type = 0;
|
||||
char APDS9960stype[9];
|
||||
char APDS9960stype[] = "APDS9960";
|
||||
char currentGesture[6];
|
||||
uint8_t gesture_mode = 1;
|
||||
|
||||
|
@ -1886,35 +1886,24 @@ void APDS9960_loop(void)
|
|||
}
|
||||
}
|
||||
|
||||
bool APDS9960_detect(void)
|
||||
void APDS9960_detect(void)
|
||||
{
|
||||
if (APDS9960type) {
|
||||
return true;
|
||||
}
|
||||
if (APDS9960type || I2cActive(APDS9960_I2C_ADDR)) { return; }
|
||||
|
||||
bool success = false;
|
||||
APDS9960type = I2cRead8(APDS9960_I2C_ADDR, APDS9960_ID);
|
||||
|
||||
if (APDS9960type == APDS9960_CHIPID_1 || APDS9960type == APDS9960_CHIPID_2) {
|
||||
strcpy_P(APDS9960stype, PSTR("APDS9960"));
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, APDS9960stype, APDS9960_I2C_ADDR);
|
||||
if (APDS9960_init()) {
|
||||
success = true;
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "APDS9960 initialized"));
|
||||
I2cSetActiveFound(APDS9960_I2C_ADDR, APDS9960stype);
|
||||
|
||||
enableProximitySensor();
|
||||
enableGestureSensor();
|
||||
} else {
|
||||
APDS9960type = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (APDS9960type == APDS9930_CHIPID_1 || APDS9960type == APDS9930_CHIPID_2) {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("APDS9930 found at address 0x%x, unsupported chip"), APDS9960_I2C_ADDR);
|
||||
}
|
||||
else{
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("APDS9960 not found at address 0x%x"), APDS9960_I2C_ADDR);
|
||||
}
|
||||
} else {
|
||||
APDS9960type = 0;
|
||||
}
|
||||
currentGesture[0] = '\0';
|
||||
return success;
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -1923,9 +1912,8 @@ bool APDS9960_detect(void)
|
|||
|
||||
void APDS9960_show(bool json)
|
||||
{
|
||||
if (!APDS9960type) {
|
||||
return;
|
||||
}
|
||||
if (!APDS9960type) { return; }
|
||||
|
||||
if (!gesture_mode && !APDS9960_overload) {
|
||||
char red_chr[10];
|
||||
char green_chr[10];
|
||||
|
@ -2033,7 +2021,8 @@ bool Xsns27(uint8_t function)
|
|||
|
||||
if (FUNC_INIT == function) {
|
||||
APDS9960_detect();
|
||||
} else if (APDS9960type) {
|
||||
}
|
||||
else if (APDS9960type) {
|
||||
switch (function) {
|
||||
case FUNC_EVERY_50_MSECOND:
|
||||
APDS9960_loop();
|
||||
|
|
|
@ -201,9 +201,7 @@ void MCP230xx_ApplySettings(void) {
|
|||
|
||||
void MCP230xx_Detect(void)
|
||||
{
|
||||
if (mcp230xx_type) {
|
||||
return;
|
||||
}
|
||||
if (mcp230xx_type || I2cActive(USE_MCP230xx_ADDR)) { return; }
|
||||
|
||||
uint8_t buffer;
|
||||
|
||||
|
@ -211,13 +209,13 @@ void MCP230xx_Detect(void)
|
|||
if (I2cValidRead8(&buffer, USE_MCP230xx_ADDR, MCP230xx_IOCON)) {
|
||||
if (0x00 == buffer) {
|
||||
mcp230xx_type = 1; // We have a MCP23008
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "MCP23008", USE_MCP230xx_ADDR);
|
||||
I2cSetActiveFound(USE_MCP230xx_ADDR, "MCP23008");
|
||||
mcp230xx_pincount = 8;
|
||||
MCP230xx_ApplySettings();
|
||||
} else {
|
||||
if (0x80 == buffer) {
|
||||
mcp230xx_type = 2; // We have a MCP23017
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "MCP23017", USE_MCP230xx_ADDR);
|
||||
I2cSetActiveFound(USE_MCP230xx_ADDR, "MCP23017");
|
||||
mcp230xx_pincount = 16;
|
||||
// Reset bank mode to 0
|
||||
I2cWrite8(USE_MCP230xx_ADDR, MCP230xx_IOCON, 0x00);
|
||||
|
@ -423,7 +421,10 @@ void MCP230xx_Reset(uint8_t pinmode) {
|
|||
Response_P(MCP230XX_SENSOR_RESPONSE,99,pinmode,pulluptxt,intmodetxt,"");
|
||||
}
|
||||
|
||||
bool MCP230xx_Command(void) {
|
||||
bool MCP230xx_Command(void)
|
||||
{
|
||||
if (!mcp230xx_type) { return false; }
|
||||
|
||||
bool serviced = true;
|
||||
bool validpin = false;
|
||||
uint8_t paramcount = 0;
|
||||
|
@ -696,7 +697,10 @@ bool MCP230xx_Command(void) {
|
|||
|
||||
const char HTTP_SNS_MCP230xx_OUTPUT[] PROGMEM = "{s}MCP230XX D%d{m}%s{e}"; // {s} = <tr><th>, {m} = </th><td>, {e} = </td></tr>
|
||||
|
||||
void MCP230xx_UpdateWebData(void) {
|
||||
void MCP230xx_UpdateWebData(void)
|
||||
{
|
||||
if (!mcp230xx_type) { return; }
|
||||
|
||||
uint8_t gpio1 = MCP230xx_readGPIO(0);
|
||||
uint8_t gpio2 = 0;
|
||||
if (2 == mcp230xx_type) {
|
||||
|
@ -782,25 +786,6 @@ bool Xsns29(uint8_t function)
|
|||
bool result = false;
|
||||
|
||||
switch (function) {
|
||||
case FUNC_EVERY_SECOND:
|
||||
MCP230xx_Detect();
|
||||
if (mcp230xx_int_counter_en) {
|
||||
mcp230xx_int_sec_counter++;
|
||||
if (mcp230xx_int_sec_counter >= Settings.mcp230xx_int_timer) { // Interrupt counter interval reached, lets report
|
||||
MCP230xx_Interrupt_Counter_Report();
|
||||
}
|
||||
}
|
||||
if (tele_period == 0) {
|
||||
if (mcp230xx_int_retainer_en) { // We have pins configured for interrupt retain reporting
|
||||
MCP230xx_Interrupt_Retain_Report();
|
||||
}
|
||||
}
|
||||
#ifdef USE_MCP230xx_OUTPUT
|
||||
if (tele_period == 0) {
|
||||
MCP230xx_OutputTelemetry();
|
||||
}
|
||||
#endif // USE_MCP230xx_OUTPUT
|
||||
break;
|
||||
case FUNC_EVERY_50_MSECOND:
|
||||
if ((mcp230xx_int_en) && (mcp230xx_type)) { // Only check for interrupts if its enabled on one of the pins
|
||||
mcp230xx_int_prio_counter++;
|
||||
|
@ -810,6 +795,25 @@ bool Xsns29(uint8_t function)
|
|||
}
|
||||
}
|
||||
break;
|
||||
case FUNC_EVERY_SECOND:
|
||||
MCP230xx_Detect();
|
||||
if (mcp230xx_type) {
|
||||
if (mcp230xx_int_counter_en) {
|
||||
mcp230xx_int_sec_counter++;
|
||||
if (mcp230xx_int_sec_counter >= Settings.mcp230xx_int_timer) { // Interrupt counter interval reached, lets report
|
||||
MCP230xx_Interrupt_Counter_Report();
|
||||
}
|
||||
}
|
||||
if (tele_period == 0) {
|
||||
if (mcp230xx_int_retainer_en) { // We have pins configured for interrupt retain reporting
|
||||
MCP230xx_Interrupt_Retain_Report();
|
||||
}
|
||||
#ifdef USE_MCP230xx_OUTPUT
|
||||
MCP230xx_OutputTelemetry();
|
||||
#endif // USE_MCP230xx_OUTPUT
|
||||
}
|
||||
}
|
||||
break;
|
||||
case FUNC_JSON_APPEND:
|
||||
MCP230xx_Show(1);
|
||||
break;
|
||||
|
|
|
@ -53,7 +53,7 @@ void CCS811Update(void) // Perform every n second
|
|||
sint8_t res = ccs.begin(CCS811_ADDRESS);
|
||||
if (!res) {
|
||||
CCS811_type = 1;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "CCS811", 0x5A);
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "CCS811", 0x5A);
|
||||
} else {
|
||||
//AddLog_P2(LOG_LEVEL_DEBUG, "CCS811 init failed: %d",res);
|
||||
}
|
||||
|
|
|
@ -145,7 +145,7 @@ void MPU_6050Detect(void)
|
|||
|
||||
if (MPU_6050_found)
|
||||
{
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, D_SENSOR_MPU6050, MPU_6050_address);
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, D_SENSOR_MPU6050, MPU_6050_address);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -502,7 +502,7 @@ bool MGC3130_detect(void)
|
|||
success = MGC3130_receiveMessage(); // This should read the firmware info
|
||||
if (success) {
|
||||
strcpy_P(MGC3130stype, PSTR("MGC3130"));
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, MGC3130stype, MGC3130_I2C_ADDR);
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, MGC3130stype, MGC3130_I2C_ADDR);
|
||||
MGC3130_currentGesture[0] = '\0';
|
||||
MGC3130_type = true;
|
||||
} else {
|
||||
|
|
|
@ -95,7 +95,7 @@ void Max4409Detect(void)
|
|||
Wire.write(MAX44009_CONTINUOUS_AUTO_MODE);
|
||||
if (0 == Wire.endTransmission()) {
|
||||
max44009_found = 1;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, max44009_types, max44009_address);
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, max44009_types, max44009_address);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -42,7 +42,7 @@ void Vl53l0Detect(void)
|
|||
|
||||
if (!sensor.init()) { return; }
|
||||
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "VL53L0X", sensor.getAddress());
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "VL53L0X", sensor.getAddress());
|
||||
|
||||
sensor.setTimeout(500);
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ void MLX90614_Init(void)
|
|||
if (!I2cSetDevice(I2_ADR_IRT)) { return; }
|
||||
|
||||
mlx_ready=1;
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "MLX90614", I2_ADR_IRT);
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "MLX90614", I2_ADR_IRT);
|
||||
|
||||
// not needed on tasmota
|
||||
//Wire.begin();
|
||||
|
|
|
@ -233,7 +233,7 @@ bool ChirpScan() {
|
|||
delay(2);
|
||||
chirp_sensor[chirp_found_sensors].version = ChirpReadVersion(address);
|
||||
if(chirp_sensor[chirp_found_sensors].version > 0) {
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, "CHIRP:", address);
|
||||
AddLog_P2(LOG_LEVEL_INFO, S_LOG_I2C_FOUND_AT, "CHIRP", address);
|
||||
if(chirp_found_sensors<CHIRP_MAX_SENSOR_COUNT){
|
||||
chirp_sensor[chirp_found_sensors].address = address; // push next sensor, as long as there is space in the array
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, PSTR("CHIRP: fw %x"), chirp_sensor[chirp_found_sensors].version);
|
||||
|
|
|
@ -257,9 +257,6 @@ void Ina226Init()
|
|||
continue; // No device
|
||||
|
||||
// store data in slave info struct.
|
||||
|
||||
I2cSetActive(addr);
|
||||
|
||||
p = &slaveInfo[i];
|
||||
// Address
|
||||
p->address = addr;
|
||||
|
@ -282,9 +279,9 @@ void Ina226Init()
|
|||
|
||||
Ina226SetCalibration(i);
|
||||
|
||||
//AddLog_P2( LOG_LEVEL_NONE, S_LOG_I2C_FOUND_AT, Ina226Str, addr );
|
||||
slavesFound++;
|
||||
I2cSetActiveFound(addr, Ina226Str);
|
||||
|
||||
slavesFound++;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -80,8 +80,7 @@ void Hih6Detect(void)
|
|||
if (uptime < 2) { delay(20); } // Skip entering power on comand mode
|
||||
Hih6.type = Hih6Read();
|
||||
if (Hih6.type) {
|
||||
I2cSetActive(HIH6_ADDR);
|
||||
AddLog_P2(LOG_LEVEL_DEBUG, S_LOG_I2C_FOUND_AT, Hih6.types, HIH6_ADDR);
|
||||
I2cSetActiveFound(HIH6_ADDR, Hih6.types);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue