Refactor I2C driver detection phase 8

This commit is contained in:
Theo Arends 2019-11-11 18:49:56 +01:00
parent 9c9d177ad5
commit 7d1794ee5b
2 changed files with 32 additions and 37 deletions

View File

@ -71,8 +71,6 @@ uint16_t read_irtmp(uint8_t flag)
void MLX90614_Every_Second(void) void MLX90614_Every_Second(void)
{ {
if (!mlx_ready) { return; }
uint16_t uval = read_irtmp(1); uint16_t uval = read_irtmp(1);
if (uval & 0x8000) { if (uval & 0x8000) {
obj_temp = -999; obj_temp = -999;
@ -95,8 +93,6 @@ void MLX90614_Every_Second(void)
void MLX90614_Show(uint8_t json) void MLX90614_Show(uint8_t json)
{ {
if (!mlx_ready) { return; }
char obj_tstr[16]; char obj_tstr[16];
dtostrfd(obj_temp, Settings.flag2.temperature_resolution, obj_tstr); dtostrfd(obj_temp, Settings.flag2.temperature_resolution, obj_tstr);
char amb_tstr[16]; char amb_tstr[16];
@ -121,21 +117,23 @@ bool Xsns46(byte function)
bool result = false; bool result = false;
switch (function) { if (FUNC_INIT == function) {
case FUNC_EVERY_SECOND: MLX90614_Init();
MLX90614_Every_Second(); }
break; else if (mlx_ready) {
case FUNC_JSON_APPEND: switch (function) {
MLX90614_Show(1); case FUNC_EVERY_SECOND:
break; MLX90614_Every_Second();
break;
case FUNC_JSON_APPEND:
MLX90614_Show(1);
break;
#ifdef USE_WEBSERVER #ifdef USE_WEBSERVER
case FUNC_WEB_SENSOR: case FUNC_WEB_SENSOR:
MLX90614_Show(0); MLX90614_Show(0);
break; break;
#endif // USE_WEBSERVER #endif // USE_WEBSERVER
case FUNC_INIT: }
MLX90614_Init();
break;
} }
return result; return result;
} }

View File

@ -309,7 +309,6 @@ void PAJ7620ReadGesture(void)
void PAJ7620Detect(void) void PAJ7620Detect(void)
{ {
PAJ7620_next_job = 255; // do not loop
if (I2cActive(PAJ7620_ADDR)) { return; } if (I2cActive(PAJ7620_ADDR)) { return; }
PAJ7620SelectBank(0); PAJ7620SelectBank(0);
@ -351,13 +350,8 @@ void PAJ7620Init(void)
void PAJ7620Loop(void) void PAJ7620Loop(void)
{ {
if (255 == PAJ7620_next_job) { return; }
if (0 == PAJ7620_timeout_counter) { if (0 == PAJ7620_timeout_counter) {
switch (PAJ7620_next_job) { switch (PAJ7620_next_job) {
case 0:
PAJ7620Detect();
break;
case 1: case 1:
PAJ7620Init(); PAJ7620Init();
break; break;
@ -376,8 +370,6 @@ void PAJ7620Loop(void)
void PAJ7620Show(bool json) void PAJ7620Show(bool json)
{ {
if (255 == PAJ7620_next_job) { return; }
if (json) { if (json) {
if (PAJ7620_currentGestureName[0] != '\0' ) { if (PAJ7620_currentGestureName[0] != '\0' ) {
ResponseAppend_P(PSTR(",\"%s\":{\"%s\":%u}"), PAJ7620_name, PAJ7620_currentGestureName, PAJ7620_gesture.same); ResponseAppend_P(PSTR(",\"%s\":{\"%s\":%u}"), PAJ7620_name, PAJ7620_currentGestureName, PAJ7620_gesture.same);
@ -436,18 +428,23 @@ bool Xsns50(uint8_t function)
bool result = false; bool result = false;
switch (function) { if (FUNC_INIT == function) {
case FUNC_COMMAND_SENSOR: PAJ7620Detect();
if (XSNS_50 == XdrvMailbox.index){ }
result = PAJ7620CommandSensor(); else if (PAJ7620_next_job) {
} switch (function) {
break; case FUNC_COMMAND_SENSOR:
case FUNC_EVERY_100_MSECOND: if (XSNS_50 == XdrvMailbox.index){
PAJ7620Loop(); result = PAJ7620CommandSensor();
break; }
case FUNC_JSON_APPEND: break;
PAJ7620Show(1); case FUNC_EVERY_100_MSECOND:
break; PAJ7620Loop();
break;
case FUNC_JSON_APPEND:
PAJ7620Show(1);
break;
}
} }
return result; return result;
} }