📄 test_led.c
字号:
#include <stdio.h>
#include <sys/time.h>
#include <time.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#define LED_IOCTL_BASE 0xbb
#define LED_LIGHT _IOR(LED_IOCTL_BASE, 1, unsigned long)
#define LED_UNLIGHT _IOR(LED_IOCTL_BASE, 2, unsigned long)
#define LED_WINK _IOR(LED_IOCTL_BASE, 3, unsigned long)
int main(int argc,char *argv[])
{
int fd;
int cmd;
int seconds=0;
if(argc<2)
{
printf("please input a parameter\n");
return 0;
}
seconds=atoi(argv[1]);
fd=open("/dev/test_leddrv",O_RDWR);
if (fd < 0)
{
printf("Can't open device file /dev/test_leddrv!\n");
return 0;
}
printf("please input your cmd:\n");
printf("1:lighting\t2:unlinghting\t3:winking\n");
scanf("%d",&cmd);
switch(cmd)
{
case 1:
{
while(1)
{
ioctl(fd, LED_LIGHT);
}
}
break;
case 2:
{
while(1)
{
ioctl(fd, LED_UNLIGHT);
}
}
case 3:
{
while(seconds)
{
ioctl(fd, LED_WINK);
sleep(1);
}
}
break;
default:
{
printf("your input error!\n");
}
break;
}
close(fd);
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -