refractor mouse app

This commit is contained in:
hathach 2014-03-07 13:05:43 +07:00
parent 3d17212f29
commit 05474e4bd2
3 changed files with 28 additions and 14 deletions

View File

@ -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
}

View File

@ -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 );
}

View File

@ -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