Ghost Mouse / Mbed 2 deprecated ghost_mouse

Dependencies:   mbed

Revision:
16:6b4a71e6f75a
Parent:
15:54cee979f202
Child:
17:08d6d9badb3f
--- a/main.cpp	Wed Apr 05 00:46:12 2017 +0000
+++ b/main.cpp	Wed Apr 05 01:35:55 2017 +0000
@@ -1,4 +1,5 @@
 #include "mbed.h"
+#include <RawSerial.h>
 
 //******************************************************************
 // All variables defined below
@@ -6,10 +7,11 @@
 
 //communication
 DigitalOut myled(LED1);
-Serial pc(USBTX, USBRX);
-Serial keyOut(p13, p14);
+RawSerial pc(USBTX, USBRX);
+RawSerial keyOut(p13, p14);
 I2C camera1(p9, p10);
 
+
 //initial camera data
 int IRsensorAddress = 0xB0;
 int slaveAddress;
@@ -48,7 +50,8 @@
 int prevy[4];
 
 //movement
-int deadzone = 5;
+int deadzone = 1;
+int mouseMoveMult = 40;
 
 //counts for clicks
 int clickDeadzone = 10;
@@ -65,11 +68,13 @@
 //implemented for ticker behavior
 //ticker depends on these values to update the state/location of the mouse
 Ticker mouseStateTicker;
-int updatex[4];
-int updatey[4];
+short updatex[4];
+short updatey[4];
 bool toLeftClick = false;
 bool toRightClick = false;
 
+//LED
+DigitalOut myled2(LED2);
 
 
 
@@ -80,7 +85,10 @@
 //takes in values for the movement in the x and y direction 
 //also can indicate whether you want to "click"
 //NOTE: hard coded wait of 0.1
-void mouseCommand(char buttons, char x, char y) {
+void mouseCommand(char buttons, short x, short y) {
+  x = mouseMoveMult*x;
+  y = mouseMoveMult*y;
+  
   keyOut.putc(0xFD);
   keyOut.putc(0x00);
   keyOut.putc(0x03);
@@ -97,14 +105,18 @@
 
 
 
+
 //the interrupt to update mouse state
 //run every 100 us
 void updateMouseState(){
     
+    myled2 = 1 - myled2;
+    
+    
     //move mouse
     //handles only single finger actions
     //TODO: uncomment
-    mouseCommand(0, (char) updatex[0], (char) updatey[0]);
+    mouseCommand(0, updatex[0], updatey[0]);
     
     //clear out changes
     updatex[0] = 0;
@@ -163,6 +175,14 @@
         //update target position to move x and y
         updatex[0] = diffX;
         updatey[0] = diffY;
+        
+        
+//        pc.printf("updating x to : %d", diffX);
+//        pc.printf("\t updating y to : %d \n", diffY);  
+        
+//        pc.printf("updating x to : %d", updatex[0]);
+//        pc.printf("\t updating y to : %d \n", updatex[0]);
+        
     }
 }
 
@@ -290,7 +310,7 @@
 //NOTE: 1023 means nothing was detected
 void readCameraData(void){
         
-    pc.printf("in read camera data \n");
+    //pc.printf("in read camera data \n");
         
     //request data from camera 
     char out[1];
@@ -383,6 +403,8 @@
     updatey[0] = 0;
     
     myled = 0;
+    myled2 = 0;
+    
     //slaveAddress = IRsensorAddress >> 1;
     slaveAddress = IRsensorAddress;
     initCamera();
@@ -391,17 +413,19 @@
     pc.baud(115200);
     
     //attach ticker for interrupt
-    mouseStateTicker.attach_us(&updateMouseState, 100);
+    //mouseStateTicker.attach_us(&updateMouseState, 100);
+    mouseStateTicker.attach(&updateMouseState, 0.1);
+    
     
     //loop to search for new info using the camera    
     while(1) {
 
-        pc.printf("while\n");
+        //pc.printf("while\n");
         
         //toggle test LED 
         myled = 1 - myled;
         
-        pc.printf("while2\n");
+        //pc.printf("while2\n");
         
         
         //get the camera data