| | |
| | | # 树莓派连接的外设信息,0:禁用或未连接 其他: 使能或相关硬件连接的Pin管脚(BCM) |
| | | [hardware] |
| | | |
| | | # LED或继电器等GPIO输出控制, 格式: {名称:BCM编码:控制:电平} |
| | | gpio_outpin={light_indoor:6:0},{light_livroomL:13:0},{light_livroomR:19:0},{light_hallway:26:0} |
| | | # LED或继电器等GPIO输出控制, 格式: {名称:BCM编码:控制电平} |
| | | gpio_outpin={light_indoor:6:1},{light_livroomL:13:1},{light_livroomR:19:1},{light_hallway:26:1} |
| | | #gpio_outpin={led_red:6:1},{led_green:13:1},{led_blue:19:1} |
| | | |
| | | # 红外探测到人后,继电器控制灯亮的时长 |
| | | light_intval=15 |
| | | |
| | | # 按键或红外感应灯GPIO输入控制, 格式: {名称:BCM编码:控制:电平} |
| | | gpio_inpin={infrared_indoor:4:0},{infrared_hallway:18:0} |
| | | gpio_inpin={infrared_indoor:23:1},{infrared_hallway:24:1} |
| | | |
| | | # 是否使能 TSL2561 光强传感器模块,0:禁用 X:光强阈值 |
| | | lux=1 |
| | | lux_threshould=0.10 |
| | | lux_threshold=0.10 |
| | | |
| | | # 是否使能 DS18b20 温度传感器模块,0:禁用 1:是能 |
| | | # ds18b20=1 |
| | |
| | | int i; |
| | | gpio_info_t *gpioinfo; |
| | | |
| | | |
| | | s_gpio = gpio; |
| | | |
| | | |
| | | if( !gpio ) |
| | | { |
| | |
| | | log_warn("WARNNING: No GPIO pins configured\n"); |
| | | return 0; |
| | | } |
| | | |
| | | |
| | | /* gpiod open chip */ |
| | | s_chip = gpiod_chip_open_by_name(RPI_GPIONAME); |
| | |
| | | } |
| | | |
| | | |
| | | #if 0 |
| | | /* Return value: 1(HIGH): Sombody detected 0(LOW): Nobody detected */ |
| | | int infrared_detect(void) |
| | | { |
| | | int i; |
| | | int rv; |
| | | struct gpiod_line_event event; |
| | | |
| | | /* This function will block, must call it to setup */ |
| | | if( gpiod_line_event_wait(s_infrared_lines, NULL) < 0 ) |
| | | for(i=0; i<s_gpio->incnt; i++) |
| | | { |
| | | //log_err("infrared gpiod line wait event failure!\n"); |
| | | return 0; |
| | | } |
| | | if( strstr(s_gpio->input[i].name, "infrared")) |
| | | { |
| | | log_dbg("Start detect '%s' on pin[#%d]\n", s_gpio->input[i].name, s_gpio->input[i].pin); |
| | | |
| | | /* This function will block, must read to clear the event */ |
| | | if (gpiod_line_event_read(s_infrared_lines, &event) < 0) |
| | | { |
| | | log_err("gpiod line event read failure!\n"); |
| | | return 0; |
| | | } |
| | | /* This function will block, must call it to setup */ |
| | | rv = gpiod_line_event_wait(s_gpio->input[i].line, NULL) ; |
| | | if( rv< 0 ) |
| | | { |
| | | log_err("infrared gpiod line wait event failure!\n"); |
| | | return 0; |
| | | } |
| | | log_err("infrared gpiod line wait event rv=%d!\n", rv); |
| | | |
| | | if (event.event_type == GPIOD_LINE_EVENT_RISING_EDGE) |
| | | return 1; |
| | | else |
| | | return 0; |
| | | /* This function will block, must read to clear the event */ |
| | | if (gpiod_line_event_read(s_gpio->input[i].line, &event) < 0) |
| | | { |
| | | log_err("gpiod line event read failure!\n"); |
| | | return 0; |
| | | } |
| | | |
| | | if (event.event_type == GPIOD_LINE_EVENT_RISING_EDGE) |
| | | return 1; |
| | | else |
| | | return 0; |
| | | } |
| | | } |
| | | } |
| | | |
| | | #endif |
| | |
| | | extern int gpio_init(gpio_t *gpio); |
| | | extern void gpio_term(void); |
| | | |
| | | |
| | | /* turn which light on/off */ |
| | | void gpio_out(char *name, char *cmd); |
| | | extern void gpio_out(char *name, char *cmd); |
| | | |
| | | /* Return value: 0(LOW): Nobody detected, !0: Which infrared detect incoming */ |
| | | extern int infrared_detect(void); |
| | |
| | | } |
| | | } |
| | | |
| | | #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 |
| | | |
| | | sleep(1); |
| | | } |
| | | } |