/*********************************************************************************
|
* 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;
|
}
|