Trackball based on the NXP LPC11U24 and the ADNS-9500
Dependencies: ADNS9500 USBDevice mbed 25LCxxx_SPI
main.cpp
- Committer:
- xxann5
- Date:
- 2012-12-09
- Revision:
- 1:34085d7e0991
- Parent:
- 0:eb8c05a5b8a7
- Child:
- 2:72a8d2b11320
File content as of revision 1:34085d7e0991:
#include "mbed.h" #include "USBMouse.h" #include <math.h> #include <stdint.h> #define ADNS9500_SROM_91 #include "adns9500.hpp" 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; /* * 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++; } int main(void) { int dataReadCounter = 0; float totalMotionDx = 0.0; float totalMotionDy = 0.0; printf("attach.\r\n"); 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" ); } printf("Enable lazer\r\n"); sensor.getLaser(); wait(3); sensor.enableLaser(); sensor.getLaser(); 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) { led1 = !led1; motionTriggered = false; sensor.getMotionDelta(dx, dy); totalMotionDx += dx; totalMotionDy += dy; dataReadCounter++; mouse.move( dx, - dy ); //printf( "X: %d Y: %d\r\n", dx, dy); } //wait(0.5); } }