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 !!
*
* I2C Address: 0x20 - standard address, is changeable
* - Uses I2C clock stretching
* - Scans all I2C addresses
\*********************************************************************************************/
#define XSNS_48 48

View File

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

View File

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