| | |
| | | log_info("Auto light control thread start\n"); |
| | | while( ! g_signal.stop ) |
| | | { |
| | | /* TSL2561 update lux in every 5 minutes */ |
| | | if(check_timeout(&last_time, 300)) |
| | | /* Block detect human incoming */ |
| | | rv = infrared_detect(); |
| | | if( rv == 0 ) |
| | | goto nextloop; |
| | | |
| | | log_warn("Someone incoming detected by %s infrared\n", rv&FLAG_INFRARED_INDOOR?"indoor":"hallway"); |
| | | |
| | | /* TSL2561 sensor is not present, do not turn on the light */ |
| | | if( !hwinfo->tsl2561 ) |
| | | { |
| | | /* The TSL2561 sensor is not present, do not turn on the light */ |
| | | if( !hwinfo->tsl2561 ) |
| | | { |
| | | log_error("TSL2561 is not present, do not turn on the light\n"); |
| | | lux = hwinfo->lux_threshold + 100.0; |
| | | goto nextloop; |
| | | } |
| | | |
| | | /* The TSL2561 sensor failed, do not turn on the light */ |
| | | if( tsl2561_get_lux(&lux) < 0 ) |
| | | { |
| | | log_error("TSL2561 sample failed, do not turn on the light\n"); |
| | | lux = hwinfo->lux_threshold + 100.0; |
| | | goto nextloop; |
| | | } |
| | | |
| | | if( lux > hwinfo->lux_threshold ) |
| | | log_info("Lux[%.3f] > Treshold[%.3f], don't auto light\n", lux, hwinfo->lux_threshold); |
| | | else |
| | | log_info("Lux[%.3f] <= Treshold[%.3f], need auto light\n", lux, hwinfo->lux_threshold); |
| | | } |
| | | |
| | | /* It's bright enough, no lighting is needed */ |
| | | if( lux > hwinfo->lux_threshold ) |
| | | { |
| | | log_error("TSL2561 is not present, do not turn on the light\n"); |
| | | goto nextloop; |
| | | } |
| | | |
| | | /* It's not bright enough, lighting is necessary */ |
| | | rv = infrared_detect(); |
| | | if( rv != 0 ) |
| | | /* TSL2561 update lux in every 10 minutes */ |
| | | if(check_timeout(&last_time, 600)) |
| | | { |
| | | log_warn("Someone incoming detected by %s infrared\n", rv&FLAG_INFRARED_INDOOR?"indoor":"hallway"); |
| | | if( tsl2561_get_lux(&lux) < 0 ) |
| | | { |
| | | log_error("TSL2561 sample failed, do not turn on the light\n"); |
| | | goto nextloop; |
| | | } |
| | | } |
| | | |
| | | /* Check need auto light or not */ |
| | | if( lux > hwinfo->lux_threshold ) |
| | | { |
| | | log_info("Lux[%.3f] > Treshold[%.3f], don't auto light\n", lux, hwinfo->lux_threshold); |
| | | } |
| | | else |
| | | { |
| | | log_info("Lux[%.3f] <= Treshold[%.3f], need auto light\n", lux, hwinfo->lux_threshold); |
| | | |
| | | turn_light("indoor", ON); |
| | | turn_light("hallway", ON); |