enable both mouse & keyboard example

This commit is contained in:
hathach 2018-07-25 12:13:40 +07:00
parent 71934228d2
commit c5a41ac9d8
1 changed files with 30 additions and 38 deletions

View File

@ -102,50 +102,42 @@ void virtual_com_task(void)
//--------------------------------------------------------------------+ //--------------------------------------------------------------------+
void usb_hid_task(void) void usb_hid_task(void)
{ {
// Poll every 10ms
static tu_timeout_t tm = { .start = 0, .interval = 10 };
if ( !tu_timeout_expired(&tm) ) return; // not enough time
tu_timeout_reset(&tm);
uint32_t const btn = board_buttons();
/*------------- Keyboard -------------*/ /*------------- Keyboard -------------*/
// if ( tud_hid_keyboard_ready() ) if ( tud_hid_keyboard_ready() )
// { {
// // Poll every 10ms if ( btn )
// static tu_timeout_t tm = { .start = 0, .interval = 10 }; {
// uint8_t keycode[6] = { 0 };
// if ( !tu_timeout_expired(&tm) ) return; // not enough time
// tu_timeout_reset(&tm); for(uint8_t i=0; i < 6; i++)
// {
// uint32_t const btn = board_buttons(); if ( btn & (1 << i) ) keycode[i] = HID_KEY_A + i;
// }
// if ( btn )
// { tud_hid_keyboard_keycode(0, keycode);
// uint8_t keycode[6] = { 0 }; }else
// {
// for(uint8_t i=0; i < 6; i++) // Null means all zeroes keycodes
// { tud_hid_keyboard_keycode(0, NULL);
// if ( btn & (1 << i) ) keycode[i] = HID_KEY_A + i; }
// } }
//
// tud_hid_keyboard_keycode(0, keycode);
// }else
// {
// // Null means all zeroes keycodes
// tud_hid_keyboard_keycode(0, NULL);
// }
// }
/*------------- Mouse -------------*/ /*------------- Mouse -------------*/
if ( tud_hid_mouse_ready() ) if ( tud_hid_mouse_ready() )
{ {
// Poll every 10ms if ( btn & 0x01 ) tud_hid_mouse_move(-10, 0 ); // left
static tu_timeout_t tm = { .start = 0, .interval = 10 }; else if( btn & 0x02 ) tud_hid_mouse_move( 10, 0 ); // right
else if( btn & 0x04 ) tud_hid_mouse_move( 0, -10); // up
if ( !tu_timeout_expired(&tm) ) return; // not enough time else if( btn & 0x08 ) tud_hid_mouse_move( 0, 10); // down
tu_timeout_reset(&tm);
uint32_t const btn = board_buttons();
if ( btn )
{
tud_hid_mouse_data(0, 10, 0, 0, 0);
}
} }
} }