Ghost Mouse / Mbed 2 deprecated ghost_mouse

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jennabarton
Date:
Sun Apr 02 22:49:19 2017 +0000
Parent:
13:4f2181174071
Child:
15:54cee979f202
Commit message:
BUG - not responding as expected

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Sun Apr 02 21:33:40 2017 +0000
+++ b/main.cpp	Sun Apr 02 22:49:19 2017 +0000
@@ -61,6 +61,17 @@
 int instabilityCount = 0;
 
 
+//MOUSE STATE
+//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];
+bool toLeftClick = false;
+bool toRightClick = false;
+
+
+
 
 //******************************************************************
 // All methods defined below
@@ -85,10 +96,41 @@
 }
 
 
+
+//the interrupt to update mouse state
+//run every 100 us
+void updateMouseState(){
+    
+    //move mouse
+    //handles only single finger actions
+    mouseCommand(0, (char) updatex[0], (char) updatey[0]);
+    
+    //clear out changes
+    updatex[0] = 0;
+    updatey[0] = 0;
+    
+    //click
+    if(toLeftClick){
+        //send command to 
+        mouseCommand(0x01, 0 , 0);
+        
+    } else if (toRightClick){
+        mouseCommand(0x02, 0 , 0);
+    }
+    
+    //fip clicking to false
+    toLeftClick = false;
+    toRightClick = false;
+    
+}
+
+
 //moves mouse on screen from one finger input
 //param
 // current point (currx, curry)
 // previous point (prevx, prevy)
+//TODO: implement additional param to indicate which finger you are looking at
+//      current implementation defaults to zero (finger one)
 void oneFingerResponse(int currx, int curry, int prevx, int prevy){
     //look at delta btwn prev val and current
     //TODO: moving average
@@ -113,8 +155,12 @@
             diffY = 0;
         }
         
-        //move x and y
-        mouseCommand(0, (char) diffX, (char) diffY);
+        
+        //mouseCommand(0, (char) diffX, (char) diffY);
+        //TODO: this is defaulting to first finger - need to fix this
+        //update target position to move x and y
+        updatex[0] = diffX;
+        updatey[0] = diffY;
     }
 }
 
@@ -190,7 +236,6 @@
         if(xStable && yStable){
             //both are stable
             fingerDownCount++;
-            //pc.printf("finger down \t");
             
         } else{
             //unstable, increase instability count
@@ -210,16 +255,22 @@
             //finger was lifted for long enough to indicate click
             if(fingerDownCount >= minRightClickDur){
                 //initiate right click
-                mouseCommand(0x02, 0 , 0);
+                //mouseCommand(0x02, 0 , 0);
+                
+                //indicate that you want to right click
+                toRightClick = true;
                 
                 //TODO: remove. for debugging purposes only
-                pc.printf("#########RIGHT mouse click \t");
+                //pc.printf("#########RIGHT mouse click \t");
             } else {
                 //initiate left click
-                mouseCommand(0x01, 0 , 0);
+                //mouseCommand(0x01, 0 , 0);
+                
+                //indicate that you want to left click
+                toLeftClick = true;
                 
                 //TODO: remove. for debugging purposes only
-                pc.printf("********LEFT mouse click \t");
+                //pc.printf("********LEFT mouse click \t");
             }
             
             //reset counters
@@ -331,6 +382,9 @@
     //update baud rate
     pc.baud(115200);
     
+    //attach ticker for interrupt
+    //mouseStateTicker.attach_us(&updateMouseState, 5000);
+    
     //loop to search for new info using the camera    
     while(1) {
         
@@ -343,8 +397,13 @@
         //get the camera data
         readCameraData();
         
+        //printing mouse state -- FOR DEBUGGING
+        pc.printf("update mouse %d, %d", updatex[0], updatey[0]);
+        pc.printf("\tclick left %s", toLeftClick ? "true" : "false");
+        pc.printf("\tclick right %s\n", toRightClick ? "true" : "false");
+        
         //print points
-        printCamData(onex, oney);  
+      //  printCamData(onex, oney);  
         
         //uncomment below to test infinite print
         //keyOut.putc(0x41);