#include <stdlib.h>
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#define NODE_EXP "/dev/7seg_led" /* Device name */
#define SEG_7_LED_ON 1
#define SEG_7_LED_WRITE 2
#define SEG_7_LED_CLEAR 3
#define SEG_7_LED_OFF 4
int main()
{
int fd;
char buff[256] = "Name";
int i,rb,m;
int exp_dev= 0; /* exp_dev is file descriptor */
int ret,res= 0; /* return value of system call */
struct input_event ev;
struct input_absinfo ab; //absolute info//
if ((fd = open("/dev/input/touchscreen0", O_RDONLY)) < 0)
{
printf ("Error Opening the Device\n");
return 1;
}
ioctl(fd, EVIOCGNAME(sizeof(buff)), buff);
printf("Touch Input device name: \"%s\"\n", buff);
/* ******************Print message on 7seg starting function ************** */
/* open as blocking mode */
exp_dev = open(NODE_EXP, O_RDWR);
if (exp_dev < 0)
{
fprintf(stderr, "Open error: %s\n", NODE_EXP);
return 1;
}
if (res=ioctl(exp_dev,SEG_7_LED_ON, NULL) < 0 )
{
printf("%d---> Error in switching OFF the LED \r\n",res);
getchar();
close(exp_dev);
return 1;
}
/* ******************Print message on 7seg starting function ************** */
for (i = 0; i < 5; i++)
{
rb=read(fd,&ev,sizeof(struct input_event));
printf ("After read\n");
if ((ev.type == 1) && (ev.code == 330))
{
printf ("Touch Event = %d\n",ev.code);
}
if ((ev.type == 3) && (ev.code == 0))
{
printf ("X Value = %d\n",ev.value);
printf ("X Value... = %d\n",ev.value/24);
m=ev.value/24;
printf ("X Value = %x\n",m);
if (res=ioctl(exp_dev,SEG_7_LED_WRITE, m) < 0 )
{
printf("%d---> Error in writing to the 7-Seg LED \r\n",res);
getchar();
close(exp_dev);
return 1;
}
}
if ((ev.type == 3) && (ev.code == 1))
{
printf ("Y Value = %d\n",ev.value);
}
if ((ev.type == 3) && (ev.code == 24))
{
printf ("Touch Pressure = %d\n",ev.value);
}
}
/* *******************Print message on 7seg closing function *************** */
printf ("Press any key to exit from the program\n");
getchar();
if (res=ioctl(exp_dev,SEG_7_LED_CLEAR, NULL) < 0 )
{
printf("%d---> Error in Clearing the LED \r\n",res);
getchar();
close(exp_dev);
return 1;
}
if (ioctl(exp_dev,SEG_7_LED_OFF, NULL) < 0 )
{
printf("Error in switching OFF the LED \r\n");
getchar();
close(exp_dev);
return 1;
}
close(exp_dev);
/* *******************Print message on 7seg closing function *************** */
return 0;
}
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <linux/input.h>
#define NODE_EXP "/dev/7seg_led" /* Device name */
#define SEG_7_LED_ON 1
#define SEG_7_LED_WRITE 2
#define SEG_7_LED_CLEAR 3
#define SEG_7_LED_OFF 4
int main()
{
int fd;
char buff[256] = "Name";
int i,rb,m;
int exp_dev= 0; /* exp_dev is file descriptor */
int ret,res= 0; /* return value of system call */
struct input_event ev;
struct input_absinfo ab; //absolute info//
if ((fd = open("/dev/input/touchscreen0", O_RDONLY)) < 0)
{
printf ("Error Opening the Device\n");
return 1;
}
ioctl(fd, EVIOCGNAME(sizeof(buff)), buff);
printf("Touch Input device name: \"%s\"\n", buff);
/* ******************Print message on 7seg starting function ************** */
/* open as blocking mode */
exp_dev = open(NODE_EXP, O_RDWR);
if (exp_dev < 0)
{
fprintf(stderr, "Open error: %s\n", NODE_EXP);
return 1;
}
if (res=ioctl(exp_dev,SEG_7_LED_ON, NULL) < 0 )
{
printf("%d---> Error in switching OFF the LED \r\n",res);
getchar();
close(exp_dev);
return 1;
}
/* ******************Print message on 7seg starting function ************** */
for (i = 0; i < 5; i++)
{
rb=read(fd,&ev,sizeof(struct input_event));
printf ("After read\n");
if ((ev.type == 1) && (ev.code == 330))
{
printf ("Touch Event = %d\n",ev.code);
}
if ((ev.type == 3) && (ev.code == 0))
{
printf ("X Value = %d\n",ev.value);
printf ("X Value... = %d\n",ev.value/24);
m=ev.value/24;
printf ("X Value = %x\n",m);
if (res=ioctl(exp_dev,SEG_7_LED_WRITE, m) < 0 )
{
printf("%d---> Error in writing to the 7-Seg LED \r\n",res);
getchar();
close(exp_dev);
return 1;
}
}
if ((ev.type == 3) && (ev.code == 1))
{
printf ("Y Value = %d\n",ev.value);
}
if ((ev.type == 3) && (ev.code == 24))
{
printf ("Touch Pressure = %d\n",ev.value);
}
}
/* *******************Print message on 7seg closing function *************** */
printf ("Press any key to exit from the program\n");
getchar();
if (res=ioctl(exp_dev,SEG_7_LED_CLEAR, NULL) < 0 )
{
printf("%d---> Error in Clearing the LED \r\n",res);
getchar();
close(exp_dev);
return 1;
}
if (ioctl(exp_dev,SEG_7_LED_OFF, NULL) < 0 )
{
printf("Error in switching OFF the LED \r\n");
getchar();
close(exp_dev);
return 1;
}
close(exp_dev);
/* *******************Print message on 7seg closing function *************** */
return 0;
}
No comments:
Post a Comment