From 0fd2ff9f9aca1f30d6b4620f90802223cc221fe0 Mon Sep 17 00:00:00 2001 From: GuoWenxue <“guowenxue@gmail.com”> Date: Fri, 22 Apr 2022 09:17:24 +0800 Subject: [PATCH] update socket.c for listen socket --- mqttd/hal/hal.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 49 insertions(+), 4 deletions(-) diff --git a/mqttd/hal/hal.c b/mqttd/hal/hal.c index 94dd8dc..527d6f9 100644 --- a/mqttd/hal/hal.c +++ b/mqttd/hal/hal.c @@ -16,9 +16,12 @@ /* LED_R LED_G LED_B */ static int led_pin[LED_MAX] = { 0,0,0 }; static int relay_pin = 0; +static int beep_pin = 0; +static int infrared_pin = 0; void init_relay(int pin); void init_led(int redpin, int greenpin, int bluepin); +void init_beep(int pin); int hal_init(hwconf_t *hwconf) { @@ -31,17 +34,29 @@ wiringPiSetup(); if( hwconf->leds ) - init_led(hwconf->redled, hwconf->greenled, hwconf->blueled); + init_led(hwconf->red_pin, hwconf->green_pin, hwconf->blue_pin); - if(hwconf->relay) - init_relay(hwconf->relay); + if( hwconf->relay_pin ) + init_relay(hwconf->relay_pin); + + if( hwconf->beep_pin ) + init_beep(hwconf->beep_pin); + + 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; } @@ -86,6 +101,36 @@ pinMode(relay_pin, OUTPUT); } +void init_beep(int pin) +{ + beep_pin = pin; + + /* TBD */ + //pinMode(relay_pin, OUTPUT); +} + +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); +} + +/* 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