summaryrefslogtreecommitdiff
path: root/examples/device
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-07-25 12:13:40 +0700
committerhathach <[email protected]>2018-07-25 12:13:40 +0700
commitc5a41ac9d8d899be40c1234fcecf325423d720cf (patch)
treea490cea2c54856fb04d626636124693f6f3a7066 /examples/device
parent71934228d2902079da0c0dc65d97cc78f1b1eaab (diff)
enable both mouse & keyboard example
Diffstat (limited to 'examples/device')
-rw-r--r--examples/device/nrf52840/src/main.c66
1 files changed, 29 insertions, 37 deletions
diff --git a/examples/device/nrf52840/src/main.c b/examples/device/nrf52840/src/main.c
index 84876e7a5..5ece8bf96 100644
--- a/examples/device/nrf52840/src/main.c
+++ b/examples/device/nrf52840/src/main.c
@@ -102,51 +102,43 @@ void virtual_com_task(void)
//--------------------------------------------------------------------+
void usb_hid_task(void)
{
- /*------------- Keyboard -------------*/
-// if ( tud_hid_keyboard_ready() )
-// {
-// // 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();
-//
-// if ( btn )
-// {
-// uint8_t keycode[6] = { 0 };
-//
-// for(uint8_t i=0; i < 6; i++)
-// {
-// 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);
-// }
-// }
+ // 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);
- /*------------- Mouse -------------*/
- if ( tud_hid_mouse_ready() )
- {
- // Poll every 10ms
- static tu_timeout_t tm = { .start = 0, .interval = 10 };
+ uint32_t const btn = board_buttons();
- if ( !tu_timeout_expired(&tm) ) return; // not enough time
- tu_timeout_reset(&tm);
+ /*------------- Keyboard -------------*/
+ if ( tud_hid_keyboard_ready() )
+ {
+ if ( btn )
+ {
+ uint8_t keycode[6] = { 0 };
- uint32_t const btn = board_buttons();
+ for(uint8_t i=0; i < 6; i++)
+ {
+ if ( btn & (1 << i) ) keycode[i] = HID_KEY_A + i;
+ }
- if ( btn )
+ tud_hid_keyboard_keycode(0, keycode);
+ }else
{
- tud_hid_mouse_data(0, 10, 0, 0, 0);
+ // Null means all zeroes keycodes
+ tud_hid_keyboard_keycode(0, NULL);
}
}
+
+
+ /*------------- Mouse -------------*/
+ if ( tud_hid_mouse_ready() )
+ {
+ if ( btn & 0x01 ) tud_hid_mouse_move(-10, 0 ); // left
+ else if( btn & 0x02 ) tud_hid_mouse_move( 10, 0 ); // right
+ else if( btn & 0x04 ) tud_hid_mouse_move( 0, -10); // up
+ else if( btn & 0x08 ) tud_hid_mouse_move( 0, 10); // down
+ }
}