Skip to content

Commit

Permalink
fix bug when exit badusb app
Browse files Browse the repository at this point in the history
  • Loading branch information
Lance798 authored and john0312 committed Aug 17, 2024
1 parent 3f9c8e4 commit f72458d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 8 additions & 2 deletions fw/Core/Hitcon/App/BadUsbApp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
} // namespace hitcon
9 changes: 8 additions & 1 deletion fw/Core/Hitcon/Logic/UsbLogic.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t*>(&empty_report), 8);
}

// run every 20ms
void UsbLogic::Routine(void* unused) {
Expand Down

0 comments on commit f72458d

Please sign in to comment.