View Single Post
Old 11-27-2012, 08:47 PM   #173
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,586
Karma: 6299993
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
Notes on Input codes
Spoiler:


okay so. Inputs: input.h

Quote:
#define K_JOY0 0x1b0
#define K_JOY1 0x1b1
#define K_JOY2 0x1b2
#define K_JOY3 0x1b3
#define K_JOY4 0x1b4
#define K_JOY5 0x1b5
#define K_JOY6 0x1b6
referenced by kindleinput.c function joy_poll()

Spoiler:
Code:
void joy_poll()
{
	event_t ev;
	struct input_event iev;
	int c;
	

	for(c = 0; c < 3; c++) {
		if(inputfds[c] < 0) continue;
		while (read(inputfds[c],&iev,sizeof(struct input_event)) == sizeof(struct input_event)) {
			if(iev.type == EV_KEY) {
				if(iev.value == 1) {
					ev.type = EV_PRESS;
				} else if(iev.value == 0) {
					ev.type = EV_RELEASE;
				} else {
//maybe a debug output here?
sprintf(stderr, "couldn't manage input type");

					continue;
				}
				switch(iev.code) {
				case 103:
				case 122: // FW_UP (K3, KDX)
					ev.code = K_JOYUP;
					break;
				case 108:
				case 123: // FW_DOWN (K3, KDX)
					ev.code = K_JOYDOWN;
					break;
				case 105: // FW_LEFT (both)
					ev.code = K_JOYLEFT;
					break;
				case 106: // FW_RIGHT (both)
					ev.code = K_JOYRIGHT;
					break;
				case 102:
				case 98:  // HOME
					ev.code = K_JOY6;
					break;
				case 44:  // Z
					ev.code = K_JOY1;
					break;
				case 45:  // X
					ev.code = K_JOY0;
					break;
				case 30:  // A
					ev.code = K_JOY2;
					break;
				case 31:  // S
					ev.code = K_JOY3;
					break;
				case 16:  // Q
					ev.code = K_JOY4;
					break;
				case 17:  // W
					ev.code = K_JOY5;
					break;
				default:
					continue;
				}
				ev_postevent(&ev);
//			fprintf(stderr, "ev.code = <%i>\n", ev.code);
			}
		}
	}


also we would like to know exactly which /dev/input/event[0-3] it is polling

(2 or 3 look likely surrogate candidates on the 5 - the button and the touchscreen respectively)

Let's just assume we don't know and push to all 4.

The relevant definitions in the Kindle Touch Kernel Sources would seem to be
( File: ./gplrelease/include/linux/input.h )

Spoiler:
Code:
#define KEY_LOGOFF              0x1b1   /* AL Logoff */

#define KEY_DOLLAR              0x1b2
#define KEY_EURO                0x1b3

#define KEY_FRAMEBACK           0x1b4   /* Consumer - transport controls */
#define KEY_FRAMEFORWARD        0x1b5
#define KEY_CONTEXT_MENU        0x1b6   /* GenDesc - system context menu */


so using:

Spoiler:
Code:
#include <stdio.h>
#include <fcntl.h>
#include <linux/input.h>
#include <sstream>
#include <unistd.h> 

#define EV_PRESSED 1
#define EV_RELEASED 0
#define EV_REPEAT 2

#define KEY_SPELLCHECK          0x1b0   /* K_JOY0 = X */
#define KEY_LOGOFF              0x1b1   /* K_JOY1 = Z */

#define KEY_DOLLAR              0x1b2   /* K_JOY2 = A  */
#define KEY_EURO                0x1b3   /* K_JOY3 = S */

#define KEY_FRAMEBACK           0x1b4     /* K_JOY4  = Q */
#define KEY_FRAMEFORWARD        0x1b5   /* K_JOY5  = W */
#define KEY_CONTEXT_MENU        0x1b6     /* K_JOY6  = HOME  */

/*
* Purpose: Stuffs the Linux keyboard buffer with a key and
* reads it back out of the buffer.
*	 All key definitions can be found in input.h file:
*	 /usr/src/linux-headers-3.2.0-23/include/linux
*
*/
main()
{
/************************************************
* IMPORTANT
* you need to execute this code as the su or
* sudo user in order to open the device properly.
***********************************************/
printf("Starting the keyboard buffer writer/reader \n");

int fd = 0;
// char *device = "/dev/input/event2";
// Whitney button
 
char *device = "/dev/input/event3"; 

// PREVIOUS PERSONS NOTES INCLUDED HERE
// This is the TS keyboard device as identified using both: $cat /proc/bus/input/devices
// and looking in the var/log/Xorg.0.log searching for "keyboard"

// Write a key to the keyboard buffer
if( (fd = open(device, O_RDWR)) > 0 )
{
struct input_event event;
printf("The keyboard code is: %d \n", KEY_EURO); // Note: these are not the same as ASCII codes.

// Press a key (stuff the keyboard with a keypress)
event.type = EV_KEY;
event.value = EV_PRESSED;
event.code = KEY_EURO;
write(fd, &event, sizeof(struct input_event));

// Release the key
event.value = EV_RELEASED;
event.code = KEY_EURO;
write(fd, &event, sizeof(struct input_event));
close(fd);
}

// Read the key back from the keyboard buffer
int fd1 = 0;
if( (fd1 = open(device, O_RDONLY)) > 0 ) // It's important to open a new file descriptor here or the program will block.
{
struct input_event event;
unsigned int scan_code = 0;

if(event.type != EV_KEY)
{
return 0; // Keyboard events are always of type EV_KEY
}

if(event.value == EV_RELEASED)
{
scan_code = event.code;
printf("read back scan_code is: %d \n", scan_code);
}
close(fd1);
}
}


One might imagine that might do something...

but seemingly not.

Am I missing something?

Stuff keycode in event thingy? no??

: )

Tips gratefully accepted.

Last edited by twobob; 11-28-2012 at 09:52 AM. Reason: File: ./gplrelease/include/linux/input.h
twobob is offline   Reply With Quote