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

Files at this revision

API Documentation at this revision

Comitter:
dglmgc
Date:
Thu Jun 09 01:22:12 2016 +0000
Parent:
0:a7df8e8cc00c
Commit message:
lab usb;

Changed in this revision

USBDevice.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r a7df8e8cc00c -r 2bdcfc75ee32 USBDevice.lib
--- a/USBDevice.lib	Mon Jun 24 23:23:47 2013 +0000
+++ b/USBDevice.lib	Thu Jun 09 01:22:12 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/USBDevice/#335f2506f422
+http://mbed.org/users/mbed_official/code/USBDevice/#01321bd6ff89
diff -r a7df8e8cc00c -r 2bdcfc75ee32 main.cpp
--- 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
diff -r a7df8e8cc00c -r 2bdcfc75ee32 mbed.bld
--- a/mbed.bld	Mon Jun 24 23:23:47 2013 +0000
+++ b/mbed.bld	Thu Jun 09 01:22:12 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34
\ No newline at end of file