From 4ff5fe054d3e9db5edf1eb8e9114729b5f7918a3 Mon Sep 17 00:00:00 2001 From: guowenxue <guowenxue@gmail.com> Date: Thu, 22 Apr 2021 03:18:37 +0800 Subject: [PATCH] update iotd for infrared detect --- iotd/main.c | 49 +++++++++++++++++++++++++++++-------------------- 1 files changed, 29 insertions(+), 20 deletions(-) diff --git a/iotd/main.c b/iotd/main.c index 80e90e7..ed29b06 100644 --- a/iotd/main.c +++ b/iotd/main.c @@ -31,7 +31,7 @@ #define PROG_VERSION "v1.0.0" #define DAEMON_PIDFILE "/tmp/.iotd.pid" -void control_thread_loop(void *ctx); +void control_thread_loop(void *args); static void program_usage(char *progname) { @@ -117,10 +117,8 @@ } log_nrml("Initialise hardware okay.\n"); - return 0; /* todo: debug and removed */ install_default_signal(); - if( check_set_program_running(daemon, DAEMON_PIDFILE) < 0 ) goto OUT; @@ -142,7 +140,6 @@ log_nrml("Start MQTT subsciber worker thread ok\n"); } } - /*+--------------------------------------------+ *| Start MQTT publisher thread if enable | @@ -176,35 +173,47 @@ void control_thread_loop(void *args) { - iotd_ctx_t *ctx = (iotd_ctx_t *)ctx; + 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_nrml("Start control thread working...\n"); + 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(); - 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.\n", lux, hal_ctx->lux_threshold); + sleep(30); + continue; + } + } + + rv = infrared_detect(250); + + if( rv & FLAG_INFRARED_INDOOR ) + { + log_nrml("Someone incoming detected by indoor infrared\n"); + } + + if( rv & FLAG_INFRARED_HALLWAY ) + { + log_nrml("Someone incoming detected by hallway infrared\n"); } } -#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 + msleep(500); } } -- Gitblit v1.9.1