guowenxue
2019-07-31 4deb51ffc4dd4588183aed82bd7877909ba2130e
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,10 +34,16 @@
    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 && hwconf->ifrd_handler )
        init_infrared(hwconf->infrared_pin, INT_EDGE_RISING, hwconf->ifrd_handler);
    if( hwconf->sht2x && sht2x_init() < 0 )
    {
@@ -86,6 +95,20 @@
    pinMode(relay_pin, OUTPUT);
}
void init_beep(int pin)
{
    beep_pin = pin;
    //pinMode(relay_pin, OUTPUT);
}
void init_infrared(int pin, int irq_type, void (*handler)(void))
{
    pinMode(pin, INPUT);
    delay(100);
    wiringPiISR(pin, irq_type, handler);
}
void turn_relay(int cmd)
{