Superhans v1 (index finger click and second finger 'q')

Dependencies:   MMA8451Q USBDevice mbed-rtos mbed

Fork of Super_Hans_USB by Anurag Dhutti

Committer:
InBrewJ
Date:
Thu Jan 30 14:48:49 2014 +0000
Revision:
2:034f34663c45
v1 Superhans

Who changed what in which revision?

UserRevisionLine numberNew contents of line
InBrewJ 2:034f34663c45 1 /* SuperHansRightGlove.cpp
InBrewJ 2:034f34663c45 2
InBrewJ 2:034f34663c45 3 IDEA - MAP FLEX SENSORS TO A SET HID REPORT.data
InBrewJ 2:034f34663c45 4 will allow more button presses!
InBrewJ 2:034f34663c45 5
InBrewJ 2:034f34663c45 6 Code for WIRED RIGHT GLOVE
InBrewJ 2:034f34663c45 7
InBrewJ 2:034f34663c45 8 Sends mouse movement dependent on tilt
InBrewJ 2:034f34663c45 9 of the glove, index finger left mouse click,
InBrewJ 2:034f34663c45 10 middle finger 'q' press and various
InBrewJ 2:034f34663c45 11 finger/palm keys corresponding to various
InBrewJ 2:034f34663c45 12 keys on a standard keyboard
InBrewJ 2:034f34663c45 13
InBrewJ 2:034f34663c45 14 For use with:
InBrewJ 2:034f34663c45 15 FRDM KL25Z
InBrewJ 2:034f34663c45 16
InBrewJ 2:034f34663c45 17 Authors:
InBrewJ 2:034f34663c45 18 Tristan Hughes
InBrewJ 2:034f34663c45 19 Anurag Dhutti
InBrewJ 2:034f34663c45 20 Jason Brewer
InBrewJ 2:034f34663c45 21 */
InBrewJ 2:034f34663c45 22
InBrewJ 2:034f34663c45 23 #include "mbed.h"
InBrewJ 2:034f34663c45 24 #include "rtos.h"
InBrewJ 2:034f34663c45 25 #define MMA8451_I2C_ADDRESS (0x1d<<1)
InBrewJ 2:034f34663c45 26 #include "MMA8451Q.h"
InBrewJ 2:034f34663c45 27 #include "USBMouseKeyboard.h"
InBrewJ 2:034f34663c45 28 #include "USBHID.h"
InBrewJ 2:034f34663c45 29
InBrewJ 2:034f34663c45 30 // Misc Init
InBrewJ 2:034f34663c45 31
InBrewJ 2:034f34663c45 32 DigitalOut led(LED1);
InBrewJ 2:034f34663c45 33 MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
InBrewJ 2:034f34663c45 34 AnalogIn ain(PTB1); // Forefinger sensor
InBrewJ 2:034f34663c45 35 AnalogIn ain1(PTB0); // Second finger Sensor
InBrewJ 2:034f34663c45 36 USBMouseKeyboard key_mouse;
InBrewJ 2:034f34663c45 37 Mutex USB_mutex;
InBrewJ 2:034f34663c45 38
InBrewJ 2:034f34663c45 39 // Button Init
InBrewJ 2:034f34663c45 40
InBrewJ 2:034f34663c45 41 // D-Pad Palm Switches
InBrewJ 2:034f34663c45 42 DigitalIn _up(PTE5);
InBrewJ 2:034f34663c45 43 DigitalIn _left(PTE4);
InBrewJ 2:034f34663c45 44 DigitalIn _down(PTE3);
InBrewJ 2:034f34663c45 45 DigitalIn _right(PTE2);
InBrewJ 2:034f34663c45 46 DigitalIn _sel(PTB11);
InBrewJ 2:034f34663c45 47 DigitalIn _start(PTB10);
InBrewJ 2:034f34663c45 48
InBrewJ 2:034f34663c45 49 // Finger Switches
InBrewJ 2:034f34663c45 50 DigitalIn _i1(PTE31);
InBrewJ 2:034f34663c45 51
InBrewJ 2:034f34663c45 52 DigitalIn _s1(PTA17);
InBrewJ 2:034f34663c45 53 DigitalIn _s2(PTA16);
InBrewJ 2:034f34663c45 54 DigitalIn _s3(PTC17);
InBrewJ 2:034f34663c45 55 DigitalIn _s4(PTC16);
InBrewJ 2:034f34663c45 56
InBrewJ 2:034f34663c45 57 DigitalIn _th1(PTC13);
InBrewJ 2:034f34663c45 58 DigitalIn _th2(PTC12);
InBrewJ 2:034f34663c45 59 DigitalIn _th3(PTC11);
InBrewJ 2:034f34663c45 60 DigitalIn _th4(PTC10);
InBrewJ 2:034f34663c45 61
InBrewJ 2:034f34663c45 62 DigitalIn _pi1(PTC6);
InBrewJ 2:034f34663c45 63
InBrewJ 2:034f34663c45 64 void click_thread(void const *args)
InBrewJ 2:034f34663c45 65 {
InBrewJ 2:034f34663c45 66 bool press[2];
InBrewJ 2:034f34663c45 67 bool lPress = 0;
InBrewJ 2:034f34663c45 68 //bool rPress = 0;
InBrewJ 2:034f34663c45 69
InBrewJ 2:034f34663c45 70 // PLEASE NOTE:
InBrewJ 2:034f34663c45 71 // The following code does not allow both mouse
InBrewJ 2:034f34663c45 72 // buttons to be pressed down at the same time.
InBrewJ 2:034f34663c45 73 // Your system will register the press of each button
InBrewJ 2:034f34663c45 74 // but as soon as one is released the other will also
InBrewJ 2:034f34663c45 75 // be released. Review your application to see if this is
InBrewJ 2:034f34663c45 76 // applicable.
InBrewJ 2:034f34663c45 77
InBrewJ 2:034f34663c45 78 while(true) {
InBrewJ 2:034f34663c45 79 lPress = ain.read()<0.5;
InBrewJ 2:034f34663c45 80 //rPress = ain1.read()<0.25;
InBrewJ 2:034f34663c45 81 //key_mouse.printf("Fore: %f Sec: %f\n",ain.read(), ain1.read());
InBrewJ 2:034f34663c45 82 if( lPress && (press[0] == 0) ) {
InBrewJ 2:034f34663c45 83 press[0] = 1;
InBrewJ 2:034f34663c45 84 led != led;
InBrewJ 2:034f34663c45 85 //key_mouse.printf("L: %i\n", lPress);
InBrewJ 2:034f34663c45 86 USB_mutex.lock();
InBrewJ 2:034f34663c45 87 key_mouse.press(MOUSE_LEFT);
InBrewJ 2:034f34663c45 88 USB_mutex.unlock();
InBrewJ 2:034f34663c45 89 } else if ( !lPress && (press[0] == 1) ) {
InBrewJ 2:034f34663c45 90 press[0] = 0;
InBrewJ 2:034f34663c45 91 //key_mouse.printf("L: %i\n", lPress);
InBrewJ 2:034f34663c45 92 USB_mutex.lock();
InBrewJ 2:034f34663c45 93 key_mouse.release(MOUSE_LEFT);
InBrewJ 2:034f34663c45 94 USB_mutex.unlock();
InBrewJ 2:034f34663c45 95 }
InBrewJ 2:034f34663c45 96 if(!_i1 && press[1] == 0) {
InBrewJ 2:034f34663c45 97 //if( rPress && (press[1] == 0) ) {
InBrewJ 2:034f34663c45 98 //key_mouse.printf("R: %i\n", rPress);
InBrewJ 2:034f34663c45 99 press[1] = 1;
InBrewJ 2:034f34663c45 100 if(!lPress) USB_mutex.lock();
InBrewJ 2:034f34663c45 101 key_mouse.press(MOUSE_RIGHT);
InBrewJ 2:034f34663c45 102 if(!lPress) USB_mutex.unlock(); // As Right mouse click
InBrewJ 2:034f34663c45 103 }else if(_i1 && press[1] == 1) {
InBrewJ 2:034f34663c45 104 //}else if( !rPress && (press[1] == 1) ) {
InBrewJ 2:034f34663c45 105 //key_mouse.printf("R: %i\n", rPress);
InBrewJ 2:034f34663c45 106 press[1] = 0;
InBrewJ 2:034f34663c45 107 if(!lPress) USB_mutex.lock();
InBrewJ 2:034f34663c45 108 key_mouse.release(MOUSE_RIGHT);
InBrewJ 2:034f34663c45 109 if(!lPress) USB_mutex.unlock();
InBrewJ 2:034f34663c45 110 }
InBrewJ 2:034f34663c45 111
InBrewJ 2:034f34663c45 112 Thread::wait(100);
InBrewJ 2:034f34663c45 113 }
InBrewJ 2:034f34663c45 114 }
InBrewJ 2:034f34663c45 115
InBrewJ 2:034f34663c45 116
InBrewJ 2:034f34663c45 117 void mouse_thread(void const *args)
InBrewJ 2:034f34663c45 118 {
InBrewJ 2:034f34663c45 119 while(true) {
InBrewJ 2:034f34663c45 120
InBrewJ 2:034f34663c45 121 USB_mutex.lock();
InBrewJ 2:034f34663c45 122 key_mouse.move(-acc.getAccZ()*10, 0);
InBrewJ 2:034f34663c45 123 key_mouse.move(0, -acc.getAccX()*10);
InBrewJ 2:034f34663c45 124 USB_mutex.unlock();
InBrewJ 2:034f34663c45 125 Thread::wait(1);
InBrewJ 2:034f34663c45 126 }
InBrewJ 2:034f34663c45 127 }
InBrewJ 2:034f34663c45 128
InBrewJ 2:034f34663c45 129 void SendKeyPress (uint8_t keyID, bool state, uint8_t numberPressed)
InBrewJ 2:034f34663c45 130 {
InBrewJ 2:034f34663c45 131 // Send a simulated keyboard keypress. Returns true if successful.
InBrewJ 2:034f34663c45 132 static HID_REPORT report;
InBrewJ 2:034f34663c45 133 static uint8_t last_pressed;
InBrewJ 2:034f34663c45 134 static uint8_t keyBuffer[3];
InBrewJ 2:034f34663c45 135
InBrewJ 2:034f34663c45 136 report.data[0] = REPORT_ID_KEYBOARD;
InBrewJ 2:034f34663c45 137 report.data[1] = 0;
InBrewJ 2:034f34663c45 138 report.data[2] = 0;
InBrewJ 2:034f34663c45 139 //report.data[3] = 0;
InBrewJ 2:034f34663c45 140 //report.data[4] = 0;
InBrewJ 2:034f34663c45 141 //report.data[5] = 0;
InBrewJ 2:034f34663c45 142 report.data[6] = 0;
InBrewJ 2:034f34663c45 143 report.data[7] = 0;
InBrewJ 2:034f34663c45 144 report.data[8] = 0;
InBrewJ 2:034f34663c45 145
InBrewJ 2:034f34663c45 146 report.length = 9;
InBrewJ 2:034f34663c45 147
InBrewJ 2:034f34663c45 148 // Multiple button press functionality
InBrewJ 2:034f34663c45 149
InBrewJ 2:034f34663c45 150 if(!numberPressed) // Clear the keyBuffer if no buttons are pressed
InBrewJ 2:034f34663c45 151 {
InBrewJ 2:034f34663c45 152 keyBuffer[0] = 0;
InBrewJ 2:034f34663c45 153 keyBuffer[1] = 0;
InBrewJ 2:034f34663c45 154 keyBuffer[2] = 0;
InBrewJ 2:034f34663c45 155 }
InBrewJ 2:034f34663c45 156
InBrewJ 2:034f34663c45 157 if(state) // If a button is pressed, put it in the keyBuffer
InBrewJ 2:034f34663c45 158 {
InBrewJ 2:034f34663c45 159 keyBuffer[numberPressed-1] = keyID;
InBrewJ 2:034f34663c45 160 }
InBrewJ 2:034f34663c45 161
InBrewJ 2:034f34663c45 162 // If keys are depressed in the same order
InBrewJ 2:034f34663c45 163 // in which they were pressed, swap the second
InBrewJ 2:034f34663c45 164 // member of the key buffer with the first so
InBrewJ 2:034f34663c45 165 // expected behaviour is maintained
InBrewJ 2:034f34663c45 166
InBrewJ 2:034f34663c45 167 // Only has functionality for 2 key presses at once
InBrewJ 2:034f34663c45 168 // which follows most standard keyboard
InBrewJ 2:034f34663c45 169
InBrewJ 2:034f34663c45 170 // 3 key presses at once gets a little trickier
InBrewJ 2:034f34663c45 171
InBrewJ 2:034f34663c45 172 if(!state && numberPressed == 1 &&
InBrewJ 2:034f34663c45 173 keyBuffer[0] == keyID)
InBrewJ 2:034f34663c45 174 {
InBrewJ 2:034f34663c45 175 keyBuffer[0] = keyBuffer[1];
InBrewJ 2:034f34663c45 176 keyBuffer[1] = 0;
InBrewJ 2:034f34663c45 177 }
InBrewJ 2:034f34663c45 178
InBrewJ 2:034f34663c45 179 //key_mouse.printf("keyBuffer: %X, %X, %X\n", keyBuffer[0], keyBuffer[1], keyBuffer[2]);
InBrewJ 2:034f34663c45 180
InBrewJ 2:034f34663c45 181 if(numberPressed == 0)
InBrewJ 2:034f34663c45 182 {
InBrewJ 2:034f34663c45 183 report.data[3] = 0;
InBrewJ 2:034f34663c45 184 report.data[4] = 0;
InBrewJ 2:034f34663c45 185 report.data[5] = 0;
InBrewJ 2:034f34663c45 186 }else if(numberPressed == 1)
InBrewJ 2:034f34663c45 187 {
InBrewJ 2:034f34663c45 188 report.data[3] = keyBuffer[0];
InBrewJ 2:034f34663c45 189 report.data[4] = 0;
InBrewJ 2:034f34663c45 190 report.data[5] = 0;
InBrewJ 2:034f34663c45 191 }else if(numberPressed == 2)
InBrewJ 2:034f34663c45 192 {
InBrewJ 2:034f34663c45 193 report.data[3] = report.data[3];
InBrewJ 2:034f34663c45 194 report.data[4] = keyBuffer[1];
InBrewJ 2:034f34663c45 195 report.data[5] = 0;
InBrewJ 2:034f34663c45 196 } else if(numberPressed == 3) // not actually functional
InBrewJ 2:034f34663c45 197 {
InBrewJ 2:034f34663c45 198 report.data[3] = report.data[3];
InBrewJ 2:034f34663c45 199 report.data[4] = report.data[4];
InBrewJ 2:034f34663c45 200 report.data[5] = keyBuffer[2];
InBrewJ 2:034f34663c45 201 }
InBrewJ 2:034f34663c45 202
InBrewJ 2:034f34663c45 203 key_mouse.send(&report);
InBrewJ 2:034f34663c45 204
InBrewJ 2:034f34663c45 205 }
InBrewJ 2:034f34663c45 206
InBrewJ 2:034f34663c45 207 void keyboard_thread(void const *args)
InBrewJ 2:034f34663c45 208 {
InBrewJ 2:034f34663c45 209 uint8_t numberPressed = 0;
InBrewJ 2:034f34663c45 210 bool press[16] = {0};
InBrewJ 2:034f34663c45 211
InBrewJ 2:034f34663c45 212 while(true) {
InBrewJ 2:034f34663c45 213
InBrewJ 2:034f34663c45 214 // Uncomment for debug
InBrewJ 2:034f34663c45 215
InBrewJ 2:034f34663c45 216 //key_mouse.printf("No: %d\n", numberPressed);
InBrewJ 2:034f34663c45 217 /*key_mouse.printf("pressArr: %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n",
InBrewJ 2:034f34663c45 218 press[0], press[1], press[2], press[3], press[4], press[5], press[6], press[7],
InBrewJ 2:034f34663c45 219 press[8], press[9], press[10], press[11], press[12], press[13], press[14], press[15]);*/
InBrewJ 2:034f34663c45 220
InBrewJ 2:034f34663c45 221 // Makes the second bend sensor map to the key "q"
InBrewJ 2:034f34663c45 222 // Mapping the second bend sensor to right mouse
InBrewJ 2:034f34663c45 223 // poses some issues to do with how the clicks are sent
InBrewJ 2:034f34663c45 224 // in the mbed libraries. An indepth analysis
InBrewJ 2:034f34663c45 225 // of HID reports is required and tbh cba ukno
InBrewJ 2:034f34663c45 226
InBrewJ 2:034f34663c45 227 if( (ain1.read()<0.25) && (press[0] == 0) ) {
InBrewJ 2:034f34663c45 228 if(press[0] == 0) numberPressed++;
InBrewJ 2:034f34663c45 229 press[0] = 1;
InBrewJ 2:034f34663c45 230 //key_mouse.printf(" qPress: %i\n", press[0]);
InBrewJ 2:034f34663c45 231 //USB_mutex.lock();
InBrewJ 2:034f34663c45 232 //key_mouse.press(MOUSE_RIGHT); // Sends right mouse click
InBrewJ 2:034f34663c45 233 //USB_mutex.unlock();
InBrewJ 2:034f34663c45 234 SendKeyPress(0x14,1,numberPressed); // Sends 'q' keypress
InBrewJ 2:034f34663c45 235 } else if ( (ain1.read()>0.25) && (press[0] == 1) ) {
InBrewJ 2:034f34663c45 236 if(press[0] == 1) numberPressed--;
InBrewJ 2:034f34663c45 237 press[0] = 0;
InBrewJ 2:034f34663c45 238 //key_mouse.printf("R: %i\n", press[0]);
InBrewJ 2:034f34663c45 239 //USB_mutex.lock();
InBrewJ 2:034f34663c45 240 //key_mouse.release(MOUSE_RIGHT); // releases right mouse click
InBrewJ 2:034f34663c45 241 //USB_mutex.unlock();
InBrewJ 2:034f34663c45 242 SendKeyPress(0x14,0,numberPressed);
InBrewJ 2:034f34663c45 243 }else
InBrewJ 2:034f34663c45 244 {
InBrewJ 2:034f34663c45 245 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 246 }
InBrewJ 2:034f34663c45 247
InBrewJ 2:034f34663c45 248 // FOREFINGER BUTTON
InBrewJ 2:034f34663c45 249
InBrewJ 2:034f34663c45 250 /*if(!_i1 && press[0] == 0) {
InBrewJ 2:034f34663c45 251 press[0] = 1;
InBrewJ 2:034f34663c45 252 SendKeyPress(0x14,0); // Sends 'q' keypress
InBrewJ 2:034f34663c45 253 //Thread::wait(60);
InBrewJ 2:034f34663c45 254 } else if(_i1 && press[0] == 1) {
InBrewJ 2:034f34663c45 255 press[0] = 0;
InBrewJ 2:034f34663c45 256 Thread::wait(17);
InBrewJ 2:034f34663c45 257 SendKeyPress(0,1);
InBrewJ 2:034f34663c45 258 }*/
InBrewJ 2:034f34663c45 259
InBrewJ 2:034f34663c45 260 // SECOND FINGER BUTTONS (4 of them)
InBrewJ 2:034f34663c45 261
InBrewJ 2:034f34663c45 262 if(!_s1 && press[1] == 0) {
InBrewJ 2:034f34663c45 263 if(press[1] == 0) numberPressed++;
InBrewJ 2:034f34663c45 264 press[1] = 1;
InBrewJ 2:034f34663c45 265 SendKeyPress(0x08,1,numberPressed); // Sends 'e' keypress (a = 0x04)
InBrewJ 2:034f34663c45 266 //SendKeyPress(0x04,1,numberPressed);
InBrewJ 2:034f34663c45 267 //Thread::wait(60);
InBrewJ 2:034f34663c45 268 } else if(_s1 && press[1] == 1) {
InBrewJ 2:034f34663c45 269 if(press[1] == 1) numberPressed--;
InBrewJ 2:034f34663c45 270 press[1] = 0;
InBrewJ 2:034f34663c45 271 Thread::wait(17);
InBrewJ 2:034f34663c45 272 SendKeyPress(0x4,0,numberPressed);
InBrewJ 2:034f34663c45 273 }else
InBrewJ 2:034f34663c45 274 {
InBrewJ 2:034f34663c45 275 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 276 }
InBrewJ 2:034f34663c45 277
InBrewJ 2:034f34663c45 278 if(!_s2 && press[2] == 0) {
InBrewJ 2:034f34663c45 279 if(press[2] == 0) numberPressed++;
InBrewJ 2:034f34663c45 280 press[2] = 1;
InBrewJ 2:034f34663c45 281 SendKeyPress(0x15,1,numberPressed); // Sends 'r' keypress (w = 0x1a)
InBrewJ 2:034f34663c45 282 //SendKeyPress(0x1a,1,numberPressed);
InBrewJ 2:034f34663c45 283 } else if(_s2 && press[2] == 1) {
InBrewJ 2:034f34663c45 284 if(press[2] == 1) numberPressed--;
InBrewJ 2:034f34663c45 285 press[2] = 0;
InBrewJ 2:034f34663c45 286 Thread::wait(17);
InBrewJ 2:034f34663c45 287 SendKeyPress(0x1a,0,numberPressed);
InBrewJ 2:034f34663c45 288 }else
InBrewJ 2:034f34663c45 289 {
InBrewJ 2:034f34663c45 290 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 291 }
InBrewJ 2:034f34663c45 292
InBrewJ 2:034f34663c45 293 if(!_s3 && press[3]== 0) {
InBrewJ 2:034f34663c45 294 if(press[3] == 0) numberPressed++;
InBrewJ 2:034f34663c45 295 press[3] = 1;
InBrewJ 2:034f34663c45 296 SendKeyPress(0x17,1,numberPressed); // Sends 't' keypress (s = 0x16)
InBrewJ 2:034f34663c45 297 //SendKeyPress(0x16,numberPressed);
InBrewJ 2:034f34663c45 298 //Thread::wait(60);
InBrewJ 2:034f34663c45 299 } else if(_s3 && press[3]== 1) {
InBrewJ 2:034f34663c45 300 if(press[3] == 1) numberPressed--;
InBrewJ 2:034f34663c45 301 press[3] = 0;
InBrewJ 2:034f34663c45 302 Thread::wait(17);
InBrewJ 2:034f34663c45 303 SendKeyPress(0x17,0,numberPressed);
InBrewJ 2:034f34663c45 304 }else
InBrewJ 2:034f34663c45 305 {
InBrewJ 2:034f34663c45 306 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 307 }
InBrewJ 2:034f34663c45 308
InBrewJ 2:034f34663c45 309 if(!_s4 && press[4]== 0) {
InBrewJ 2:034f34663c45 310 if(press[4] == 0) numberPressed++;
InBrewJ 2:034f34663c45 311 press[4] = 1;
InBrewJ 2:034f34663c45 312 SendKeyPress(0x1c,1,numberPressed); // Sends 'y' keypress (d = 0x07)
InBrewJ 2:034f34663c45 313 //SendKeyPress(0x07,0);
InBrewJ 2:034f34663c45 314 //Thread::wait(60);
InBrewJ 2:034f34663c45 315 } else if(_s4 && press[4]== 1) {
InBrewJ 2:034f34663c45 316 if(press[4] == 1) numberPressed--;
InBrewJ 2:034f34663c45 317 press[4] = 0;
InBrewJ 2:034f34663c45 318 Thread::wait(17);
InBrewJ 2:034f34663c45 319 SendKeyPress(0x1c,0,numberPressed);
InBrewJ 2:034f34663c45 320 }else
InBrewJ 2:034f34663c45 321 {
InBrewJ 2:034f34663c45 322 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 323 }
InBrewJ 2:034f34663c45 324
InBrewJ 2:034f34663c45 325 // THIRD FINGER BUTTONS (4 of them)
InBrewJ 2:034f34663c45 326
InBrewJ 2:034f34663c45 327 if(!_th1 && press[5]== 0) {
InBrewJ 2:034f34663c45 328 if(press[5] == 0) numberPressed++;
InBrewJ 2:034f34663c45 329 press[5]= 1;
InBrewJ 2:034f34663c45 330 SendKeyPress(0x18,1,numberPressed); // Sends 'u' keypress
InBrewJ 2:034f34663c45 331 Thread::wait(60);
InBrewJ 2:034f34663c45 332 } else if(_th1 && press[5]== 1) {
InBrewJ 2:034f34663c45 333 if(press[5] == 1) numberPressed--;
InBrewJ 2:034f34663c45 334 press[5]= 0;
InBrewJ 2:034f34663c45 335 SendKeyPress(0x18,0,numberPressed);
InBrewJ 2:034f34663c45 336 }else
InBrewJ 2:034f34663c45 337 {
InBrewJ 2:034f34663c45 338 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 339 }
InBrewJ 2:034f34663c45 340
InBrewJ 2:034f34663c45 341 if(!_th2 && press[6]== 0) {
InBrewJ 2:034f34663c45 342 if(press[6] == 0) numberPressed++;
InBrewJ 2:034f34663c45 343 press[6]= 1;
InBrewJ 2:034f34663c45 344 SendKeyPress(0x0c,1,numberPressed); // Sends 'i' keypress
InBrewJ 2:034f34663c45 345
InBrewJ 2:034f34663c45 346 } else if(_th2 && press[6]== 1) {
InBrewJ 2:034f34663c45 347 if(press[6] == 1) numberPressed--;
InBrewJ 2:034f34663c45 348 press[6]= 0;
InBrewJ 2:034f34663c45 349 SendKeyPress(0x0c,0,numberPressed);
InBrewJ 2:034f34663c45 350 }else
InBrewJ 2:034f34663c45 351 {
InBrewJ 2:034f34663c45 352 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 353 }
InBrewJ 2:034f34663c45 354
InBrewJ 2:034f34663c45 355 if(!_th3 && press[7]== 0) {
InBrewJ 2:034f34663c45 356 if(press[7] == 0) numberPressed++;
InBrewJ 2:034f34663c45 357 press[7]= 1;
InBrewJ 2:034f34663c45 358 SendKeyPress(0x12,1,numberPressed); // Sends 'o' keypress
InBrewJ 2:034f34663c45 359
InBrewJ 2:034f34663c45 360 } else if(_th3 && press[7]== 1) {
InBrewJ 2:034f34663c45 361 if(press[7] == 1) numberPressed--;
InBrewJ 2:034f34663c45 362 press[7]= 0;
InBrewJ 2:034f34663c45 363 SendKeyPress(0x12,0,numberPressed);
InBrewJ 2:034f34663c45 364 }else
InBrewJ 2:034f34663c45 365 {
InBrewJ 2:034f34663c45 366 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 367 }
InBrewJ 2:034f34663c45 368
InBrewJ 2:034f34663c45 369 if(!_th4 && press[8]== 0) {
InBrewJ 2:034f34663c45 370 if(press[8] == 0) numberPressed++;
InBrewJ 2:034f34663c45 371 press[8]= 1;
InBrewJ 2:034f34663c45 372 SendKeyPress(0x13,1, numberPressed); // Sends 'p' keypress
InBrewJ 2:034f34663c45 373
InBrewJ 2:034f34663c45 374 } else if(_th4 && press[8]== 1) {
InBrewJ 2:034f34663c45 375 if(press[8] == 1) numberPressed--;
InBrewJ 2:034f34663c45 376 press[8]= 0;
InBrewJ 2:034f34663c45 377 SendKeyPress(0x13,0,numberPressed);
InBrewJ 2:034f34663c45 378 }else
InBrewJ 2:034f34663c45 379 {
InBrewJ 2:034f34663c45 380 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 381 }
InBrewJ 2:034f34663c45 382
InBrewJ 2:034f34663c45 383 // PINKY BUTTON
InBrewJ 2:034f34663c45 384
InBrewJ 2:034f34663c45 385 if(!_pi1 && press[9]== 0) {
InBrewJ 2:034f34663c45 386 if(press[9] == 0) numberPressed++;
InBrewJ 2:034f34663c45 387 press[9]= 1;
InBrewJ 2:034f34663c45 388 //SendKeyPress(0x2f,0); // Sends '[' keypress
InBrewJ 2:034f34663c45 389 SendKeyPress(0x2c,1,numberPressed); // Sends 'space' keypress
InBrewJ 2:034f34663c45 390
InBrewJ 2:034f34663c45 391 } else if(_pi1 && press[9]== 1) {
InBrewJ 2:034f34663c45 392 if(press[9] == 1) numberPressed--;
InBrewJ 2:034f34663c45 393 press[9]= 0;
InBrewJ 2:034f34663c45 394 Thread::wait(17);
InBrewJ 2:034f34663c45 395 SendKeyPress(0x2c,0, numberPressed);
InBrewJ 2:034f34663c45 396 }else
InBrewJ 2:034f34663c45 397 {
InBrewJ 2:034f34663c45 398 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 399 }
InBrewJ 2:034f34663c45 400
InBrewJ 2:034f34663c45 401 // PALM D-PAD BUTTONS (6 of them)
InBrewJ 2:034f34663c45 402
InBrewJ 2:034f34663c45 403 if(!_up && press[10]== 0) {
InBrewJ 2:034f34663c45 404 if(press[10] == 0) numberPressed++;
InBrewJ 2:034f34663c45 405 press[10]= 1;
InBrewJ 2:034f34663c45 406 SendKeyPress(0x52,1,numberPressed); // Sends up arrow keypress
InBrewJ 2:034f34663c45 407
InBrewJ 2:034f34663c45 408 } else if(_up && press[10]== 1) {
InBrewJ 2:034f34663c45 409 if(press[10] == 1) numberPressed--;
InBrewJ 2:034f34663c45 410 press[10]= 0;
InBrewJ 2:034f34663c45 411 SendKeyPress(0x52,1,numberPressed);
InBrewJ 2:034f34663c45 412 }else
InBrewJ 2:034f34663c45 413 {
InBrewJ 2:034f34663c45 414 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 415 }
InBrewJ 2:034f34663c45 416
InBrewJ 2:034f34663c45 417 if(!_left && press[11]== 0) {
InBrewJ 2:034f34663c45 418 if(press[11] == 0) numberPressed++;
InBrewJ 2:034f34663c45 419 press[11]= 1;
InBrewJ 2:034f34663c45 420 SendKeyPress(0x50,1,numberPressed); // Sends left arrow keypress
InBrewJ 2:034f34663c45 421
InBrewJ 2:034f34663c45 422 } else if(_left && press[11]== 1) {
InBrewJ 2:034f34663c45 423 if(press[11] == 1) numberPressed--;
InBrewJ 2:034f34663c45 424 press[11]= 0;
InBrewJ 2:034f34663c45 425 SendKeyPress(0x50,0,numberPressed);
InBrewJ 2:034f34663c45 426 }else
InBrewJ 2:034f34663c45 427 {
InBrewJ 2:034f34663c45 428 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 429 }
InBrewJ 2:034f34663c45 430
InBrewJ 2:034f34663c45 431 if(!_down && press[12]== 0) {
InBrewJ 2:034f34663c45 432 if(press[12] == 0) numberPressed++;
InBrewJ 2:034f34663c45 433 press[12]= 1;
InBrewJ 2:034f34663c45 434 SendKeyPress(0x51,1,numberPressed); // Sends down arrow keypress
InBrewJ 2:034f34663c45 435
InBrewJ 2:034f34663c45 436 } else if(_down && press[12]== 1) {
InBrewJ 2:034f34663c45 437 if(press[12] == 1) numberPressed--;
InBrewJ 2:034f34663c45 438 press[12]= 0;
InBrewJ 2:034f34663c45 439 SendKeyPress(0x51,0,numberPressed);
InBrewJ 2:034f34663c45 440 }else
InBrewJ 2:034f34663c45 441 {
InBrewJ 2:034f34663c45 442 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 443 }
InBrewJ 2:034f34663c45 444
InBrewJ 2:034f34663c45 445 if(!_right && press[13]== 0) {
InBrewJ 2:034f34663c45 446 if(press[13] == 0) numberPressed++;
InBrewJ 2:034f34663c45 447 press[13]= 1;
InBrewJ 2:034f34663c45 448 SendKeyPress(0x4f,1,numberPressed); // Sends right arrow keypress
InBrewJ 2:034f34663c45 449
InBrewJ 2:034f34663c45 450 } else if(_right && press[13]== 1) {
InBrewJ 2:034f34663c45 451 if(press[13] == 1) numberPressed--;
InBrewJ 2:034f34663c45 452 press[13]= 0;
InBrewJ 2:034f34663c45 453 SendKeyPress(0x4f,0,numberPressed);
InBrewJ 2:034f34663c45 454 }else
InBrewJ 2:034f34663c45 455 {
InBrewJ 2:034f34663c45 456 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 457 }
InBrewJ 2:034f34663c45 458
InBrewJ 2:034f34663c45 459 if(!_sel && press[14]== 0) {
InBrewJ 2:034f34663c45 460 if(press[14] == 0) numberPressed++;
InBrewJ 2:034f34663c45 461 press[14]= 1;
InBrewJ 2:034f34663c45 462 SendKeyPress(0x1d,1,numberPressed); // Sends 'z' keypress
InBrewJ 2:034f34663c45 463
InBrewJ 2:034f34663c45 464 } else if(_sel && press[14]== 1) {
InBrewJ 2:034f34663c45 465 if(press[14] == 1) numberPressed--;
InBrewJ 2:034f34663c45 466 press[14]= 0;
InBrewJ 2:034f34663c45 467 SendKeyPress(0x1d,0,numberPressed);
InBrewJ 2:034f34663c45 468 }else
InBrewJ 2:034f34663c45 469 {
InBrewJ 2:034f34663c45 470 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 471 }
InBrewJ 2:034f34663c45 472
InBrewJ 2:034f34663c45 473 if(!_start && press[15]== 0) {
InBrewJ 2:034f34663c45 474 if(press[15] == 0) numberPressed++;
InBrewJ 2:034f34663c45 475 press[15]= 1;
InBrewJ 2:034f34663c45 476 SendKeyPress(0x1b,1,numberPressed); // Sends 'x' keypress
InBrewJ 2:034f34663c45 477
InBrewJ 2:034f34663c45 478 } else if(_start && press[15]== 1) {
InBrewJ 2:034f34663c45 479 if(press[15] == 1) numberPressed--;
InBrewJ 2:034f34663c45 480 press[15]= 0;
InBrewJ 2:034f34663c45 481 SendKeyPress(0x1b,0,numberPressed);
InBrewJ 2:034f34663c45 482 }else
InBrewJ 2:034f34663c45 483 {
InBrewJ 2:034f34663c45 484 numberPressed = numberPressed;
InBrewJ 2:034f34663c45 485 }
InBrewJ 2:034f34663c45 486
InBrewJ 2:034f34663c45 487 Thread::wait(100); // Slows the whole thread down. Without this keys stick!
InBrewJ 2:034f34663c45 488 //Thread::wait(300);
InBrewJ 2:034f34663c45 489
InBrewJ 2:034f34663c45 490 }
InBrewJ 2:034f34663c45 491 }
InBrewJ 2:034f34663c45 492
InBrewJ 2:034f34663c45 493 int main()
InBrewJ 2:034f34663c45 494 {
InBrewJ 2:034f34663c45 495 Thread click(click_thread);
InBrewJ 2:034f34663c45 496 Thread mouse(mouse_thread);
InBrewJ 2:034f34663c45 497 Thread keyboard(keyboard_thread);
InBrewJ 2:034f34663c45 498
InBrewJ 2:034f34663c45 499 led = 1.0;
InBrewJ 2:034f34663c45 500
InBrewJ 2:034f34663c45 501 while (true) {
InBrewJ 2:034f34663c45 502 }
InBrewJ 2:034f34663c45 503 }