Refactor I2C driver detection phase 42

This commit is contained in:
Theo Arends 2019-11-12 22:57:48 +01:00
parent fa03f57ca8
commit 3aea6b0626
3 changed files with 40 additions and 45 deletions

View File

@ -40,6 +40,8 @@
* !! The I2C-soil-moisture-sensor is the preferred one !! * !! The I2C-soil-moisture-sensor is the preferred one !!
* *
* I2C Address: 0x20 - standard address, is changeable * I2C Address: 0x20 - standard address, is changeable
* - Uses I2C clock stretching
* - Scans all I2C addresses
\*********************************************************************************************/ \*********************************************************************************************/
#define XSNS_48 48 #define XSNS_48 48

View File

@ -74,7 +74,6 @@ bool Hih6Read(void)
void Hih6Detect(void) void Hih6Detect(void)
{ {
if (Hih6.type) { return; }
if (I2cActive(HIH6_ADDR)) { return; } if (I2cActive(HIH6_ADDR)) { return; }
if (uptime < 2) { delay(20); } // Skip entering power on comand mode if (uptime < 2) { delay(20); } // Skip entering power on comand mode
@ -86,17 +85,10 @@ void Hih6Detect(void)
void Hih6EverySecond(void) void Hih6EverySecond(void)
{ {
if ((100 - XSNS_55) == (uptime %100)) { if (uptime &1) {
// 1mS
Hih6Detect();
}
else if (uptime &1) {
// HIH6130: 30mS // HIH6130: 30mS
if (Hih6.type) { if (!Hih6Read()) {
if (!Hih6Read()) { AddLogMissed(Hih6.types, Hih6.valid);
AddLogMissed(Hih6.types, Hih6.valid);
// if (!Hih6.valid) { Hih6.type = 0; }
}
} }
} }
} }
@ -141,21 +133,23 @@ bool Xsns55(uint8_t function)
bool result = false; bool result = false;
switch (function) { if (FUNC_INIT == function) {
case FUNC_EVERY_SECOND: Hih6Detect();
Hih6EverySecond(); }
break; else if (Hih6.type) {
case FUNC_JSON_APPEND: switch (function) {
Hih6Show(1); case FUNC_EVERY_SECOND:
break; Hih6EverySecond();
#ifdef USE_WEBSERVER break;
case FUNC_WEB_SENSOR: case FUNC_JSON_APPEND:
Hih6Show(0); Hih6Show(1);
break; break;
#endif // USE_WEBSERVER #ifdef USE_WEBSERVER
case FUNC_INIT: case FUNC_WEB_SENSOR:
Hih6Detect(); Hih6Show(0);
break; break;
#endif // USE_WEBSERVER
}
} }
return result; return result;
} }

View File

@ -41,9 +41,8 @@ float tsl2591_lux = 0;
void Tsl2591Init(void) void Tsl2591Init(void)
{ {
if (tsl2591_type) { return; } // if (I2cSetDevice(0x29) || I2cSetDevice(0x39) || I2cSetDevice(0x49)) {
if (I2cSetDevice(0x29)) {
if (I2cSetDevice(0x29) || I2cSetDevice(0x39) || I2cSetDevice(0x49)) {
if (tsl.begin()) { if (tsl.begin()) {
tsl.setGain(TSL2591_GAIN_MED); tsl.setGain(TSL2591_GAIN_MED);
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS); tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
@ -65,9 +64,7 @@ bool Tsl2591Read(void)
void Tsl2591EverySecond(void) void Tsl2591EverySecond(void)
{ {
if (tsl2591_type) { Tsl2591Read();
Tsl2591Read();
}
} }
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
@ -103,21 +100,23 @@ bool Xsns57(uint8_t function)
bool result = false; bool result = false;
switch (function) { if (FUNC_INIT == function) {
case FUNC_EVERY_SECOND: Tsl2591Init();
Tsl2591EverySecond(); }
break; else if (tsl2591_type) {
case FUNC_JSON_APPEND: switch (function) {
Tsl2591Show(1); case FUNC_EVERY_SECOND:
break; Tsl2591EverySecond();
break;
case FUNC_JSON_APPEND:
Tsl2591Show(1);
break;
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR: case FUNC_WEB_SENSOR:
Tsl2591Show(0); Tsl2591Show(0);
break; break;
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
case FUNC_INIT: }
Tsl2591Init();
break;
} }
return result; return result;
} }