diff options
Diffstat (limited to 'Model01-Firmware.ino')
-rw-r--r-- | Model01-Firmware.ino | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/Model01-Firmware.ino b/Model01-Firmware.ino index 14d7efb..c8d3f2e 100644 --- a/Model01-Firmware.ino +++ b/Model01-Firmware.ino @@ -56,6 +56,9 @@ // Support for Keyboardio's internal keyboard testing mode #include "Kaleidoscope-Model01-TestMode.h" +// Support for host power management (suspend & wakeup) +#include "Kaleidoscope-HostPowerManagement.h" + /** This 'enum' is a list of all the macros used by the Model 01's firmware * The names aren't particularly important. What is important is that each @@ -249,7 +252,32 @@ static kaleidoscope::LEDSolidColor solidBlue(0, 70, 130); static kaleidoscope::LEDSolidColor solidIndigo(0, 0, 170); static kaleidoscope::LEDSolidColor solidViolet(130, 0, 120); +/** toggleLedsOnSuspendResume toggles the LEDs off when the host goes to sleep, + * and turns them back on when it wakes up. + */ +void toggleLedsOnSuspendResume(kaleidoscope::HostPowerManagement::Event event) { + switch (event) { + case kaleidoscope::HostPowerManagement::Suspend: + LEDControl.paused = true; + LEDControl.set_all_leds_to({0, 0, 0}); + LEDControl.syncLeds(); + break; + case kaleidoscope::HostPowerManagement::Resume: + LEDControl.paused = false; + LEDControl.refreshAll(); + break; + case kaleidoscope::HostPowerManagement::Sleep: + break; + } +} +/** hostPowerManagementEventHandler dispatches power management events (suspend, + * resume, and sleep) to other functions that perform action based on these + * events. + */ +void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event event) { + toggleLedsOnSuspendResume(event); +} /** The 'setup' function is one of the two standard Arduino sketch functions. * It's called when your keyboard first powers up. This is where you set up @@ -309,7 +337,11 @@ void setup() { &Macros, // The MouseKeys plugin lets you add keys to your keymap which move the mouse. - &MouseKeys + &MouseKeys, + + // The HostPowerManagement plugin enables waking up the host from suspend, + // and allows us to turn LEDs off when it goes to sleep. + &HostPowerManagement ); // While we hope to improve this in the future, the NumPad plugin @@ -329,6 +361,9 @@ void setup() { // see https://github.com/keyboardio/Kaleidoscope-LED-Stalker StalkerEffect.variant = STALKER(BlazingTrail); + // We want the keyboard to be able to wake the host up from suspend. + HostPowerManagement.enableWakeup(); + // We want to make sure that the firmware starts with LED effects off // This avoids over-taxing devices that don't have a lot of power to share // with USB devices |