Ghost Mouse / Mbed 2 deprecated ghost_mouse

Dependencies:   mbed

Revision:
4:1f443e7a0122
Parent:
3:7b0c215eb6a7
Child:
5:34c72bf980fa
--- a/main.cpp	Fri Mar 31 22:49:07 2017 +0000
+++ b/main.cpp	Fri Mar 31 23:27:52 2017 +0000
@@ -2,7 +2,7 @@
 
 DigitalOut myled(LED1);
 Serial pc(USBTX, USBRX);
-
+Serial keyOut(p13, p14);
 I2C camera1(p9, p10);
 
 //initial camera data
@@ -37,6 +37,8 @@
 int oney[4];
 
 
+
+
 void write2bytes(char data1, char data2){
     char out[2];
     out[0] = data1;
@@ -45,6 +47,31 @@
     wait(0.01);   
 }
 
+void mouseCommand(uint8_t buttons, uint8_t x, uint8_t y) {
+  keyOut.putc(0xFD);
+  keyOut.putc(0x00);
+  keyOut.putc(0x03);
+  keyOut.putc(buttons);
+  keyOut.putc(x);
+  keyOut.putc(y);
+  keyOut.putc(0x00);
+  keyOut.putc(0x00);
+  keyOut.putc(0x00);
+}
+
+void keyCommand(uint8_t modifiers, uint8_t keycode1, uint8_t keycode2 = 0, uint8_t keycode3 = 0, 
+                uint8_t keycode4 = 0, uint8_t keycode5 = 0, uint8_t keycode6 = 0) {
+  keyOut.putc(0xFD);       // our command
+  keyOut.putc(modifiers);  // modifier!
+  keyOut.putc(0x00); // 0x00  
+  keyOut.putc(keycode1);   // key code #1
+  keyOut.putc(keycode2); // key code #2
+  keyOut.putc(keycode3); // key code #3
+  keyOut.putc(keycode4); // key code #4
+  keyOut.putc(keycode5); // key code #5
+  keyOut.putc(keycode6); // key code #6
+}
+
 void initCamera(void){
   // Initialize WiiMote Camera
     write2bytes(0x30, 0x01); 
@@ -128,6 +155,10 @@
         
         //y coordinate
         pc.printf(" %d\t", y);  
+        
+        if(x < 800 ){
+            keyOut.putc(0x41);
+        }
     }
     
     //new line and delay
@@ -135,6 +166,10 @@
     //wait(0.01);
 }
 
+
+
+
+
 int main() {
     myled = 0;
     //slaveAddress = IRsensorAddress >> 1;
@@ -144,6 +179,11 @@
     //update baud rate
     pc.baud(115200);
     
+    //click the left button and drag the mouse down 50 units
+    //mouseCommand(0x1, 0, -50);
+    keyCommand(0, 4);
+
+    
     
     while(1) {
         wait(0.01);
@@ -155,5 +195,6 @@
         //print points
         printCamData(onex, oney);  
         
+        
     }
 }