From 55f465be474c54edbceb3c6013ae629e0e0323d8 Mon Sep 17 00:00:00 2001
From: guowenxue <guowenxue@gmail.com>
Date: Wed, 31 Jul 2019 16:26:46 +0800
Subject: [PATCH] Add tsl2561 code, and test force fill-in light ok

---
 mqttd/etc/conf.c |   99 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 99 insertions(+), 0 deletions(-)

diff --git a/mqttd/etc/conf.c b/mqttd/etc/conf.c
index c78e24d..d9df566 100644
--- a/mqttd/etc/conf.c
+++ b/mqttd/etc/conf.c
@@ -25,6 +25,7 @@
 
     if( !conf_file )
     { 
+        strncpy(ctx->id, "\"rpi3b001\"", sizeof(ctx->id));
 
         /* logger settings */
         strncpy(ctx->logfile, DBG_LOG_FILE, sizeof(ctx->logfile));
@@ -99,6 +100,104 @@
     log_nrml("Logger system initialise ok\n");
 
 
+    /*+------------------------------------------------------+
+     *|      parser hardware module configuration ID         |
+     *+------------------------------------------------------+*/
+
+    /* hardware module enable or not */
+    ctx->hwconf.enable=iniparser_getint(ini, "hardware:enable", 0);
+    log_nrml("Parser hardware modules [%s]\n", ctx->hwconf.enable ? "enable" : "disable");
+
+    /* relay control light  */
+    ctx->hwconf.relay_pin=iniparser_getint(ini, "hardware:relay_pin", 0);
+    if( !ctx->hwconf.relay_pin )
+        log_nrml("Parser relay module disabled\n");
+    else
+        log_nrml("Parser relay connected wPI #pin number [%d]\n", ctx->hwconf.relay_pin); 
+
+    /* buzzer */
+    ctx->hwconf.beep_pin=iniparser_getint(ini, "hardware:beep_pin", 0); 
+    log_nrml("Parser buzzer connected wPI #pin number [%d]\n", ctx->hwconf.beep_pin); 
+
+    /* Beep max. times set beep 10 */ 
+    ctx->hwconf.beep_times = iniparser_getint(ini, "hardware:beep_times", 0); 
+    log_nrml("Parser inbreak buzzer beep times [%d]\n", ctx->hwconf.beep_times);
+
+
+    /* RGB 3-colors LED  */
+    ctx->hwconf.red_pin=iniparser_getint(ini, "hardware:red_pin", 0);
+    ctx->hwconf.green_pin=iniparser_getint(ini, "hardware:green_pin", 0);
+    ctx->hwconf.blue_pin=iniparser_getint(ini, "hardware:blue_pin", 0);
+    if( !ctx->hwconf.red_pin && !ctx->hwconf.green_pin && !ctx->hwconf.blue_pin )
+    {
+        ctx->hwconf.leds = 0;
+        log_nrml("Parser RGB leds module disabled\n");
+    }
+    else
+    {
+        ctx->hwconf.leds = 1;
+        log_nrml("Parser RGB led connected wPI #pin number [%d,%d,%d]\n", 
+            ctx->hwconf.red_pin, ctx->hwconf.green_pin, ctx->hwconf.blue_pin);
+    }
+
+    /* temperature sensor ds18b20  */
+    ctx->hwconf.ds18b20=iniparser_getint(ini, "hardware:ds18b20", 0);
+    log_nrml("Parser temperature sensor DS18B20 modules [%s]\n", ctx->hwconf.ds18b20 ? "enable" : "disable");
+
+    /* temperature and hummidity sensor sht2x  */
+    ctx->hwconf.sht2x=iniparser_getint(ini, "hardware:sht2x", 0);
+    log_nrml("Parser temperature and hummidity sensor sht2x modules [%s]\n", ctx->hwconf.sht2x ? "enable" : "disable");
+
+    /* light intensity sensor TSL2561 */
+    ctx->hwconf.lux=iniparser_getint(ini, "hardware:lux", 0);
+    log_nrml("Parser light intensity sensor TSL2561 modules [%s]\n", ctx->hwconf.ds18b20 ? "enable" : "disable");
+
+    ctx->hwconf.infrared_pin=iniparser_getint(ini, "hardware:infrared_pin", 0);
+    log_nrml("Parser infrared pin connected wPI #pin number [%d]\n", ctx->hwconf.infrared_pin);
+
+    if( ctx->hwconf.infrared_pin )
+    {
+        ctx->hwconf.inbreak_beep = iniparser_getint(ini, "hardware:inbreak_beep", 0); 
+        log_nrml("Parser %s inbreak beep\n", ctx->hwconf.inbreak_beep? "enable" : "disable");
+        if( !ctx->hwconf.beep_pin ) 
+        {
+            log_warn("WARNNING: beep hardware not enable and will disable inbreak beep\n");
+            ctx->hwconf.inbreak_beep = 0;
+        }
+
+        ctx->hwconf.fillin_light = iniparser_getint(ini, "hardware:fillin_light", 0);
+        log_nrml("Parser inbreak fill-in light mode [%d]\n", ctx->hwconf.fillin_light);
+
+        if( !ctx->hwconf.relay_pin )
+        {
+            log_warn("WARNNING: Relay hardware not enable and change fill-in light mode to OFF\n");
+            ctx->hwconf.fillin_light = FILLIN_LIGHT_OFF;
+        }
+
+        if( !ctx->hwconf.lux )
+        {
+            log_warn("WARNNING: LUX sensor hardware not enable and change fill-in light mode to ON\n");
+            ctx->hwconf.fillin_light = FILLIN_LIGHT_ON;
+        }
+
+        ctx->hwconf.light_intval = iniparser_getint(ini, "hardware:light_intval", 20);
+        log_nrml("Parser inbreak fill-in light interval time [%d]\n", ctx->hwconf.light_intval);
+    }
+
+
+    /*+------------------------------------------------------+
+     *|               parser production ID                   |
+     *+------------------------------------------------------+*/
+
+    if( !(str=iniparser_getstring(ini, "common:id", NULL)) )
+    {
+        log_err("ERROR: Parser production ID failure\n");
+        return -2;
+    }
+    /* cJSON parser ID will get ""  */
+    snprintf(ctx->id, sizeof(ctx->id), "\"%s\"", str);
+    log_nrml("Parser production ID [%s]\n", ctx->id);
+
 
     /*+------------------------------------------------------+
      *|              parser broker settings                  |

--
Gitblit v1.9.1