Test application for Freedom KL25Z, mouse driven by accelerometer and click with TSI interface

Dependencies:   MMA8451Q TSI USBDevice mbed

Fork of Airmouse by Frederic Thierry

Revision:
1:2bdcfc75ee32
Parent:
0:a7df8e8cc00c
--- a/main.cpp	Mon Jun 24 23:23:47 2013 +0000
+++ b/main.cpp	Thu Jun 09 01:22:12 2016 +0000
@@ -1,16 +1,17 @@
 #include "mbed.h"
-#include "USBMouse.h"
+#include "USBKeyboard.h"
 #include "MMA8451Q.h"
 #include "TSISensor.h"
 
 #define MMA8451_I2C_ADDRESS (0x1d<<1)
 
-USBMouse mouse;
+USBKeyboard teclado;
 Serial pc(USBTX, USBRX); // tx, rx
 
 int main()
 {
     float click =0;
+    float clickant = 0;
     int16_t x = 0;
     int16_t y = 0;
     TSISensor tsi;
@@ -19,23 +20,104 @@
     while (1) {
         x = -10*acc.getAccY();
         y = 10*acc.getAccX();
-
-        mouse.move(x, y);
     
         click=tsi.readPercentage();
         //pc.printf("%f\n",click);
-        if (click>0.70)
-            mouse.press(MOUSE_LEFT);
-            else
-            mouse.release(MOUSE_LEFT);
-            
-          if((click<0.30)&&(click>0))
-            
-            mouse.press(MOUSE_RIGHT);
-            else
-            mouse.release(MOUSE_RIGHT);
-            
+        if(click < (clickant - 0.10) || click > (clickant + 0.10)) {
+            if(x>0 && y > 0){                
+                if (click>0.80)
+                    teclado._putc(99);
+                    
+                if((click<0.30)&&(click>0))
+                    teclado._putc(97);
+                    
+                if((click<0.80)&&(click>0.30))
+                    teclado._putc(98);
+            }
+            if(x<0 && y > 0){                
+                if (click>0.80)
+                    teclado._putc(102);
+                    
+                if((click<0.30)&&(click>0))
+                    teclado._putc(100);
+                    
+                if((click<0.80)&&(click>0.30))
+                    teclado._putc(101);
+            }
+            if(x<0 && y < 0){                
+                if (click>0.80)
+                    teclado._putc(105);
+                    
+                if((click<0.30)&&(click>0))
+                    teclado._putc(103);
+                    
+                if((click<0.80)&&(click>0.30))
+                    teclado._putc(104);
+            }
+            if(x>0 && y < 0){                
+                if (click>0.80)
+                    teclado._putc(108);
+                    
+                if((click<0.30)&&(click>0))
+                    teclado._putc(106);
+                    
+                if((click<0.80)&&(click>0.30))
+                    teclado._putc(107);
+            }
+            if(x==0 && y < 0){                
+                if (click>0.80)
+                    teclado._putc(111);
+                    
+                if((click<0.30)&&(click>0))
+                    teclado._putc(109);
+                    
+                if((click<0.80)&&(click>0.30))
+                    teclado._putc(110);
+            }
+            if(x==0 && y > 0){                
+                if (click>0.80)
+                    teclado._putc(114);
+                    
+                if((click<0.30)&&(click>0))
+                    teclado._putc(112);
+                    
+                if((click<0.80)&&(click>0.30))
+                    teclado._putc(113);
+            }
+            if(x==0 && y == 0){                
+                if (click>0.80)
+                    teclado._putc(117);
+                    
+                if((click<0.30)&&(click>0))
+                    teclado._putc(115);
+                    
+                if((click<0.80)&&(click>0.30))
+                    teclado._putc(116);
+            }
+            if(x>0 && y == 0){                
+                if (click>0.80)
+                    teclado._putc(120);
+                    
+                if((click<0.30)&&(click>0))
+                    teclado._putc(118);
+                    
+                if((click<0.80)&&(click>0.30))
+                    teclado._putc(119);
+            }
+            if(x<0 && y == 0){                
+                if (click>0.80)
+                    teclado._putc(123);
+                    
+                if((click<0.30)&&(click>0))
+                    teclado._putc(121);
+                    
+                if((click<0.80)&&(click>0.30))
+                    teclado._putc(122);
+            }
+        }
+        
         wait(0.001);
+        clickant = click;
        
     }
 }
\ No newline at end of file