Trackball based on the NXP LPC11U24 and the ADNS-9500
Dependencies: ADNS9500 USBDevice mbed 25LCxxx_SPI
Revision 2:72a8d2b11320, committed 2012-12-12
- Comitter:
- xxann5
- Date:
- Wed Dec 12 03:21:38 2012 +0000
- Parent:
- 1:34085d7e0991
- Child:
- 3:b57d3319dd97
- Commit message:
- added main.h and moved some things there. Cleaned up some code. Also added suport for left, middle and right mouse buttons, A Z button that turns the call into a scrolle wheel and an HR button that toggles the CPI value
Changed in this revision
--- a/ADNS9500.lib Sun Dec 09 05:34:22 2012 +0000 +++ b/ADNS9500.lib Wed Dec 12 03:21:38 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/xxann5/code/ADNS9500/#85ea51a56fdc +http://mbed.org/users/xxann5/code/ADNS9500/#de76a70defb3
--- a/USBDevice.lib Sun Dec 09 05:34:22 2012 +0000 +++ b/USBDevice.lib Wed Dec 12 03:21:38 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/xxann5/code/USBDevice/#8b528e323b30 +https://mbed.org/users/mbed_official/code/USBDevice/#d95e52d47216
--- a/main.cpp Sun Dec 09 05:34:22 2012 +0000 +++ b/main.cpp Wed Dec 12 03:21:38 2012 +0000 @@ -1,109 +1,114 @@ -#include "mbed.h" -#include "USBMouse.h" -#include <math.h> -#include <stdint.h> - -#define ADNS9500_SROM_91 - -#include "adns9500.hpp" - +#include "main.h" -DigitalOut led1(LED1); -DigitalOut led2(LED2); -DigitalOut led3(LED3); -DigitalOut led4(LED4); - -DigitalIn left(p18); -DigitalIn middle(p19); -DigitalIn right(p20); - -USBMouse mouse; - -//Ticker printData; +/* + * type, VID, PID, release + */ +USBMouse mouse( REL_MOUSE, 0x192f, 0x0000, 0x0001 ) ; /* * mosi miso sclk ncs FREQ, motion */ adns9500::ADNS9500 sensor(p5, p6, p7, p8, adns9500::MAX_SPI_FREQUENCY, p21); -bool motionTriggered = false; -//bool printDataTriggered = false; - -int motionCallbackCounter = 0; - -//void printDataCallback() -//{ -// printDataTriggered = true; -//} - void motionCallback() { - motionTriggered = true; - motionCallbackCounter++; + motion_triggered = true; +} + +void btn_hr_press(){ + high_rez_active = true; + sensor.setResolution( default_hirez_cpi ); +} +void btn_hr_release(){ + high_rez_active = false; + sensor.setResolution( default_motion_cpi ); +} + +void btn_z_press(){ + z_axis_active = true; + sensor.setResolution( default_z_cpi ); +} +void btn_z_release(){ + z_axis_active = false; + sensor.setResolution( default_motion_cpi ); } +void btn_l_press(){ + mouse.press(MOUSE_LEFT); +} +void btn_l_release(){ + mouse.release(MOUSE_LEFT); +} + +void btn_m_press(){ + mouse.press(MOUSE_MIDDLE); +} +void btn_m_release(){ + mouse.release(MOUSE_MIDDLE); +} + +void btn_r_press(){ + mouse.press(MOUSE_RIGHT); +} +void btn_r_release(){ + mouse.release(MOUSE_RIGHT); +} int main(void) { - int dataReadCounter = 0; - float totalMotionDx = 0.0; - float totalMotionDy = 0.0; + + btn_hr.rise(&btn_hr_press); + btn_hr.fall(&btn_hr_release); + + btn_z.rise(&btn_z_press); + btn_z.fall(&btn_z_release); - printf("attach.\r\n"); + btn_l.rise(&btn_l_press); + btn_l.fall(&btn_l_release); + + btn_m.rise(&btn_m_press); + btn_m.fall(&btn_m_release); + + btn_r.rise(&btn_r_press); + btn_r.fall(&btn_r_release); + + int dx, dy; + sensor.attach(&motionCallback); - printf("reset\r\n"); sensor.reset(); - printf("srom downlaod\r\n"); uint16_t crc = sensor.sromDownload(adns9500FWArray, (uint16_t)ADNS9500_FIRMWARE_LEN ); - - printf( "CRC [%x] [%x].\r\n", (uint16_t)ADNS6010_FIRMWARE_CRC, crc ); - + if( (uint16_t)ADNS6010_FIRMWARE_CRC != crc ) { - printf( "CRC does not match: [%x] [%x].\r\n", (uint16_t)ADNS6010_FIRMWARE_CRC, crc ); - error( "Exiting.\r\n" ); + error( "CRC does not match: [%x] [%x], Exiting.\r\n", (uint16_t)ADNS6010_FIRMWARE_CRC, crc ); } - printf("Enable lazer\r\n"); - sensor.getLaser(); - wait(3); + sensor.enableLaser(); - sensor.getLaser(); + + sensor.setResolution( default_motion_cpi ); while (true) { - if( left ){ - mouse.click( 0 ); - led2 = !led2; - } - if( middle ){ - mouse.click( 1 ); - led2 = !led3; - } - if( ! right ){ - mouse.click( 2 ); - led2 = !led4; - } - - int dx, dy; - if (motionTriggered) { + if (motion_triggered) { led1 = !led1; - motionTriggered = false; + motion_triggered = false; sensor.getMotionDelta(dx, dy); - totalMotionDx += dx; - totalMotionDy += dy; - - dataReadCounter++; - - mouse.move( dx, - dy ); - //printf( "X: %d Y: %d\r\n", dx, dy); + /* + * The sensor does not know its upside down and backwords + * so we are helping it out with the y axis. + */ + if( z_axis_active ){ + mouse.scroll( - dy ); + } + else{ + mouse.move( dx, - dy ); + } } - - //wait(0.5); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Wed Dec 12 03:21:38 2012 +0000 @@ -0,0 +1,29 @@ +#include "mbed.h" +#include "USBMouse.h" +#include <math.h> +#include <stdint.h> + +#define ADNS9500_SROM_91 + +#define DEBUG + +#include "adns9500.hpp" + +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +InterruptIn btn_hr(p16); +InterruptIn btn_z(p17); +InterruptIn btn_l(p18); +InterruptIn btn_m(p19); +InterruptIn btn_r(p20); + +bool motion_triggered = false; +bool z_axis_active = false; +bool high_rez_active = false; + +int default_motion_cpi = 1080; +int default_z_cpi = 90; +int default_hirez_cpi = 180; \ No newline at end of file