/*
* =====================================================================================
*
* Filename: led.c
*
* Description:
*
* Version: 1.0
* Created: 2012年01月16日 17时56分13秒
* Revision: none
* Compiler: gcc
*
* Author: YOUR NAME (),
* Company:
*
* =====================================================================================
*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#define LED_GPIO "/dev/gpio_led_control"
int main(int argc, char *args[])
{
int fd;
char cmd[64];
if (argc < 3) {
printf("Usge:\n");
printf("\t./led led_name on/off\n");
printf("\n");
printf("\t./led red on\n");
printf("\t./led blue on\n");
printf("\t./led green on\n");
printf("\t./led red off\n");
printf("\t./led blue off\n");
printf("\t./led green off\n");
return -1;
}
fd = open(LED_GPIO, O_RDWR);
if (fd < 0) {
printf("Open %s failed\n", LED_GPIO);
return -1;
}
memset(cmd, 0, strlen(cmd));
strcpy(cmd, args[1]);
strcat(cmd, "-");
strcat(cmd, args[2]);
write(fd, cmd, strlen(cmd));
close(fd);
}
GPIO control app
最新推荐文章于 2022-10-23 18:38:11 发布