Skip to content
Snippets Groups Projects
Commit fb39c746 authored by 최준영's avatar 최준영
Browse files

Add new file

parent 8adf3a66
No related branches found
No related tags found
No related merge requests found
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/sysmacros.h>
#define MOTION_MAJOR_NUMBER 500
#define MOTION_MINOR_NUMBER 100
#define MOTION_DEV_PATH_NAME "/dev/motion_ioctl"
#define IOCTL_MAGIC_NUMBER 'm'
#define IOCTL_CMD_MOTION_ON _IO(IOCTL_MAGIC_NUMBER, 0)
#define IOCTL_CMD_MOTION_OFF _IO(IOCTL_MAGIC_NUMBER, 1)
int main(void) {
dev_t motion_dev;
int fd;
motion_dev = makedev(MOTION_MAJOR_NUMBER, MOTION_MINOR_NUMBER);
mknod(MOTION_DEV_PATH_NAME, S_IFCHR | 0666, motion_dev);
fd = open(MOTION_DEV_PATH_NAME, O_RDWR);
if (fd < 0) {
printf("fail to open motion\n");
return -1;
}
int i = 0;
while (i < 100) {
if (ioctl(fd, IOCTL_CMD_MOTION_ON, 0) == 1) {
printf("HIGH\n");
sleep(1);
i++;
}
else
printf("LOW\n");
sleep(1);
i++;
}
close(fd);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment