starting with commands
This commit is contained in:
@@ -371,6 +371,29 @@ static inline bool find_key_in_report(hid_keyboard_report_t const *report, uint8
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool process_command(const char* input) {
|
||||
if (input[0] != '/') return false;
|
||||
|
||||
if (strcmp(input, "/refresh") == 0) {
|
||||
printf("Command: /refresh\n");
|
||||
g_force_full_refresh = true;
|
||||
send_display_update("", false);
|
||||
return true;
|
||||
} else if (strcmp(input, "/clear") == 0) {
|
||||
printf("Command: /clear\n");
|
||||
g_entry_list.count = 0;
|
||||
memset(g_entry_list.entries, 0, sizeof(g_entry_list.entries));
|
||||
g_force_full_refresh = true;
|
||||
send_display_update("", false);
|
||||
return true;
|
||||
} else if (strcmp(input, "/wifisetup") == 0) {
|
||||
printf("Command: /wifisetup (Not implemented)\n");
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void process_kbd_report(hid_keyboard_report_t const *report) {
|
||||
static hid_keyboard_report_t prev_report = { 0, 0, {0} };
|
||||
|
||||
@@ -403,21 +426,32 @@ static void process_kbd_report(hid_keyboard_report_t const *report) {
|
||||
} else if (is_enter) {
|
||||
printf("\n");
|
||||
|
||||
// Update e-Paper (commit line)
|
||||
send_display_update(g_input_buffer, true);
|
||||
|
||||
// Save to last echo
|
||||
strncpy(g_last_echo, g_input_buffer, sizeof(g_last_echo) - 1);
|
||||
g_last_echo[sizeof(g_last_echo) - 1] = '\0';
|
||||
|
||||
// Clear buffer
|
||||
g_buffer_index = 0;
|
||||
g_input_buffer[0] = '\0';
|
||||
|
||||
// Update OLED
|
||||
if (g_display_manager) {
|
||||
g_display_manager->set_last_echo(g_last_echo);
|
||||
g_display_manager->refresh("", g_last_echo);
|
||||
if (process_command(g_input_buffer)) {
|
||||
// Command handled, clear buffer but don't commit line
|
||||
g_buffer_index = 0;
|
||||
g_input_buffer[0] = '\0';
|
||||
|
||||
if (g_display_manager) {
|
||||
g_display_manager->set_last_echo("Command Executed");
|
||||
g_display_manager->refresh("", "Command Executed");
|
||||
}
|
||||
} else {
|
||||
// Update e-Paper (commit line)
|
||||
send_display_update(g_input_buffer, true);
|
||||
|
||||
// Save to last echo
|
||||
strncpy(g_last_echo, g_input_buffer, sizeof(g_last_echo) - 1);
|
||||
g_last_echo[sizeof(g_last_echo) - 1] = '\0';
|
||||
|
||||
// Clear buffer
|
||||
g_buffer_index = 0;
|
||||
g_input_buffer[0] = '\0';
|
||||
|
||||
// Update OLED
|
||||
if (g_display_manager) {
|
||||
g_display_manager->set_last_echo(g_last_echo);
|
||||
g_display_manager->refresh("", g_last_echo);
|
||||
}
|
||||
}
|
||||
} else if (is_printable) {
|
||||
printf("%c", ch);
|
||||
@@ -443,12 +477,25 @@ static void process_kbd_report(hid_keyboard_report_t const *report) {
|
||||
// TinyUSB Callbacks
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static bool g_keyboard_mounted = false;
|
||||
|
||||
// Invoked when device is suspended
|
||||
void tuh_device_suspend_cb(uint8_t dev_addr) {
|
||||
printf("Device address = %d suspended\r\n", dev_addr);
|
||||
}
|
||||
|
||||
// Invoked when device is resumed
|
||||
void tuh_device_resume_cb(uint8_t dev_addr) {
|
||||
printf("Device address = %d resumed\r\n", dev_addr);
|
||||
}
|
||||
|
||||
void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len) {
|
||||
printf("HID device address = %d, instance = %d is mounted\r\n", dev_addr, instance);
|
||||
|
||||
uint8_t const itf_protocol = tuh_hid_interface_protocol(dev_addr, instance);
|
||||
if (itf_protocol == HID_ITF_PROTOCOL_KEYBOARD) {
|
||||
printf("Keyboard mounted\r\n");
|
||||
g_keyboard_mounted = true;
|
||||
if (g_display_manager) {
|
||||
g_display_manager->refresh("Keyboard Connected", nullptr);
|
||||
}
|
||||
@@ -460,8 +507,14 @@ void tuh_hid_mount_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_re
|
||||
|
||||
void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) {
|
||||
printf("HID device address = %d, instance = %d is unmounted\r\n", dev_addr, instance);
|
||||
g_keyboard_mounted = false;
|
||||
|
||||
// Reset input buffer
|
||||
g_buffer_index = 0;
|
||||
g_input_buffer[0] = '\0';
|
||||
|
||||
if (g_display_manager) {
|
||||
g_display_manager->refresh("Keyboard Disconnected", nullptr);
|
||||
g_display_manager->refresh("Waiting for Keyboard", nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -503,7 +556,7 @@ int main() {
|
||||
|
||||
uint32_t now = to_ms_since_boot(get_absolute_time());
|
||||
if (now - last_print > 5000) {
|
||||
printf("Heartbeat: %u\n", now);
|
||||
printf("Heartbeat: %u, Mounted: %d\n", now, g_keyboard_mounted);
|
||||
last_print = now;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user