This is where I got to (with broken code)
Spoiler:
Something like.... Which is broken.. I will figure out what I did tomorrow.
stupid cut and paste loop error. will pick this up tomorrow.
noted here for the morning.
Spoiler:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/input.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include "input.h"
#include "rc.h"
#define WIDTH 600
#define HEIGHT 800
#define STRIDE 608
#define TOUCH_SCREEN "/dev/input/event3"
#define UP 0
#define DOWN 1
static int inputfds[] = { -1, -1, -1 };
rcvar_t joy_exports[] = { RCV_END };
void joy_init() {
int c;
char dev[128];
for (c = 0; c < 3; c++) {
sprintf(dev, "/dev/input/event%d", c);
inputfds[c] = open(dev, O_RDONLY | O_NONBLOCK);
if (inputfds[c] < 0) {
fprintf(stderr, "couldn't open <%s>\n", dev);
}
}
}
void joy_close() {
int c;
for (c = 0; c < 3; c++) {
if (inputfds[c] < 0)
continue;
close(inputfds[c]);
}
}
void update(int refresh) {
if (refresh) {
system("eips -f ''");
} else {
system("eips ''");
}
}
void joy_poll() {
int touch_screen_fd = 0;
unsigned char *frame_buffer = NULL;
unsigned char event_buffer[16];
/* First finger variables */
int finger = UP;
int x = 300;
int y = 400;
/* Second finger variables */
int finger2 = UP;
int x2 = 0;
int y2 = 0;
int f2_mode = 0;
int i = 0;
int j = 0;
int sync = 0; //? maybe
event_t ev;
//open it?
touch_screen_fd = open(TOUCH_SCREEN, O_RDONLY);
if (touch_screen_fd == -1) {
fprintf(stderr, "Error: Could not open touch screen.\n");
exit(EXIT_FAILURE);
}
// Do the setup
while (read(touch_screen_fd, event_buffer, 16)) {
if (event_buffer[0x08] == 0x03) {
switch (event_buffer[0x0A]) {
case 0x2F:
/* When f2_mode is nonzero, data is treated as being for
the second finger */
f2_mode = event_buffer[0x0C];
break;
case 0x35:
/* X Coordinate change */
if (!f2_mode) {
x = (WIDTH
* (event_buffer[0x0C] + (event_buffer[0x0D] << 8)))
/ 0x1000;
} else {
x2 = (WIDTH
* (event_buffer[0x0C] + (event_buffer[0x0D] << 8)))
/ 0x1000;
}
break;
case 0x36:
/* Y Coordinate change */
if (!f2_mode) {
y = (HEIGHT
* (event_buffer[0x0C] + (event_buffer[0x0D] << 8)))
/ 0x1000;
} else {
y2 = (HEIGHT
* (event_buffer[0x0C] + (event_buffer[0x0D] << 8)))
/ 0x1000;
}
break;
case 0x39:
/* Finger up / down */
if (event_buffer[0x0C] == 0x00) {
finger = DOWN;
} else if (event_buffer[0x0C] == 0x01) {
finger2 = DOWN;
} else {
if (finger2 == DOWN) {
finger2 = UP;
} else {
finger = UP;
}
}
break;
default:
break;
}
}
if (event_buffer[0x08] == 0x00) {
sync = 1;
}
if (sync) { /* We have recieved a sync */
/* If finger 1 is down, draw for it */
if (finger == DOWN) {
if (finger2 == UP) {
}
}
/* Fingers are up. Did we just push exit / clear? */
if (finger == UP) { /* Release your finger in the top right to exit */
if (x > 500 && y < 100) {
printf("Exiting.\n");
break;
}
if (x < 100 && y < 100) { /* Release your finger in the top left
to clear the screen */
update(1);
x = 300;
y = 400;
}
if (x >= 50 && x <= 250 && y >= 140 && y <= 500) {
// S
ev.code = K_JOY3;
sync = 0;
}
}
}
ev_postevent(&ev);
fprintf(stderr, "ev.code = <%i>\n", ev.code);
}
}
I will check the matching brackets when I am less tired.
But this is close...
I get the relevant output... mainly...
Quote:
ev.code = <435>
ev.code = <435>
ev.code = <435>
ev.code = <435>
Exiting.
ev.code = <161956>
|