From 2e7765f468c46728df16faa903d1f4b8a17f76fd Mon Sep 17 00:00:00 2001 From: Guo Wenxue <guowenxue@gmail.com> Date: Wed, 21 Sep 2022 23:09:27 +0800 Subject: [PATCH] update sqlite_blob.c --- mqttd/hal/hal.c | 36 +++++++++++++++++++++++++++++------- 1 files changed, 29 insertions(+), 7 deletions(-) diff --git a/mqttd/hal/hal.c b/mqttd/hal/hal.c index 4840944..527d6f9 100644 --- a/mqttd/hal/hal.c +++ b/mqttd/hal/hal.c @@ -42,15 +42,21 @@ if( hwconf->beep_pin ) init_beep(hwconf->beep_pin); - if( hwconf->infrared_pin && hwconf->ifrd_handler ) - init_infrared(hwconf->infrared_pin, INT_EDGE_RISING, hwconf->ifrd_handler); + if( hwconf->infrared_pin ) + init_infrared(hwconf->infrared_pin); if( hwconf->sht2x && sht2x_init() < 0 ) { - log_err("Initialise SHT20 failure\n"); + log_err("Initialise SHT20 T&H sensor failure\n"); return -1; } + if( hwconf->lux && tsl2561_init() < 0 ) + { + log_err("Initialise TSL2561 Lux sensor failure\n"); + return -1; + } + return 0; } @@ -98,16 +104,32 @@ void init_beep(int pin) { beep_pin = pin; + + /* TBD */ //pinMode(relay_pin, OUTPUT); } -void init_infrared(int pin, int irq_type, void (*handler)(void)) +void turn_beep(int times) { + /* TBD */ +} + +/* wiringPi IRQ handler use a thread and can not pass argument, so we don't use interrupt */ +void init_infrared(int pin) +{ + infrared_pin = pin; pinMode(pin, INPUT); +} - delay(100); - - wiringPiISR(pin, irq_type, handler); +/* jitter_time: cancel jitter interval time + * Return value: 1(HIGH): Sombody detected 0(LOW): Nobody detected */ +int infrared_detect(int jitter_time) +{ + if( digitalRead(infrared_pin) ) + { + msleep(jitter_time); + } + return digitalRead(infrared_pin); } void turn_relay(int cmd) -- Gitblit v1.9.1