@@ -240,10 +240,9 @@ tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol) {
240240 (1<<REPORT_ID_KEYBOARD) | (1<<REPORT_ID_MOUSE) | \
241241 (1<<REPORT_ID_CONSUMER_CONTROL) | (1<<REPORT_ID_RAWHID) )
242242
243- static uint8_t prev_keyboard_keycodes [6 ] = {0 , 0 , 0 , 0 , 0 , 0 };
244243static uint8_t input_updated_bitmap = 0 ;
245244static uint8_t keyboard_modifier = 0 ;
246- static uint8_t * keyboard_keycodes = NULL ;
245+ static uint8_t keyboard_keycodes [ 6 ] = { 0 , 0 , 0 , 0 , 0 , 0 } ;
247246static uint16_t consumer_keycode = 0 ;
248247static uint32_t joystick_buttons = 0 ;
249248static uint8_t joystick_hat = 0 ;
@@ -266,8 +265,6 @@ send_hid_report()
266265
267266 for (uint8_t i = 1 ;i < 6 ;i ++ ) {
268267 if (input_updated_bitmap & (1 <<i ) ) {
269- input_updated_bitmap &= ~(1 <<i );
270-
271268 switch (i )
272269 {
273270 case REPORT_ID_KEYBOARD : {
@@ -306,6 +303,7 @@ tud_hid_report_complete_cb(uint8_t instance, uint8_t const* report, uint8_t len)
306303 (void ) instance ;
307304 (void ) len ;
308305
306+ input_updated_bitmap &= ~(1 <<report [0 ]); // report[0] is report ID
309307 send_hid_report ();
310308}
311309
@@ -402,16 +400,13 @@ c_report_raw_hid(mrb_vm *vm, mrb_value *v, int argc) {
402400void
403401c_Keyboard_hid_task (mrb_vm * vm , mrb_value * v , int argc )
404402{
405- input_updated_bitmap = 0 ;
406-
407403 if ( keyboard_modifier != GET_INT_ARG (1 ) ) {
408404 keyboard_modifier = (uint8_t )GET_INT_ARG (1 );
409405 input_updated_bitmap |= 1 <<REPORT_ID_KEYBOARD ;
410406 }
411407
412- if ( memcmp (prev_keyboard_keycodes , GET_STRING_ARG (2 ), 6 ) ) {
413- keyboard_keycodes = GET_STRING_ARG (2 );
414- memcpy (prev_keyboard_keycodes , GET_STRING_ARG (2 ), 6 );
408+ if ( memcmp (keyboard_keycodes , GET_STRING_ARG (2 ), 6 ) ) {
409+ memcpy (keyboard_keycodes , GET_STRING_ARG (2 ), 6 );
415410 input_updated_bitmap |= 1 <<REPORT_ID_KEYBOARD ;
416411 }
417412
0 commit comments