guowenxue
2021-04-21 8913f64d481a3da19d7e03b619605dc67eaf0591
update infrared test.c
1 files modified
20 ■■■■ changed files
modules/c/infrared.c 20 ●●●● patch | view | raw | blame | history
modules/c/infrared.c
@@ -9,7 +9,8 @@
 *
 *             PIN          #PIN        BCM           wPi 
 *           VCC(left) ----  2   ----   5v     ----   5v
 *            I/O(mid) ----  32  ----   12     ----   26
 *         I/O(indoor) ----  16  ----   23     ----   4
 *        I/O(hallway) ----  18  ----   24     ----   5
 *          GND(right) ----  34  ----   0v     ----   0v
 *
 *        Version:  1.0.0(30/01/19)
@@ -20,13 +21,17 @@
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
//#define CONFIG_USE_WIRINGPI
#ifdef CONFIG_USE_WIRINGPI
#include <wiringPi.h>
#define INFRARED_PIN           26
#define INFRARED_PIN           4
//#define INFRARED_PIN           5
int main (int argc, char **argv)
{
@@ -39,7 +44,6 @@
        sleep(1);
    }
    return 0;
}
@@ -47,7 +51,8 @@
#include <gpiod.h>
#define INFRARED_PIN           12
#define INFRARED_PIN           23
//#define INFRARED_PIN           24
int main (int argc, char **argv)
{
@@ -72,9 +77,10 @@
    }
    if( gpiod_line_request_rising_edge_events(line, "infrared") < 0 )
    //if( gpiod_line_request_rising_edge_events(line, "infrared") < 0 )
    if( gpiod_line_request_falling_edge_events(line, "infrared") < 0 )
    {
    printf("gpiod request rising edge event failure\n");
        printf("gpiod request rising edge event failure: %s\n", strerror(errno));
    rv = 3;
    goto cleanup;
    }
@@ -82,12 +88,14 @@
    while(1)
    {
    /* This function will block, must call it to setup */
        printf("Start gpiod_line_event_wait...\n");
        if( gpiod_line_event_wait(line, NULL) < 0 )
    {
        printf("gpiod line wait event failure!\n");
    }
    
    /* This function will block, must read to clear the event  */
        printf("Start gpiod_line_event_read...\n");
        if (gpiod_line_event_read(line, &event) < 0)
    {
        printf("gpiod line wait event failure!\n");