From c395bea78de70eb968c697e55c486d1d249f4b58 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Thu, 27 Nov 2025 21:44:58 +0800
Subject: [PATCH] Update lightd code for incoming detect
---
project/lightd/lightd.c | 58 +++++++++++++++++++++++++++-------------------------------
1 files changed, 27 insertions(+), 31 deletions(-)
diff --git a/project/lightd/lightd.c b/project/lightd/lightd.c
index 4af1957..9d5b03d 100644
--- a/project/lightd/lightd.c
+++ b/project/lightd/lightd.c
@@ -142,42 +142,38 @@
log_info("Auto light control thread start\n");
while( ! g_signal.stop )
{
- /* TSL2561 update lux in every 10 minutes */
- if(check_timeout(&last_time, 600))
+ /* 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);
--
Gitblit v1.9.1