From 47579e3790b1ee5a1ad2ce35ea6028cd9ddf6ea0 Mon Sep 17 00:00:00 2001
From: GuoWenxue <“guowenxue@gmail.com”>
Date: Fri, 29 Apr 2022 09:23:27 +0800
Subject: [PATCH] update client_main.c to use packet_segmented_pack
---
iotd/main.c | 50 +++++++++++++++++++++++++++++++++-----------------
1 files changed, 33 insertions(+), 17 deletions(-)
diff --git a/iotd/main.c b/iotd/main.c
index cbc0d85..53cdf9c 100644
--- a/iotd/main.c
+++ b/iotd/main.c
@@ -176,33 +176,49 @@
iotd_ctx_t *ctx = (iotd_ctx_t *)args;
hal_ctx_t *hal_ctx;
float lux = 0.0;
+ int rv;
hal_ctx = &ctx->hal_ctx;
+ log_dbg("infrared configured [%d], lux configured [%d]\n", hal_ctx->gpio.infrared_enable, hal_ctx->lux_enable);
+
while( ! g_signal.stop )
{
- if( hal_ctx->lux_enable )
+ if( hal_ctx->gpio.infrared_enable )
{
- lux = tsl2561_get_lux();
- log_dbg("TSL2561 get Lux[%.3f].\n", lux);
-
- if( lux > hal_ctx->lux_threshold )
+ if( hal_ctx->lux_enable )
{
- log_nrml("Lux[%.3f] > Treshold[%.3f], don't need light on.\n", lux, hal_ctx->lux_threshold);
- sleep(30);
- continue;
+ lux = tsl2561_get_lux();
+
+ log_dbg("TSL2561 get Lux[%.3f] Treshold[%.3f].\n", lux, hal_ctx->lux_threshold);
+
+ if( lux > hal_ctx->lux_threshold )
+ {
+ log_nrml("Lux[%.3f] > Treshold[%.3f], don't need light on and sleep now.\n", lux, hal_ctx->lux_threshold);
+ if( hal_ctx->gpio.light_intval > 0)
+ sleep( hal_ctx->gpio.light_intval );
+ else
+ sleep(30);
+
+ continue;
+ }
+ }
+
+ rv = infrared_detect();
+ if( rv & FLAG_INFRARED_INDOOR )
+ {
+ log_nrml("Someone incoming detected by indoor infrared\n");
+ thread_start(NULL, light_on_worker, "indoor" );
+ }
+
+ if( rv & FLAG_INFRARED_HALLWAY )
+ {
+ log_nrml("Someone incoming detected by hallway infrared\n");
+ thread_start(NULL, light_on_worker, "hallway" );
}
}
-#if 0
- log_nrml("start infrared monitor detect...\n");
- if( infrared_detect() )
- {
- log_nrml("Someone incoming detected by infrared\n");
- log_nrml("Lux[%.3f] < Treshold[%.3f], auto light on now..\n", lux, hal_ctx->lux_threshold);
- }
-#endif
- sleep(1);
+ msleep(100);
}
}
--
Gitblit v1.9.1