凌云实验室推出的ARM Linux物联网网关开发板IGKBoard(IoT Gateway Kit Board)项目源码
guowenxue
2022-06-12 b7272b190ad85118a9c0793aaf0705f036bf853b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*********************************************************************************
 *      Copyright:  (C) 2021 LingYun IoT System Studio
 *                  All rights reserved.
 *
 *       Filename:  test_led.c
 *    Description:  This file is imx6ull LED test program
 *                 
 *        Version:  1.0.0(2021年11月17日)
 *         Author:  Guo Wenxue <guowenxue@gmail.com>
 *      ChangeLog:  1, Release initial version on "2021年11月17日 22时59分31秒"
 *                 
 ********************************************************************************/
 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/ioctl.h>
 
#define CLASS_LED    "/sys/class/leds"
 
int turn_led(char *which, unsigned char brightness);
 
int main (int argc, char **argv)
{
    while(1)
    {
        turn_led("sysled", 255);
        sleep(1);
        turn_led("sysled", 0);
        sleep(1);
    }
 
 
    return 0;
 
 
int turn_led(char *which, unsigned char brightness)
{
    char            led_path[64] = {0x0};
    char            buf[5] = {0x0};
    int             fd = -1;
    int             rv = 0;
 
    if( !which )
    {
        printf("%s() Invalid input arguments\n", __func__);
        return -1;
    }
 
    snprintf(led_path, sizeof(led_path), "%s/%s/brightness", CLASS_LED, which);
    if( (fd=open(led_path, O_WRONLY)) < 0 )
    {
        printf("Open led file '%s' failure: %s\n", strerror(errno));
        return -2;
    }
 
 
    snprintf(buf, sizeof(buf), "%d", brightness);
    if( write(fd, buf, strlen(buf)) < 0 )
    {
        printf("Open led file '%s' failure: %s\n", strerror(errno));
        rv = -3;
    }
 
    close(fd);
 
    return rv;
}