Merge remote-tracking branch 'plugin/HostPowerManagement/f/monorepo' into f/monorepo

pull/365/head
Gergely Nagy 6 years ago
commit 0d2c846656
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -0,0 +1,47 @@
# Kaleidoscope-HostPowerManagement
Support performing custom actions whenever the host suspends, resumes, or is
sleeping.
## Using the plugin
To use the plugin, one needs to include the header, and activate it. No further
configuration is necessary, unless one wants to perform custom actions.
```c++
#include <Kaleidoscope.h>
#include <Kaleidoscope-HostPowerManagement.h>
KALEIDOSCOPE_INIT_PLUGINS(HostPowerManagement);
void setup () {
Kaleidoscope.setup ();
}
```
## Plugin methods
The plugin provides the `HostPowerManagement` object, with no public methods.
## Overrideable methods
### `hostPowerManagementEventHandler(event)`
> The `hostPowerManagementEventHandler` method is the brain of the plugin: this function
> tells it what action to perform in response to the various events.
>
> Currently supported events are:
> `kaleidoscope::plugin::HostPowerManagement::Suspend` is fired once when the
> host suspends; `kaleidoscope::plugin::HostPowerManagement::Sleep` is fired
> every cycle while the host is suspended;
> `kaleidoscope::plugin::HostPowerManagement::Resume` is fired once when the
> host wakes up.
>
> The default implementation is empty.
## Further reading
Starting from the [example][plugin:example] is the recommended way of getting
started with the plugin.
[plugin:example]: ../../examples/HostPowerManagement/HostPowerManagement.ino

@ -0,0 +1,71 @@
/* -*- mode: c++ -*-
* Kaleidoscope-HostPowerManagement -- Host power management support plugin.
* Copyright (C) 2017, 2018 Gergely Nagy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Kaleidoscope.h>
#include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-HostPowerManagement.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED
(
Key_NoKey, Key_1, Key_2, Key_3, Key_4, Key_5, Key_NoKey,
Key_Backtick, Key_Q, Key_W, Key_E, Key_R, Key_T, Key_Tab,
Key_PageUp, Key_A, Key_S, Key_D, Key_F, Key_G,
Key_PageDown, Key_Z, Key_X, Key_C, Key_V, Key_B, Key_Escape,
Key_LeftControl, Key_Backspace, Key_LeftGui, Key_LeftShift,
Key_NoKey,
Key_skip, Key_6, Key_7, Key_8, Key_9, Key_0, Key_skip,
Key_Enter, Key_Y, Key_U, Key_I, Key_O, Key_P, Key_Equals,
Key_H, Key_J, Key_K, Key_L, Key_Semicolon, Key_Quote,
Key_skip, Key_N, Key_M, Key_Comma, Key_Period, Key_Slash, Key_Minus,
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey
),
};
// *INDENT-ON*
void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event) {
switch (event) {
case kaleidoscope::plugin::HostPowerManagement::Suspend:
LEDControl.paused = true;
LEDControl.set_all_leds_to({0, 0, 0});
LEDControl.syncLeds();
break;
case kaleidoscope::plugin::HostPowerManagement::Resume:
LEDControl.paused = false;
LEDControl.refreshAll();
break;
case kaleidoscope::plugin::HostPowerManagement::Sleep:
break;
}
}
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
HostPowerManagement);
void setup() {
Kaleidoscope.setup();
}
void loop() {
Kaleidoscope.loop();
}

@ -0,0 +1,21 @@
/* -*- mode: c++ -*-
* Kaleidoscope-HostPowerManagement -- Host power management support plugin.
* Copyright (C) 2017 Gergely Nagy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <kaleidoscope/plugin/HostPowerManagement.h>

@ -0,0 +1,64 @@
/* -*- mode: c++ -*-
* Kaleidoscope-HostPowerManagement -- Host power management support plugin.
* Copyright (C) 2017, 2018 Gergely Nagy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <Kaleidoscope.h>
#include <Kaleidoscope-HostPowerManagement.h>
#include <Kaleidoscope-LEDControl.h>
// 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 plugin {
bool HostPowerManagement::was_suspended_ = false;
bool HostPowerManagement::initial_suspend_ = true;
EventHandlerResult HostPowerManagement::beforeEachCycle() {
#ifdef __AVR__
if ((_usbSuspendState & (1 << SUSPI))) {
if (!initial_suspend_) {
if (!was_suspended_) {
was_suspended_ = true;
hostPowerManagementEventHandler(Suspend);
} else {
hostPowerManagementEventHandler(Sleep);
}
}
} else {
if (initial_suspend_)
initial_suspend_ = false;
if (was_suspended_) {
was_suspended_ = false;
hostPowerManagementEventHandler(Resume);
}
}
#endif
return EventHandlerResult::OK;
}
}
}
__attribute__((weak)) void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event) {
}
kaleidoscope::plugin::HostPowerManagement HostPowerManagement;

@ -0,0 +1,57 @@
/* -*- mode: c++ -*-
* Kaleidoscope-HostPowerManagement -- Host power management support plugin.
* Copyright (C) 2017, 2018 Gergely Nagy
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <Kaleidoscope.h>
#define _DEPRECATED_MESSAGE_ENABLEWAKEUP \
"The HostPowerManagement.enableWakeup() call is not necessary anymore,\n" \
"the firmware supports wakeup by default now. The line can be safely\n" \
"removed."
namespace kaleidoscope {
namespace plugin {
class HostPowerManagement : public kaleidoscope::Plugin {
public:
typedef enum {
Suspend,
Sleep,
Resume,
} Event;
HostPowerManagement(void) {}
void enableWakeup(void) DEPRECATED(ENABLEWAKEUP) {}
EventHandlerResult beforeEachCycle();
private:
static bool was_suspended_;
static bool initial_suspend_;
};
}
// Backwards compatibility
typedef plugin::HostPowerManagement HostPowerManagement;
}
void hostPowerManagementEventHandler(kaleidoscope::plugin::HostPowerManagement::Event event);
extern kaleidoscope::plugin::HostPowerManagement HostPowerManagement;
Loading…
Cancel
Save