Merge pull request #1260 from tlyu/hostpower-cleanup

master
Jesse Vincent 2 years ago committed by GitHub
commit fefc6699ba
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -26,15 +26,10 @@
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerResult::OK #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerResult::OK
// This is a terrible hack until Arduino#6964 gets implemented.
// It makes the `_usbSuspendState` symbol available to us.
extern uint8_t _usbSuspendState;
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
bool HostPowerManagement::was_suspended_ = false; bool HostPowerManagement::was_suspended_ = false;
bool HostPowerManagement::initial_suspend_ = true;
bool HostPowerManagement::isSuspended() { bool HostPowerManagement::isSuspended() {
#if defined(__AVR__) #if defined(__AVR__)
@ -48,17 +43,13 @@ bool HostPowerManagement::isSuspended() {
EventHandlerResult HostPowerManagement::beforeEachCycle() { EventHandlerResult HostPowerManagement::beforeEachCycle() {
if (isSuspended()) { if (isSuspended()) {
if (!initial_suspend_) {
if (!was_suspended_) { if (!was_suspended_) {
was_suspended_ = true; was_suspended_ = true;
hostPowerManagementEventHandler(Suspend); hostPowerManagementEventHandler(Suspend);
} else { } else {
hostPowerManagementEventHandler(Sleep); hostPowerManagementEventHandler(Sleep);
} }
}
} else { } else {
if (initial_suspend_)
initial_suspend_ = false;
if (was_suspended_) { if (was_suspended_) {
was_suspended_ = false; was_suspended_ = false;
hostPowerManagementEventHandler(Resume); hostPowerManagementEventHandler(Resume);

@ -34,7 +34,6 @@ class HostPowerManagement : public kaleidoscope::Plugin {
private: private:
static bool was_suspended_; static bool was_suspended_;
static bool initial_suspend_;
bool isSuspended(); bool isSuspended();
}; };

Loading…
Cancel
Save