View Single Post
Old 11-28-2012, 02:01 PM   #187
twobob
( ͡° ͜ʖ ͡°){ʇlnɐɟ ƃǝs}Týr
twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.twobob ought to be getting tired of karma fortunes by now.
 
twobob's Avatar
 
Posts: 6,491
Karma: 5977000
Join Date: Jun 2012
Location: uti gratia usura (Yao ying da ying; Mo ying da yieng)
Device: PW-WIFI|K5-3G+WIFI| K4|K3-3G|DXG|K2| Rooted Nook Touch
okay. I have some input working now. will expand on it.

This more or less works,

with a few issues.

need to send the right Key RELEASE codes I think to stop the infinite Joy Direction repeat.

But essentially working (other than that show-stopping niggle)
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>

#define WIDTH 600
#define HEIGHT 800
#define STRIDE 608

#include "input.h"
#include "rc.h"

#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 < 4; 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 < 4; c++) {
		if (inputfds[c] < 0)
			continue;
		close(inputfds[c]);
	}
}

void update(int refresh) {   // #FIXME. Partial screen update. this is horrible
	if (refresh) {
		system("eips -f ''");
	} else {
		system("eips ''");
	}
}

void joy_poll() {
	event_t ev;

	struct input_event iev;
	int c;

	// Add in some TS initial values

	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

	//

	for (c = 2; c < 4; c++) {
		if (inputfds[c] < 0)
			continue;
		//while (read(inputfds[c], &iev, sizeof(struct input_event))
		//			== sizeof(struct input_event)) {

		while (read(inputfds[c], event_buffer, 16) == 16) {

			//	event_buffer = (unsigned char *)&iev;

			//	&iev = (struct input_event)event_buffer;

			if (event_buffer[0x08] == 0x03) {

				// if (iev.type == EV_KEY || 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;
						ev.type = EV_PRESS;

					} else if (event_buffer[0x0C] == 0x01) {
						ev.type = EV_PRESS;
						finger2 = DOWN;
					} else {
						if (finger2 == DOWN) {
							ev.type = EV_PRESS;
							finger2 = UP;
						} else {
							ev.type = EV_RELEASE;
							finger = UP;
						}

					}
					break;
				default:
					update(0);
					//continue;
					break;

				}

				// End of Switch

				// TODO: This does what now???

				if (event_buffer[0x08] == 0x00) {
					sync = 1;
				}

				//if (sync) { /* We have received a sync */
				if (1) { /* We have received a sync */

					// seemingly pointless code TODO: check relevance

					/* If finger 1 is down, draw for it */
					if (finger == DOWN) {
						if (finger2 == UP) {
						}
					}
					/* END OF: If finger 1 is down, draw for it */

					/* Fingers are up. Did we just push exit / clear? */
					if (finger == UP) { /* Release your finger in the top right to exit */
						if (x > 400 && y < 200) {
							printf("Exiting.\n");
							ev.code = K_JOY6;
							ev_postevent(&ev);
							//	break;
						}
						if (x < 200 && y < 200) { /* Release your finger in the top left
						 to clear the screen */
							update(1);
							x = 300;
							y = 400;

						}

						if (x <= 290 && y >= 210 && y <= 560) {

							// S (start)
							ev.code = K_JOY3;
							ev_postevent(&ev);
							fprintf(stderr, "RELEASE <%i>\n", ev.code);
							sync = 0;
							fprintf(stderr, "ev.code <%i>\n", K_JOY3);

						}

						else if (x >= 310 && y >= 210 && y <= 560) {

							// A (select)
							ev.code = K_JOY2;
							ev_postevent(&ev);
							fprintf(stderr, "RELEASE <%i>\n", ev.code);
							sync = 0;

						}

						else if (x <= 160 && y >= 580) {

							// Z  (left fire)
							ev.code = K_JOY1;
							ev_postevent(&ev);
							fprintf(stderr, "RELEASE <%i>\n", ev.code);
							sync = 0;

						}

						else if (x >= 170 && x <= 300 && y >= 580) {

							// X  (right fire)
							ev.code = K_JOY0;
							ev_postevent(&ev);
							fprintf(stderr, "RELEASE <%i>\n", ev.code);
							sync = 0;

						}

						else if (x >= 400 && x <= 510 && y >= 580 && y <= 650) {

							// Joy Up  
							ev.code = K_JOYUP;
							ev_postevent(&ev);
							fprintf(stderr, "RELEASE <%i>\n", ev.code);
							sync = 0;

						}

						else if (x >= 400 && x <= 510 && y >= 710) {

							// JoyDown  
							ev.code = K_JOYDOWN;
							ev_postevent(&ev);
							fprintf(stderr, "RELEASE <%i>\n", ev.code);
							sync = 0;

						}

						else if (x >= 370 && x <= 440 && y >= 650 && y <= 710) {

							// Joy LEFT  
							ev.code = K_JOYLEFT;
							ev_postevent(&ev);
							fprintf(stderr, "RELEASE <%i>\n", ev.code);
							sync = 0;

						}

						else if (x >= 510 && y >= 650 && y <= 710) {

							// Joy RIGHT  
							ev.code = K_JOYRIGHT;
							ev_postevent(&ev);
							fprintf(stderr, "RELEASE <%i>\n", ev.code);
							sync = 0;

						}

						// End of else if's
					}

					/* END OF: Fingers are up. Did we just push exit / clear? */

				}
				// end of: if (sync)

			}
		}
	}
}

Last edited by twobob; 11-28-2012 at 07:04 PM. Reason: && not &
twobob is offline   Reply With Quote