summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Vincent <jesse@fsck.com>2017-12-16 11:42:38 -0800
committerGitHub <noreply@github.com>2017-12-16 11:42:38 -0800
commitb745a26c5ac8d4587f868612bf148b00dc485de9 (patch)
treea08ef4a4c985ef7f0b978ef6d316730d17861568
parent709aaa235487e8ce086c5ddf159d34d8c3dd618b (diff)
parent72035c14d032908930b66c1260a225a01200c6c8 (diff)
downloadmodel01-firmware-b745a26c5ac8d4587f868612bf148b00dc485de9.tar.gz
model01-firmware-b745a26c5ac8d4587f868612bf148b00dc485de9.tar.bz2
model01-firmware-b745a26c5ac8d4587f868612bf148b00dc485de9.zip
Merge pull request #41 from algernon/f/host-powermanagement
Add support for host power management (suspend & wakeup)
-rw-r--r--Model01-Firmware.ino37
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