Skip to content

Commit 5bcdae0

Browse files
committed
Some keyboard show
1 parent 25f3649 commit 5bcdae0

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

main/main.c

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,23 @@ static void hid_host_keyboard_report_callback(const uint8_t* const data, const i
350350
return;
351351
}
352352

353+
static char hex_string[3 * 64] = {0}; // Safe for up to 64 bytes
354+
char* p = hex_string;
355+
356+
for (int i = 0; i < length; i++) {
357+
p += sprintf(p, "%02X ", data[i]);
358+
}
359+
if (p > hex_string) *(p - 1) = '\0';
360+
361+
cls();
362+
pax_draw_text(&fb, BLACK, pax_font_sky_mono, 16, 10, 180, hex_string);
363+
353364
static uint8_t prev_keys[HID_KEYBOARD_KEY_MAX] = {0};
354365
key_event_t key_event;
355366

367+
char text[64] = {0};
368+
char* q = text;
369+
356370
for (int i = 0; i < HID_KEYBOARD_KEY_MAX; i++) {
357371

358372
// key has been released verification
@@ -371,8 +385,18 @@ static void hid_host_keyboard_report_callback(const uint8_t* const data, const i
371385
key_event.state = KEY_STATE_PRESSED;
372386
key_event_callback(&key_event);
373387
}
388+
389+
// add currently pressed key to text buffer
390+
if (kb_report->key[i] > HID_KEY_ERROR_UNDEFINED) {
391+
// Append as hex, or you can convert to ASCII if you have a lookup
392+
int written = snprintf(q, sizeof(text) - (q - text), "%02X ", kb_report->key[i]);
393+
if (written > 0) q += written;
394+
}
374395
}
375396

397+
pax_draw_text(&fb, BLACK, pax_font_sky_mono, 16, 10, 10, text);
398+
blit();
399+
376400
memcpy(prev_keys, &kb_report->key, HID_KEYBOARD_KEY_MAX);
377401
}
378402

0 commit comments

Comments
 (0)