Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADNS9500 USBDevice mbed 25LCxxx_SPI
Revision 5:c7056267daa7, committed 2012-12-16
- Comitter:
- xxann5
- Date:
- Sun Dec 16 18:38:20 2012 +0000
- Parent:
- 4:ba169f98e9be
- Child:
- 6:4cb2c9a3abcd
- Commit message:
- Started fooling around with sending HID reports to configure the mouse with. things such as default CPI.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Thu Dec 13 03:10:46 2012 +0000
+++ b/main.cpp Sun Dec 16 18:38:20 2012 +0000
@@ -3,8 +3,13 @@
/*
* type, VID, PID, release
*/
+
USBMouse mouse( REL_MOUSE, 0x192f, 0x0000, 0x0001 ) ;
+//We declare a USBHID device. By default input and output reports are 64 bytes long.
+USBHID hid(8, 8);
+
+
/*
* mosi miso sclk ncs FREQ, motion
*/
@@ -37,27 +42,45 @@
mouse.press(MOUSE_LEFT);
}
void btn_l_release(){
- mouse.release(MOUSE_LEFT);
+ //mouse.release(MOUSE_LEFT);
}
void btn_m_press(){
- mouse.press(MOUSE_MIDDLE);
+ //mouse.press(MOUSE_MIDDLE);
}
void btn_m_release(){
- mouse.release(MOUSE_MIDDLE);
+ //mouse.release(MOUSE_MIDDLE);
}
void btn_r_press(){
- mouse.press(MOUSE_RIGHT);
+ //mouse.press(MOUSE_RIGHT);
}
void btn_r_release(){
- mouse.release(MOUSE_RIGHT);
+ //mouse.release(MOUSE_RIGHT);
}
-
+void set( uint8_t attrib, uint8_t *val ){
+ switch (attrib){
+ case CHAT_MOTION_DEFAULT_CPI:
+ default_motion_cpi = *val;
+ break;
+ case CHAT_Z_DEFAULT_CPI:
+ default_z_cpi = *val;
+ break;
+ default:
+ // FIXME: error handling.
+ printf("crap\r\n");
+ }
+}
+
+void get( uint8_t attrib ){
+}
+
int main(void)
{
+ send_rep.length = 8;
+
btn_hr.rise(&btn_hr_press);
btn_hr.fall(&btn_hr_release);
@@ -92,6 +115,22 @@
while (true)
{
+ //try to read a msg
+ if(hid.readNB(&recv_rep)) {
+ led4 = !led4;
+ switch (recv_rep.data[0]){
+ case CHAT_SET:
+ set(recv_rep.data[1],&recv_rep.data[2]);
+ break;
+ case CHAT_GET:
+ get(recv_rep.data[1]);
+ break;
+ default:
+ // FIXME: error handling.
+ printf("crap\r\n");
+ }
+ }
+
if (motion_triggered) {
led1 = !led1;
motion_triggered = false;
@@ -103,10 +142,10 @@
* so we are helping it out with the y axis.
*/
if( z_axis_active ){
- mouse.scroll( - dy );
+ //////mouse.scroll( - dy );
}
else{
- mouse.move( dx, - dy );
+ //////mouse.move( dx, - dy );
}
}
}
--- a/main.h Thu Dec 13 03:10:46 2012 +0000 +++ b/main.h Sun Dec 16 18:38:20 2012 +0000 @@ -1,30 +1,61 @@ -#include "mbed.h" -#include "USBMouse.h" -#include <math.h> -#include <stdint.h> - -#define ADNS9500_SROM_91 - -#define DEBUG - -#include "adns9500.hpp" -#include "Ser25lcxxx.h" - -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 +#include "mbed.h" +#include "USBHID.h" +#include "USBMouse.h" +#include <math.h> +#include <stdint.h> + +#define ADNS9500_SROM_91 + +#define DEBUG + +#include "adns9500.hpp" +#include "Ser25lcxxx.h" + +#define CHAT_SET 0x01 +#define CHAT_GET 0x02 + +#define CHAT_MOTION_DEFAULT_CPI 0x01 +#define CHAT_MOTION_MAX_CPI 0x02 +#define CHAT_MOTION_MIN_CPI 0x03 +#define CHAT_MOTION_STEP_CPI 0x04 +#define CHAT_Z_DEFAULT_CPI 0x05 +#define CHAT_HR_DEFAULT_CPI 0x06 + +#define CHAT_VID 0x07 +#define CHAT_PID 0x08 + +#define CHAT_ADNS_SROM 0x09 + +#define CHAT_LED_BEHAVIOR 0x0a + + + +//This report will contain data to be sent +HID_REPORT send_rep; +HID_REPORT recv_rep; + +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; + + + + + +void set( uint8_t attrib, uint8_t *val ); +void get( uint8_t attrib); \ No newline at end of file