USB mouse example for KL25 Freedom board.

Dependencies:   MMA8451Q TSI USBDevice mbed

Files at this revision

API Documentation at this revision

Comitter:
PavelM
Date:
Tue Jul 30 12:26:10 2013 +0000
Commit message:
Beta version of USB mouse for FRDMkl25.

Changed in this revision

MMA8451Q.lib Show annotated file Show diff for this revision Revisions of this file
TSI.lib Show annotated file Show diff for this revision Revisions of this file
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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MMA8451Q.lib	Tue Jul 30 12:26:10 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/JoKer/code/MMA8451Q/#2d14600116fc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TSI.lib	Tue Jul 30 12:26:10 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/vsluiter/code/TSI/#4dc2f5a3a731
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Tue Jul 30 12:26:10 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#1e3d126a322b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jul 30 12:26:10 2013 +0000
@@ -0,0 +1,107 @@
+#include "mbed.h"
+#include "MMA8451Q.h"
+#include "USBMouse.h"
+#include "TSISensor.h"
+ 
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+#define DEBUGCONSOLE 1  /* 9600bd serial to OpenSWD COM port */
+
+USBMouse mouse;
+Serial pc(USBTX,USBRX);
+ 
+void mbutton_detect( float percent)
+{
+    #define LBTN_MIN    75
+    #define LBTN_MAX    100
+    #define RBTN_MIN    1
+    #define RBTN_MAX    30
+    #define DBL_MIN     35
+    #define DBL_MAX     70
+    
+    int pos = percent * 100;
+    static bool ltouchflg = false;
+    static bool rtouchflg = false;
+
+    /* left button */
+    if((pos >= DBL_MIN))   
+    {
+        if( ltouchflg == false ) 
+        {
+            mouse.press(MOUSE_LEFT);
+            ltouchflg = true;
+#if DEBUGCONSOLE            
+            pc.printf("ltouch \n");
+#endif            
+        }
+    }
+    
+    /* right button */
+    if((pos <= DBL_MAX) && (pos > RBTN_MIN))   
+    {
+        if( rtouchflg == false ) 
+        {
+            mouse.press(MOUSE_RIGHT);
+            rtouchflg = true;
+#if DEBUGCONSOLE              
+            pc.printf("rtouch \n");
+#endif            
+        }
+    }
+    
+    /* release left */
+    if( (pos < DBL_MIN))
+    {
+        if( ltouchflg == true )
+        {
+            mouse.release(MOUSE_LEFT);
+            ltouchflg = false;
+#if DEBUGCONSOLE              
+            pc.printf("lrelease \n");
+#endif            
+        }
+    } 
+    
+    /* release right */
+    if( (pos < RBTN_MIN) || (pos >= DBL_MAX) )
+    {
+        if( rtouchflg == true )
+        {
+            mouse.release(MOUSE_RIGHT);
+            rtouchflg = false;
+#if DEBUGCONSOLE              
+            pc.printf("rrelease \n");
+#endif            
+        }
+    }
+}
+ 
+ 
+int main(void) {
+ 
+    /* acc sensor init */
+    MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS);
+    
+    /* TSI init */
+    TSISensor tsi;
+    
+    /* LED init */
+    PwmOut rled(LED_RED);
+    PwmOut gled(LED_GREEN);
+    PwmOut bled(LED_BLUE);
+ 
+    while (true) { 
+    
+        /* -1*accY correspond to mouse axe X; acc X correspond to mouse Y */
+        mouse.move( -1*int(acc.getAccY()*20), int(acc.getAccX()*20) );
+        
+        mbutton_detect( tsi.readPercentage());
+      
+        rled = 1.0 - abs(acc.getAccX());
+        gled = 1.0 - abs(acc.getAccY());
+        bled = 1.0 - abs(acc.getAccZ());
+        
+        wait(0.001);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jul 30 12:26:10 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/b3110cd2dd17
\ No newline at end of file