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,6 +117,10 @@ bool Xsns46(byte function)
bool result = false; bool result = false;
if (FUNC_INIT == function) {
MLX90614_Init();
}
else if (mlx_ready) {
switch (function) { switch (function) {
case FUNC_EVERY_SECOND: case FUNC_EVERY_SECOND:
MLX90614_Every_Second(); MLX90614_Every_Second();
@ -133,9 +133,7 @@ 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;
} }

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,6 +428,10 @@ bool Xsns50(uint8_t function)
bool result = false; bool result = false;
if (FUNC_INIT == function) {
PAJ7620Detect();
}
else if (PAJ7620_next_job) {
switch (function) { switch (function) {
case FUNC_COMMAND_SENSOR: case FUNC_COMMAND_SENSOR:
if (XSNS_50 == XdrvMailbox.index){ if (XSNS_50 == XdrvMailbox.index){
@ -449,6 +445,7 @@ bool Xsns50(uint8_t function)
PAJ7620Show(1); PAJ7620Show(1);
break; break;
} }
}
return result; return result;
} }