From 732d1963ed83abf4e5f1b06ec451a6943421d716 Mon Sep 17 00:00:00 2001 From: Guo Wenxue <guowenxue@gmail.com> Date: Thu, 22 Sep 2022 00:36:11 +0800 Subject: [PATCH] update ds18b20.c to snprintf --- modules/c/led.c | 84 ++++++++++++++++-------------------------- 1 files changed, 32 insertions(+), 52 deletions(-) diff --git a/modules/c/led.c b/modules/c/led.c index 5ef2c0c..fba63b6 100644 --- a/modules/c/led.c +++ b/modules/c/led.c @@ -1,21 +1,21 @@ /********************************************************************************* - * Copyright: (C) 2018 LingYun IoT System Studio + * Copyright: (C) 2021 LingYun IoT System Studio * All rights reserved. * * Filename: led.c - * Description: This file is used to control RGB 3-colours LED + * Description: This file is used to control RGB 3-colors LED * - * pi@raspberrypi:~ $ gpio readall show BCM and wPi pinmap + * pi@raspberrypi:~ $ gpio readall #show RPi pin map * - * LED BCM wPi - * G ---- GPIO.13 ---- GPIO.23 - * R ---- GPIO.19 ---- GPIO.24 - * B ---- GPIO.26 ---- GPIO.25 - * I ---- GND ---- + * LED #PIN BCM + * I ---- 39 ---- GND + * G ---- 37 ---- GPIO26 + * R ---- 35 ---- GPIO19 + * B ---- 33 ---- GPIO13 * - * Version: 1.0.0(2018/10/14) + * Version: 1.0.0(2012/11/03) * Author: Guo Wenxue <guowenxue@gmail.com> - * ChangeLog: 1, Release initial version on "2018/10/14 12:13:26" + * ChangeLog: 1, Release initial version on "2021/11/03 12:13:26" * ********************************************************************************/ @@ -28,10 +28,28 @@ #include <time.h> #include <errno.h> -#include "led.h" +#include <gpiod.h> #define msleep(x) usleep( 1000*(x) ) #define DELAY 500 + +#define ON 1 +#define OFF 0 + +/* Three LEDs code */ +enum +{ + LED_R = 0, + LED_G, + LED_B, + LED_MAX, +}; + +/* RGB 3-color LED BCM pin number */ +static int led_gpio[LED_MAX]= { 19, 26, 13 }; + +void init_led(void); +int turn_led(int which, int cmd); int main(int argc, char *argv[]) { @@ -40,56 +58,18 @@ while(1) { turn_led(LED_R, ON); - msleep(DELAY); turn_led(LED_R, OFF); - msleep(DELAY); turn_led(LED_G, ON); - msleep(DELAY); turn_led(LED_G, OFF); - msleep(DELAY); turn_led(LED_B, ON); - msleep(DELAY); turn_led(LED_B, OFF); - msleep(DELAY); } return 0; } -#ifdef CONFIG_USE_WIRINGPI -#include <wiringPi.h> - -void init_led(void) -{ - int i; - - wiringPiSetup(); - - for(i=0; i<LED_MAX; i++) - { - pinMode( led_gpio[i], OUTPUT ); - } -} - -int turn_led(int which, int cmd) -{ - if( which<0 || which>=LED_MAX ) - return -1; - - - if( OFF == cmd ) - digitalWrite (led_gpio[which], LOW); - else - digitalWrite (led_gpio[which], HIGH); - - return 0; -} - -#else /* use libgpiod library */ - -#include <gpiod.h> #if 0 /* Use libgpiod lowlevel API */ @@ -126,16 +106,17 @@ { gpiod_line_set_value(line, 1); } + + msleep(DELAY); } #else /* use libgpiod ctxless high level API */ void init_led(void) { - } -void gpiod_ctxless_cb(void *data) +static void gpiod_ctxless_cb(void *data) { sleep(1); } @@ -150,4 +131,3 @@ #endif -#endif -- Gitblit v1.9.1