📄 gpio_intermain.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
//#define DEVICE_GPIOALARM "/dev/misc/gpio_interrupt"
//int read_gpio_alarmin(int iValue)
//{
// int fd;
// if( fd = open("/dev/misc/dvc501_gpio", O_RDWR)<0)
// {
// perror("can not open device");
// exit(1);
// }
// ioctl(fd, 0x00, &iValue);
// printf("gpio1_0 is %u\n", iValue);
// close(fd);
// return 0;
//}
//int write_gpio_alarmout(int iValue1)
//{
// int fd;
// if( fd = open("/dev/misc/gpio_interrupt", O_RDWR)<0)
// {
// perror("can not open device");
// exit(1);
// }
// ioctl(fd, 0x01, &iValue1);
// printf("gpio1_2 set %u\n", iValue1);
// close(fd);
// return 0;
//}
int main()
{
int value;
int fd;
if( (fd = open("/dev/misc/dvc501_gpio", O_RDONLY | O_NONBLOCK))<0)
{
perror("can not open device");
exit(1);
}
ioctl(fd, 0x04, 0);
while(1)
{
printf("0-----out-----1\n1------out-------0\n4---------------readinput\n");
printf("please input cmdvalue:");
scanf("%d",&value);
switch(value)
{
case 0:
printf("\nout 1");
ioctl(fd, 0x00, 0);break;
case 1:
printf("\nout 0");
ioctl(fd, 0x01, 0);break;
case 4:
printf("\nread input");
ioctl(fd, 0x04, 0);break;
default:
printf("error !");break;
}
}
close(fd);
return 0;
// int i;
// int fd;
// int type;
// int times;
// char * buffer;
// size_t count = 4;
// int m;
// int n;
// if( (fd = open(DEVICE_GPIOALARM,O_RDONLY | O_NONBLOCK)) < 0 )
// {
// perror("can not open device");
// exit(1);
// }
// printf("waiting stop................");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -