From 05474e4bd2ff6a6ed5c99deddb0c96ff641f1bff Mon Sep 17 00:00:00 2001 From: hathach Date: Fri, 7 Mar 2014 13:05:43 +0700 Subject: [PATCH] refractor mouse app --- demos/device/src/main.c | 10 +++++----- demos/device/src/moused_app.c | 28 +++++++++++++++++++++------- demos/device/src/tusb_config.h | 4 ++-- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/demos/device/src/main.c b/demos/device/src/main.c index a69a710f1..890f6eea6 100644 --- a/demos/device/src/main.c +++ b/demos/device/src/main.c @@ -133,11 +133,11 @@ OSAL_TASK_FUNCTION( led_blinking_task ) (void* p_task_para) board_leds(led_on_mask, 1 - led_on_mask); led_on_mask = 1 - led_on_mask; // toggle - uint32_t btn_mask = board_buttons(); - for(uint8_t i=0; i<32; i++) - { - if ( BIT_TEST_(btn_mask, i) ) printf("button %d is pressed\n", i); - } +// uint32_t btn_mask = board_buttons(); +// for(uint8_t i=0; i<32; i++) +// { +// if ( BIT_TEST_(btn_mask, i) ) printf("button %d is pressed\n", i); +// } OSAL_TASK_LOOP_END } diff --git a/demos/device/src/moused_app.c b/demos/device/src/moused_app.c index dfce5a43c..b70b235e1 100644 --- a/demos/device/src/moused_app.c +++ b/demos/device/src/moused_app.c @@ -102,20 +102,34 @@ OSAL_TASK_FUNCTION( moused_app_task ) (void* p_task_para) { OSAL_TASK_LOOP_BEGIN - osal_task_delay(100); + osal_task_delay(10); if ( tusbd_is_configured(0) ) { - static uint32_t button_mask = 0; - - uint32_t new_button_mask = board_buttons(); + uint32_t button_mask = board_buttons(); //------------- button pressed -------------// - if ( (button_mask != new_button_mask) && !tusbd_hid_mouse_is_busy(0) ) + if ( !tusbd_hid_mouse_is_busy(0) ) { - button_mask = new_button_mask; + enum { + BUTTON_UP = 0, // map to button mask + BUTTON_DOWN = 1, + BUTTON_LEFT = 2, + BUTTON_RIGHT = 3, + BUTTON_CLICK_LEFT = 4, +// BUTTON_CLICK_RIGHT = 5, + MOUSE_RESOLUTION = 5 + }; - mouse_report.x = mouse_report.y = BIT_TEST_(button_mask, 0) ? 10 : 0; + memclr_(&mouse_report, sizeof(hid_mouse_report_t)); + + if ( BIT_TEST_(button_mask, BUTTON_UP) ) mouse_report.y = -MOUSE_RESOLUTION; + if ( BIT_TEST_(button_mask, BUTTON_DOWN) ) mouse_report.y = MOUSE_RESOLUTION; + + if ( BIT_TEST_(button_mask, BUTTON_LEFT) ) mouse_report.x = -MOUSE_RESOLUTION; + if ( BIT_TEST_(button_mask, BUTTON_RIGHT) ) mouse_report.x = MOUSE_RESOLUTION; + + if ( BIT_TEST_(button_mask, BUTTON_CLICK_LEFT) ) mouse_report.buttons = MOUSE_BUTTON_LEFT; tusbd_hid_mouse_send(0, &mouse_report ); } diff --git a/demos/device/src/tusb_config.h b/demos/device/src/tusb_config.h index bfc225351..c0a26ffd3 100644 --- a/demos/device/src/tusb_config.h +++ b/demos/device/src/tusb_config.h @@ -82,8 +82,8 @@ #define TUSB_CFG_DEVICE_FULLSPEED 1 // TODO refractor, remove //------------- CLASS -------------// -#define TUSB_CFG_DEVICE_HID_KEYBOARD 1 -#define TUSB_CFG_DEVICE_HID_MOUSE 0 +#define TUSB_CFG_DEVICE_HID_KEYBOARD 0 +#define TUSB_CFG_DEVICE_HID_MOUSE 1 #define TUSB_CFG_DEVICE_HID_GENERIC 0 #define TUSB_CFG_DEVICE_MSC 0 #define TUSB_CFG_DEVICE_CDC 0