test_led.c

来自「本程序为嵌入式linux驱动」· C语言 代码 · 共 41 行

C
41
字号
#include <stdio.h>#include <stdlib.h>#include <sys/ioctl.h>#include <unistd.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/mman.h>#include "gpio_test.h"#define DEVICE_GPIODRV	"/tmp/led"int main(){	int fd;	int val=-1;		if((fd=open(DEVICE_GPIODRV,O_RDONLY | O_NONBLOCK))<0)	{		printf("open device: %s\n",DEVICE_GPIODRV);		perror("can not open device");		exit(1);	}	while(1){		printf("0:set ,1:clear,2: quit        :");		scanf("%d",&val);		if(val==0)			ioctl(fd,IOWRITE,0);		else if(val==1)			ioctl(fd,IOCLEAR,0);		else if(val==2){			close(fd);			return 0;		}else{			printf("val is %d\n",val);			continue;		}				}	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?