USB mouse example for KL25 Freedom board.
Dependencies: MMA8451Q TSI USBDevice mbed
Revision 0:fa851c29384b, committed 2013-07-30
- Comitter:
- PavelM
- Date:
- Tue Jul 30 12:26:10 2013 +0000
- Commit message:
- Beta version of USB mouse for FRDMkl25.
Changed in this revision
diff -r 000000000000 -r fa851c29384b MMA8451Q.lib --- /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
diff -r 000000000000 -r fa851c29384b TSI.lib --- /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
diff -r 000000000000 -r fa851c29384b USBDevice.lib --- /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
diff -r 000000000000 -r fa851c29384b main.cpp --- /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); + } +} +
diff -r 000000000000 -r fa851c29384b mbed.bld --- /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