38 lines
834 B
C
38 lines
834 B
C
#include <sys/types.h>
|
|
#include <sys/stat.h>
|
|
#include <fcntl.h>
|
|
#include <string.h>
|
|
#include <unistd.h>
|
|
#include <stdio.h>
|
|
|
|
int main(int argc, char const *argv[])
|
|
{
|
|
int fd;
|
|
char status = 0;
|
|
|
|
if (argc != 3) {
|
|
printf("Usage: %s <dev> <on|off>\r\n", argv[0]);
|
|
printf(" eg: %s /dev/led_jzh on\r\n", argv[0]);
|
|
printf(" eg: %s /dev/led_jzh off\r\n", argv[0]);
|
|
return -1;
|
|
}
|
|
fd = open(argv[1], O_RDWR);
|
|
if (fd < 0) {
|
|
printf("Cannot open %s\r\n", argv[1]);
|
|
return -1;
|
|
}
|
|
if (strcmp(argv[2], "on") == 0) {
|
|
status = 1;
|
|
} else if (strcmp(argv[2], "off") == 0) {
|
|
status = 0;
|
|
} else {
|
|
printf("Invalid argument: %s\r\n", argv[2]);
|
|
close(fd);
|
|
return -1;
|
|
}
|
|
write(fd, &status, 1);
|
|
close(fd);
|
|
|
|
return 0;
|
|
}
|