Ghost Mouse / Mbed 2 deprecated ghost_mouse

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jennabarton
Date:
Mon Apr 10 20:46:08 2017 +0000
Parent:
19:0dd0fe82c3e7
Child:
21:a23f87a688b2
Commit message:
slow with some clicking

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Apr 05 02:43:57 2017 +0000
+++ b/main.cpp	Mon Apr 10 20:46:08 2017 +0000
@@ -54,16 +54,29 @@
 int mouseMoveMult = 1;
 
 //counts for clicks
-int clickDeadzone = 10;
+int clickDeadzone = 15;
 int fingerDownCount = 0;
 int fingerUpCount = 0;
-int minLeftClickDur = 4;
+int minLeftClickDur = 10;
 int minRightClickDur = 10;
-int delayForClick = 2;
-int instabilityLimit = 3;
+int delayForClick = 3;
+int instabilityLimit = 2;
 int instabilityCount = 0;
 
 
+
+//tracking info for click 
+bool readyForClick = false;
+bool readingClick = false;
+bool readyForClickRelease = false;
+int preClickDelayMin = 0;
+int preClickDelayMax = 100000;
+int preClickDelayCount = 0;
+
+int returnForClickX = 1023;
+int returnForClickY = 1023;
+
+
 //MOUSE STATE
 //implemented for ticker behavior
 //ticker depends on these values to update the state/location of the mouse
@@ -119,7 +132,6 @@
     
     //move mouse
     //handles only single finger actions
-    //TODO: uncomment
     mouseCommand(0, updatex[0], updatey[0]);
     
     //clear out changes
@@ -187,7 +199,7 @@
 //        pc.printf("updating x to : %d", updatex[0]);
 //        pc.printf("\t updating y to : %d \n", updatex[0]);
         
-    }
+    } 
 }
 
 
