From f72458d211cbd060bc07bc7617ce28da4fc84632 Mon Sep 17 00:00:00 2001 From: Lance798 <32232417+Lance798@users.noreply.github.com> Date: Sat, 17 Aug 2024 15:01:32 +0800 Subject: [PATCH] fix bug when exit badusb app --- fw/Core/Hitcon/App/BadUsbApp.cc | 10 ++++++++-- fw/Core/Hitcon/Logic/UsbLogic.cc | 9 ++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/fw/Core/Hitcon/App/BadUsbApp.cc b/fw/Core/Hitcon/App/BadUsbApp.cc index e94bb7a3..798546c8 100644 --- a/fw/Core/Hitcon/App/BadUsbApp.cc +++ b/fw/Core/Hitcon/App/BadUsbApp.cc @@ -14,10 +14,16 @@ void BadUsbApp::OnEntry() { void BadUsbApp::OnExit() { g_usb_logic.StopScript(); } -void BadUsbApp::OnButton(button_t button) {} +void BadUsbApp::OnButton(button_t button) { + switch (button & BUTTON_VALUE_MASK) { + case BUTTON_BACK: + badge_controller.OnAppEnd(this); + break; + } +} void BadUsbApp::OnScriptFinished(void *unsed) { badge_controller.OnAppEnd(this); } } // namespace usb -} // namespace hitcon \ No newline at end of file +} // namespace hitcon diff --git a/fw/Core/Hitcon/Logic/UsbLogic.cc b/fw/Core/Hitcon/Logic/UsbLogic.cc index ceb5f7da..6269d0ff 100644 --- a/fw/Core/Hitcon/Logic/UsbLogic.cc +++ b/fw/Core/Hitcon/Logic/UsbLogic.cc @@ -119,7 +119,14 @@ void UsbLogic::RunScript(callback_t cb, void* arg1) { flag = false; } -void UsbLogic::StopScript() { scheduler.DisablePeriodic(&_routine_task); } +void UsbLogic::StopScript() { + if (_routine_task.IsEnabled()) scheduler.DisablePeriodic(&_routine_task); + if (_write_routine_task.IsEnabled()) + scheduler.DisablePeriodic(&_write_routine_task); + + USBD_CUSTOM_HID_SendReport(&hUsbDeviceFS, + reinterpret_cast(&empty_report), 8); +} // run every 20ms void UsbLogic::Routine(void* unused) {