Ghost Mouse / Mbed 2 deprecated ghost_mouse

Dependencies:   mbed

Revision:
21:a23f87a688b2
Parent:
20:550a57fb9344
Child:
22:99ff69f7111a
--- a/main.cpp	Mon Apr 10 20:46:08 2017 +0000
+++ b/main.cpp	Wed Apr 12 21:04:40 2017 +0000
@@ -1,5 +1,6 @@
 #include "mbed.h"
 #include <RawSerial.h>
+//#include <math.h>
 
 //******************************************************************
 // All variables defined below
@@ -50,8 +51,9 @@
 int prevy[4];
 
 //movement
-int deadzone = 1;
-int mouseMoveMult = 1;
+const int deadzone = 1;
+const int mouseMoveMult = 3;
+const double mouseMovePwr = 1.3;
 
 //counts for clicks
 int clickDeadzone = 15;
@@ -86,6 +88,12 @@
 bool toLeftClick = false;
 bool toRightClick = false;
 
+
+
+//READING FROM CAMERA VIA INTERRUPT
+Ticker cameraReadTicker;
+
+
 //LED
 DigitalOut myled2(LED2);
 
@@ -99,11 +107,12 @@
 //also can indicate whether you want to "click"
 //NOTE: hard coded wait of 0.1
 void mouseCommand(char buttons, short x, short y) {
-  x = mouseMoveMult*x;
-  x = x*abs(x);
+  
+  x = (x > 0) ? pow(mouseMoveMult*x, mouseMovePwr) : -pow(-mouseMoveMult*x, mouseMovePwr);
+  //x = x*abs(x);
   //x = x*sqrt((float)abs(x));
-  y = mouseMoveMult*y;
-  y = y*abs(y);
+  y = (y > 0) ? pow(mouseMoveMult*y, mouseMovePwr) : -pow(-mouseMoveMult*y, mouseMovePwr);
+  //y = y*abs(y);
   //y = y*sqrt((float)abs(y));
   
   keyOut.putc(0xFD);
@@ -291,7 +300,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;
@@ -471,6 +480,9 @@
 //entrance to the code
 int main() {
     
+    //i2c increase
+    camera1.frequency(400000);
+    
     //set values initially to zero
     updatex[0] = 0;
     updatey[0] = 0;
@@ -487,7 +499,10 @@
     
     //attach ticker for interrupt
     //mouseStateTicker.attach_us(&updateMouseState, 100);
-    mouseStateTicker.attach(&updateMouseState, 0.01);
+    mouseStateTicker.attach(&updateMouseState, 0.05);
+    
+    //attach ticker for reading camera interrupt
+    cameraReadTicker.attach(&readCameraData, 0.01);
     
     
     //loop to search for new info using the camera    
@@ -500,9 +515,9 @@
         
         //pc.printf("while2\n");
         
-        
+        //DEPRECATED: now interrupt
         //get the camera data
-        readCameraData();
+        //readCameraData();
         
         //printing clicking state -- FOR DEBUGGING
 //        pc.printf("readyForClick %s", readyForClick ? "true" : "false");
@@ -520,9 +535,13 @@
         //print points
         printCamData(onex, oney);  
         
+        
+        
+        
+        
+        
         //uncomment below to test infinite print
         //keyOut.putc(0x41);
-
         
         //uncomment below to infinitely move mouse in a square
 //        double delay = 0.1;