@@ -222,9 +234,41 @@
 void updateClickState(int currx, int curry, int prevx, int prevy){
     bool xStable = false;
     bool yStable = false; 
+    
+    //TODO: Do these need to be stable?
+    if(currx != 1023 && curry != 1023 && !readingClick){
+        //finger is down on the surface and you are not registering a click
+        readyForClick = true;
+        returnForClickX = currx;
+        returnForClickY = curry;
 
-    //TODO: update to handle cases where just one is 1023
-    if(currx != 1023 || curry != 1023){
+    } else if (currx == 1023 && curry == 1023 && readyForClick){
+        //finger is off of surface but had been on surface previously
+        //you can start looking to call a click now
+        
+        
+        readyForClick = false;
+        readingClick = true;
+        
+//        //increment count that tracks how long you have been delaying
+//        preClickDelayCount = preClickDelayCount + 1;
+//        
+//        if(preClickDelayCount > preClickDelayMax){
+//            //too much time has passed for a click
+//            readyForClick = false;
+//            readingClick = true;
+//            preClickDelayCount = 0;
+//        } else if(preClickDelayCount > preClickDelayMin){
+//            readyForClick = false;
+//            readingClick = false;
+//            preClickDelayCount = 0;
+//        }
+        
+        
+    } else if(currx != 1023 && curry != 1023 && readingClick){
+        //TODO: update to handle cases where just one is 1023
+        
+        //if finger is on plane and you can click, check if it is stable
         //check x stability 
         if( currx > prevx ){
             if(currx-prevx < clickDeadzone){
@@ -247,7 +291,7 @@
                 //barely moved in y dir
                 yStable = true;                 
             } 
-        } else if( curry < prevy) {
+        } else if( curry < prevy) 
             if(prevy-curry < clickDeadzone){
                 //barely moved in y dir
                 yStable = true;
@@ -266,37 +310,60 @@
             //unstable, increase instability count
             instabilityCount++;
             if(instabilityCount > instabilityLimit){
-                //too many instable points, reset to zero
+                //too many unstable points, reset to zero
                 fingerDownCount = 0;
                 instabilityCount = 0;
+                readingClick = false;
             }
         }
         
-    } else {
+        //if finger has been down and stable long enough to be a click
+        //set state to ready to get click release
+        if(fingerDownCount >= minLeftClickDur){
+            //let system know click can be released
+            readyForClickRelease = true;
+            readingClick = false;
+        }
+        
+        
+    } else if(currx == 1023 && curry == 1023 && readyForClickRelease) {
         //both are up, increment up count
         fingerUpCount++;
-        if(fingerUpCount >= delayForClick && fingerDownCount >= minLeftClickDur){
-            //finger was down for long enough to be a click
+        if(fingerUpCount >= delayForClick){
             //finger was lifted for long enough to indicate click
-            if(fingerDownCount >= minRightClickDur){
-                //initiate right click
-                //mouseCommand(0x02, 0 , 0);
-                
-                //indicate that you want to right click
-                toRightClick = true;
+            
+            //indicate that you want to left click
+            toLeftClick = true;
                 
-                //TODO: remove. for debugging purposes only
-                pc.printf("#########RIGHT mouse click \t");
-            } else {
-                //initiate left click
-                //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");
-            }
+            //TODO: remove. for debugging purposes only
+            pc.printf("********LEFT mouse click \n");
+            
+            readingClick = false;
+            readyForClick = false;
+            readyForClickRelease = false;
+            
+            
+//>>>>>>>>>>>>> begin code for left-right diff
+ //           if(fingerDownCount >= minRightClickDur){
+//                //initiate right click
+//                //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");
+//            } else {
+//                //initiate left click
+//                //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");
+//            }
+//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< end code for left-right diff
             
             //reset counters
             fingerUpCount = 0;
@@ -348,32 +415,34 @@
     
     //<<<<<<<<<<<<<<<<End unfinished code for moving averages
     
-    //POINT 2
-    //get data
-    point2x = data_buf[4];
-    point2y = data_buf[5];
-    s = data_buf[6];
-    //load x,y
-    onex[1] = point2x + ((s & 0x30) << 4);
-    oney[1] = point2y + ((s & 0xC0) << 2);
-      
-    //POINT 3
-    //get data
-    point3x = data_buf[7];
-    point3y = data_buf[8];
-    s = data_buf[9];
-    //load x,y
-    onex[2] = point3x + ((s & 0x30) << 4);
-    oney[2] = point3y + ((s & 0xC0) << 2);
-    
-    //POINT 4
-    //get data
-    point4x = data_buf[10];
-    point4y = data_buf[11];
-    s = data_buf[12];
-    //load x,y
-    onex[3] = point4x + ((s & 0x30) << 4);
-    oney[3] = point4y + ((s & 0xC0) << 2);
+    //>>>>>>>>>>>>>>>>Begin unused parsing for multiple fingers
+ //   //POINT 2
+//    //get data
+//    point2x = data_buf[4];
+//    point2y = data_buf[5];
+//    s = data_buf[6];
+//    //load x,y
+//    onex[1] = point2x + ((s & 0x30) << 4);
+//    oney[1] = point2y + ((s & 0xC0) << 2);
+//      
+//    //POINT 3
+//    //get data
+//    point3x = data_buf[7];
+//    point3y = data_buf[8];
+//    s = data_buf[9];
+//    //load x,y
+//    onex[2] = point3x + ((s & 0x30) << 4);
+//    oney[2] = point3y + ((s & 0xC0) << 2);
+//    
+//    //POINT 4
+//    //get data
+//    point4x = data_buf[10];
+//    point4y = data_buf[11];
+//    s = data_buf[12];
+//    //load x,y
+//    onex[3] = point4x + ((s & 0x30) << 4);
+//    oney[3] = point4y + ((s & 0xC0) << 2);
+    //<<<<<<<<<<<<<<<<<<<<<<End unused parsing for multiple fingers
     
 }
 
@@ -435,6 +504,14 @@
         //get the camera data
         readCameraData();
         
+        //printing clicking state -- FOR DEBUGGING
+//        pc.printf("readyForClick %s", readyForClick ? "true" : "false");
+//        pc.printf("\treadingClick %s", readingClick ? "true" : "false");        
+//        pc.printf("\treadyForClickRelease %s\n", readyForClickRelease ? "true" : "false");        
+        
+        
+        
+        
         //printing mouse state -- FOR DEBUGGING
 //        pc.printf("update mouse %d, %d", updatex[0], updatey[0]);
 //        pc.printf("\tclick left %s", toLeftClick ? "true" : "false");