Merge pull request #1257 from keyboardio/r/hostpowermanagement/refactor

HostPowerManagement: Lift out the suspension check, to remove code duplication
master
Jesse Vincent 2 years ago committed by GitHub
commit 95ea4e3175
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -36,10 +36,18 @@ namespace plugin {
bool HostPowerManagement::was_suspended_ = false; bool HostPowerManagement::was_suspended_ = false;
bool HostPowerManagement::initial_suspend_ = true; bool HostPowerManagement::initial_suspend_ = true;
EventHandlerResult HostPowerManagement::beforeEachCycle() { bool HostPowerManagement::isSuspended() {
#if defined(__AVR__)
return USBDevice.isSuspended();
#elif defined(ARDUINO_ARCH_GD32)
return USBCore().isSuspended();
#else
return false;
#endif
}
#ifdef __AVR__ EventHandlerResult HostPowerManagement::beforeEachCycle() {
if ((_usbSuspendState & (1 << SUSPI))) { if (isSuspended()) {
if (!initial_suspend_) { if (!initial_suspend_) {
if (!was_suspended_) { if (!was_suspended_) {
was_suspended_ = true; was_suspended_ = true;
@ -56,23 +64,6 @@ EventHandlerResult HostPowerManagement::beforeEachCycle() {
hostPowerManagementEventHandler(Resume); hostPowerManagementEventHandler(Resume);
} }
} }
#endif
#ifdef ARDUINO_ARCH_GD32
if (USBCore().isSuspended()) {
if (!was_suspended_) {
was_suspended_ = true;
hostPowerManagementEventHandler(Suspend);
} else {
hostPowerManagementEventHandler(Sleep);
}
} else {
if (was_suspended_) {
was_suspended_ = false;
hostPowerManagementEventHandler(Resume);
}
}
#endif
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -35,6 +35,8 @@ class HostPowerManagement : public kaleidoscope::Plugin {
private: private:
static bool was_suspended_; static bool was_suspended_;
static bool initial_suspend_; static bool initial_suspend_;
bool isSuspended();
}; };
} // namespace plugin } // namespace plugin

Loading…
Cancel
Save