|
From: <ph...@us...> - 2007-02-14 09:08:14
|
Revision: 808
http://svn.sourceforge.net/hackndev/?rev=808&view=rev
Author: phiren
Date: 2007-02-14 01:08:12 -0800 (Wed, 14 Feb 2007)
Log Message:
-----------
Touchscreen Keyboard: Initial import
Added Paths:
-----------
tsk/
tsk/.messagease.h.swp
tsk/.tsk.c.swp
tsk/branches/
tsk/tags/
tsk/trunk/
tsk/trunk/messagease.h
tsk/trunk/tsk.c
Added: tsk/.messagease.h.swp
===================================================================
(Binary files differ)
Property changes on: tsk/.messagease.h.swp
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: tsk/.tsk.c.swp
===================================================================
(Binary files differ)
Property changes on: tsk/.tsk.c.swp
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: tsk/trunk/messagease.h
===================================================================
--- tsk/trunk/messagease.h (rev 0)
+++ tsk/trunk/messagease.h 2007-02-14 09:08:12 UTC (rev 808)
@@ -0,0 +1,88 @@
+/*
+ * messagease.h -- Layout of the left-hand MessagEase stamp
+ *
+ * Author: Scott Mansell <ph...@gm...>
+ *
+ * This file is released under the GPL version 2
+ *
+ * The MessagEase layout is Copyright © 2005 EXideas
+ */
+
+#ifndef MESSAGease_LAYOUT
+#define MESSAGease_LAYOUT
+
+#define BOX_Y 4
+#define BOX_X 9
+
+static int lookup[ 35 * 9 ];
+
+static struct {
+ int box;
+ int direction;
+ int value; } data[] = {
+// LetterPad
+{ 32, 0, 30 }, /* A */
+{ 32, 5, 47 }, // v
+{ 33, 0, 49 }, /* N */
+{ 33, 6, 38 }, // l
+{ 34, 0, 23 }, /* I */
+{ 34, 7, 45 }, // x
+{ 23, 0, 35 }, /* H */
+{ 23, 4, 37 }, // k
+{ 24, 0, 24 }, /* O */
+{ 24, 1, 16 }, // q
+{ 24, 2, 22 }, // u
+{ 24, 3, 25 }, // p
+{ 24, 4, 48 }, // b
+{ 24, 5, 36 }, // j
+{ 24, 6, 32 }, // d
+{ 24, 7, 34 }, // g
+{ 24, 8, 46 }, // c
+{ 25, 0, 19 }, /* R */
+{ 25, 2, 54 }, // shift
+{ 25, 8, 50 }, // m
+{ 14, 0, 20 }, /* T */
+{ 14, 3, 21 }, // y
+{ 15, 0, 18 }, /* E */
+{ 15, 2, 17 }, // w
+{ 15, 4, 44 }, // z
+{ 15, 7, 51 }, // ,
+{ 15, 6, 52 }, // .
+{ 16, 0, 31 }, /* S */
+{ 16, 1, 33 }, // f
+// Number pad
+{ 28, 0, 2 }, // 1
+{ 29, 0, 3 }, // 2
+{ 30, 0, 4 }, // 3
+{ 19, 0, 5 }, // 4
+{ 20, 0, 6 }, // 5
+{ 21, 0, 7 }, // 6
+{ 10, 0, 8 }, // 7
+{ 11, 0, 9 }, // 8
+{ 15, 7, 51}, // ,
+{ 15, 6, 52}, // .
+{ 12, 0, 10}, // 9
+{ 2, 0, 11 }, // 0
+// Whitespace
+{ 3, 0, 57 }, // Space
+{ 4, 0, 57 }, // Space
+{ 5, 0, 57 }, // Space
+{ 6, 0, 57 }, // Space
+{13, 0, 57 }, // Space
+{13, 5, 28 }, // Return
+{13, 6, 28 }, // Return
+{13, 7, 28 }, // Return
+{ 3, 4, 15 }, // Tab
+{ 4, 4, 15 }, // Tab
+{ 5, 4, 15 }, // Tab
+{ 6, 4, 15 }, // Tab
+{ 7, 0, 14 }, // Backspace
+{ 6, 8, 14 }, // Backspace
+{ 5, 8, 14 }, // Backspace
+{ 4, 8, 14 }, // Backspace
+{ 3, 8, 14 }, // Backspace
+{31, 0, 58 }, // Caps lock
+{27, 0, 0}}; // ESC
+
+
+#endif
Added: tsk/trunk/tsk.c
===================================================================
--- tsk/trunk/tsk.c (rev 0)
+++ tsk/trunk/tsk.c 2007-02-14 09:08:12 UTC (rev 808)
@@ -0,0 +1,163 @@
+/*
+ * tsk.c
+ *
+ * Touchscreen Keyboard: creates a virtual keyboard on your touchscreen
+ *
+ * Author: Scott Mansell <ph...@gm...>
+ *
+ * This file has been released under the GPL version 2
+ */
+
+
+#include <stdio.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <string.h>
+#include <linux/input.h>
+#include <linux/uinput.h>
+
+#define absX 0
+#define absY 1
+#define absZ 24
+#define DOWN 192
+
+#include "messagease.h"
+
+//You will need to calibrate, the digitizer to the sticker
+//Sorry, later I will include a feature to do this automaticly
+#define TOP 1180 //Top of sticker
+#define BOTTOM 200 // Bottom of sticker
+#define LEFT 240 // Left side of sticker
+#define RIGHT 3760 // Right side
+
+//Don't touch these, they automaticly adjust to the above settings
+#define HEIGHT (int) ((TOP-BOTTOM)/BOX_Y)
+#define WIDTH (int) ((RIGHT-LEFT)/BOX_X)
+
+int box(int startx, int starty, int endx, int endy)
+{
+ int start = ((startx - LEFT) / WIDTH + (starty - BOTTOM) / HEIGHT * BOX_X);
+ if (start > BOX_X*BOX_Y)
+ return -1;
+ int end = ((endx - LEFT) / WIDTH + (endy - BOTTOM) / HEIGHT * BOX_X);
+ int ret = start*9;
+ switch( start-end )
+ {
+ case 1: //Mid left
+ ret += 8;
+ break;
+ case 0: //Mid
+ break;
+ case -1: // Mid right
+ ret += 4;
+ break;
+ case (BOX_X - 1): //Bot right
+ ret += 5;
+ break;
+ case (BOX_X): //Bot mid
+ ret += 6;
+ break;
+ case (BOX_X + 1): //Bot left
+ ret += 7;
+ break;
+ case (BOX_X * -1 + 1): //Top left
+ ret += 1;
+ break;
+ case (BOX_X * -1): // Top Mid
+ ret += 2;
+ break;
+ case (BOX_X * -1 - 1): // Top Right
+ ret += 3;
+ break;
+ default: // To far...
+ ret = -1;
+ }
+ return ret;
+}
+
+int main (int argc, char* argv[])
+{
+ struct input_event ev;
+ struct input_event event;
+ int x;
+ int y;
+ int z;
+ int i;
+ int startx;
+ int starty;
+
+ //Seting up uinput
+ struct uinput_user_dev uidev;
+ int ctr;
+ int uinput = open("/dev/input/uinput",O_WRONLY | O_NDELAY);
+ if (uinput == -1)
+ {
+ printf("Error: Could not open uinput driver.\n");
+ return 1;
+ }
+ memset(&uidev, 0, sizeof(uidev));
+ strncpy(uidev.name, "SerKBD", UINPUT_MAX_NAME_SIZE);
+ uidev.id.bustype = BUS_RS232;
+ uidev.id.vendor = 0x00;
+ uidev.id.product = 0x00;
+ uidev.id.version = 0x00;
+ ioctl (uinput, UI_SET_EVBIT, EV_KEY);
+ ioctl (uinput, UI_SET_EVBIT, EV_REP);
+ for (i = 0; i <= (BOX_X * BOX_Y * 9 + 0); i++) {
+ ioctl(uinput, UI_SET_KEYBIT, i);
+ }
+ write (uinput, &uidev, sizeof(uidev));
+ if (ioctl(uinput, UI_DEV_CREATE)) {
+ perror ("failed to create uinput device");
+ return 1;
+ }
+ //End of setting up uinput
+
+ //Setup Lookup table
+ memset(&lookup, 0, sizeof(lookup)); // Zero the lookup table
+ for (i = 0; i<(sizeof(data) / (sizeof data[0])); i++)
+ lookup[(data[i].box * 9 + data[i].direction)] = data[i].value;
+ //open the touch screen for input
+ int touch = open("/dev/input/event1", O_RDONLY); //Right now hardcoded to event1
+ if(touch == -1){
+ printf("Error, Could not open touchscreen");
+ return 1;}
+ do { // Main program loop
+ do { // We loop through the events reading x, y and pressure values untill we get a blank event.
+ read(touch, &ev, sizeof(struct input_event)); //Read from event interface
+ if (ev.type == 3)
+ switch(ev.code)
+ {
+ case absX:
+ x = ev.value;
+ break;
+ case absY:
+ y = ev.value;
+ break;
+ case absZ: // Pen pressure
+ z = ev.value;
+ }
+ } while (ev.type != 0);
+ if(z == DOWN) // If the pen has just been put down, then we record the start x and y cordnates.
+ {
+ startx = x;
+ starty = y;
+ z = 1; // Clear z so we don't record startx and starty untill the pen goes down again
+ }
+ if(z == 0) // Pen up
+ {
+ z = 1; //clear z again
+ int code = box(startx, starty, x, y);
+ if (code != -1 && lookup[code] != 0)
+ {
+ event.type = EV_KEY; //indicates the keyboard event
+ event.code = lookup[code]; //Key value
+ event.value = 1; //amount of key
+ write (uinput, &event, sizeof event);
+ event.value = 0; //amount of key
+ write (uinput, &event, sizeof event);
+ }
+ }
+ } while(1);
+ return 1; //Right now we will never get here.
+;}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|