Updated to use the new plugin APIs

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 7 years ago
parent c56c7791ba
commit 19cffca5c4

@ -22,10 +22,11 @@ configuration is necessary, unless one wants to perform custom actions.
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-HostPowerManagement.h> #include <Kaleidoscope-HostPowerManagement.h>
KALEIDOSCOPE_INIT_PLUGINS(HostPowerManagement);
void setup () { void setup () {
Kaleidoscope.setup (); Kaleidoscope.setup ();
Kaleidoscope.use(&HostPowerManagement);
HostPowerManagement.enableWakeup(); HostPowerManagement.enableWakeup();
} }
``` ```

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-HostPowerManagement -- Host power management support plugin. * Kaleidoscope-HostPowerManagement -- Host power management support plugin.
* Copyright (C) 2017 Gergely Nagy * Copyright (C) 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -20,6 +20,7 @@
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-HostPowerManagement.h> #include <Kaleidoscope-HostPowerManagement.h>
// *INDENT-OFF*
const Key keymaps[][ROWS][COLS] PROGMEM = { const Key keymaps[][ROWS][COLS] PROGMEM = {
[0] = KEYMAP_STACKED [0] = KEYMAP_STACKED
( (
@ -39,8 +40,8 @@ const Key keymaps[][ROWS][COLS] PROGMEM = {
Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl, Key_RightShift, Key_RightAlt, Key_Spacebar, Key_RightControl,
Key_NoKey Key_NoKey
), ),
}; };
// *INDENT-ON*
void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event event) { void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event event) {
switch (event) { switch (event) {
@ -58,11 +59,12 @@ void hostPowerManagementEventHandler(kaleidoscope::HostPowerManagement::Event ev
} }
} }
KALEIDOSCOPE_INIT_PLUGINS(LEDControl,
HostPowerManagement);
void setup() { void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
Kaleidoscope.use(&HostPowerManagement);
HostPowerManagement.enableWakeup(); HostPowerManagement.enableWakeup();
} }

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-HostPowerManagement -- Host power management support plugin. * Kaleidoscope-HostPowerManagement -- Host power management support plugin.
* Copyright (C) 2017 Gergely Nagy * Copyright (C) 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -29,14 +29,7 @@ namespace kaleidoscope {
bool HostPowerManagement::was_suspended_ = false; bool HostPowerManagement::was_suspended_ = false;
bool HostPowerManagement::initial_suspend_ = true; bool HostPowerManagement::initial_suspend_ = true;
void HostPowerManagement::begin(void) { EventHandlerResult HostPowerManagement::beforeEachCycle() {
Kaleidoscope.useLoopHook(loopHook);
}
void HostPowerManagement::loopHook(bool post_clear) {
if (post_clear)
return;
if ((_usbSuspendState & (1 << SUSPI))) { if ((_usbSuspendState & (1 << SUSPI))) {
if (!initial_suspend_) { if (!initial_suspend_) {
if (!was_suspended_) { if (!was_suspended_) {
@ -54,7 +47,23 @@ void HostPowerManagement::loopHook(bool post_clear) {
hostPowerManagementEventHandler(Resume); hostPowerManagementEventHandler(Resume);
} }
} }
return EventHandlerResult::OK;
}
// Legacy V1 API
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
void HostPowerManagement::begin() {
Kaleidoscope.useLoopHook(legacyLoopHook);
}
void HostPowerManagement::legacyLoopHook(bool is_post_clear) {
if (is_post_clear)
return;
::HostPowerManagement.beforeEachCycle();
} }
#endif
} }

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-HostPowerManagement -- Host power management support plugin. * Kaleidoscope-HostPowerManagement -- Host power management support plugin.
* Copyright (C) 2017 Gergely Nagy * Copyright (C) 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -22,7 +22,7 @@
#include "WakeupKeyboard.h" #include "WakeupKeyboard.h"
namespace kaleidoscope { namespace kaleidoscope {
class HostPowerManagement : public KaleidoscopePlugin { class HostPowerManagement : public kaleidoscope::Plugin {
public: public:
typedef enum { typedef enum {
Suspend, Suspend,
@ -30,18 +30,23 @@ class HostPowerManagement : public KaleidoscopePlugin {
Resume, Resume,
} Event; } Event;
HostPowerManagement(void) {}; HostPowerManagement(void) {}
void begin(void) final;
void enableWakeup(void) { void enableWakeup(void) {
WakeupKeyboard.begin(); WakeupKeyboard.init();
}; }
EventHandlerResult beforeEachCycle();
#if KALEIDOSCOPE_ENABLE_V1_PLUGIN_API
protected:
void begin();
static void legacyLoopHook(bool is_post_clear);
#endif
private: private:
static bool was_suspended_; static bool was_suspended_;
static bool initial_suspend_; static bool initial_suspend_;
static void loopHook(bool post_clear);
}; };
} }

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-MyOldFriend -- Host power management support plugin. * Kaleidoscope-HostPowerManagement -- Host power management support plugin.
* Copyright (C) 2017 Gergely Nagy * Copyright (C) 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -85,7 +85,7 @@ bool WakeupKeyboard_::setup(USBSetup& setup) {
return false; return false;
} }
void WakeupKeyboard_::begin() { void WakeupKeyboard_::init() {
} }
WakeupKeyboard_ WakeupKeyboard; WakeupKeyboard_ WakeupKeyboard;

@ -1,6 +1,6 @@
/* -*- mode: c++ -*- /* -*- mode: c++ -*-
* Kaleidoscope-MyOldFriend -- Host power management support plugin. * Kaleidoscope-HostPowerManagement -- Host power management support plugin.
* Copyright (C) 2017 Gergely Nagy * Copyright (C) 2017, 2018 Gergely Nagy
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -22,10 +22,10 @@
#include "PluggableUSB.h" #include "PluggableUSB.h"
#include "HID.h" #include "HID.h"
class WakeupKeyboard_ : public PluggableUSBModule, public KaleidoscopePlugin { class WakeupKeyboard_ : public PluggableUSBModule, public kaleidoscope::Plugin {
public: public:
WakeupKeyboard_(void); WakeupKeyboard_(void);
void begin() final; void init();
protected: protected:
int getInterface(uint8_t* interfaceCount); int getInterface(uint8_t* interfaceCount);

Loading…
Cancel
Save