Rearrange the file layout in preparation of becoming a monorepo

Move the documentation to `doc/plugin/LEDControl.md`, sources under
`src/kaleidoscope/plugin/` (appropriately namespaced). This is in preparation of
merging plugins into a single monorepo.

Signed-off-by: Gergely Nagy <algernon@keyboard.io>
pull/365/head
Gergely Nagy 6 years ago
parent dfe2ffaab4
commit 6a46b800d0
No known key found for this signature in database
GPG Key ID: AC1E90BAC433F68F

@ -1,6 +1,3 @@
# Kaleidoscope-LEDControl
This is a plugin for [Kaleidoscope][fw], for controlling the LEDs, and LED
effects.
[fw]: https://github.com/keyboardio/Kaleidoscope
See [doc/plugin/LEDControl.md](doc/plugin/LEDControl.md) for documentation.

@ -0,0 +1,21 @@
# Kaleidoscope-LEDControl
This is a plugin for [Kaleidoscope][fw], for controlling the LEDs, and LED
effects.
[fw]: https://github.com/keyboardio/Kaleidoscope
## Upgrading
The `LEDUtils.h` and `LED-Off.h` headers were moved, and need a
`kaleidoscope/plugin/` prefix now. The old headers still work, but are
deprecated, and will emit a warning. Both of them are included by
`<Kaleidoscope-LEDControl.h>` by default, so instead of migrating to the new
paths, one might wish to simply drop them instead.
The compatibility headers will be removed by 2019-01-14.
Furthermore, to implement LED modes, one should use
`kaleidoscope::plugin::LEDMode` as a base class now, instead of the former
`kaleidoscope::LEDMode`. There is a backwards compatible typedef, but like the
headers, it will be removed by 2019-01-14.

@ -16,150 +16,6 @@
#pragma once
#include <Kaleidoscope.h>
#define LED_MAX_MODES 24
#define LED_TOGGLE B00000001 // Synthetic, internal
#define Key_LEDEffectNext (Key) { 0, KEY_FLAGS | SYNTHETIC | IS_INTERNAL | LED_TOGGLE }
#define Key_LEDEffectPrevious (Key) { 1, KEY_FLAGS | SYNTHETIC | IS_INTERNAL | LED_TOGGLE }
namespace kaleidoscope {
/** Base class for LED modes.
*
* LED modes are a special kind of plugin, they are in charge of updating LED
* colors, setting a theme. While it is possible to have other plugins
* override the mode's colors, the LED mode is the baseline.
*
* Most of its functionality is called via @ref LEDControl, with only a few
* public methods.
*
* A LED mode **must** implement at least one of @ref onActivate or @ref
* update, and possibly @ref refreshAt too.
*/
class LEDMode : public kaleidoscope::Plugin {
friend class LEDControl;
protected:
// These methods should only be called by LEDControl.
/** One-time setup, called at keyboard boot.
*
* Any hooks that need registering, any one-time setup that needs to be
* performed, shall be done here. This is purely for preparation purposes, the
* LEDs should not be touched yet at this time.
*/
virtual void setup(void) {}
/** Function to call whenever the mode is activated.
*
* Like @ref setup, this method need not touch LEDs, @ref update will be
* called right after it. The purpose of this callback is to allow a plugin to
* do some preparation whenever it is activated, instead of only on boot, or
* always at each cycle.
*
* However, unlike @ref setup, this method can change LED colors, if so
* desired. Either to provide an initial state, or a static color set. In the
* latter case, consider implementing @ref refreshAt too, because other
* plugins may override some of the colors set at activation time, and @ref
* refreshAt can be used to restore them when needed.
*
* Before the callback runs, LEDs will be blanked.
*/
virtual void onActivate(void) {}
/** Update the LEDs once per cycle.
*
* Usually the brains of the plugin, which updates the LEDs each cycle. It is
* called after the matrix has been scanned, once per cycle.
*/
virtual void update(void) {}
/** Refresh the color of a given key.
*
* If we have another plugin that overrides colors set by the active LED mode
* (either at @onActivate time, or via @ref update), if that plugin wants to
* restore whatever color the mode would set the key color to, this is the
* method it will call.
*
* @param row is the row coordinate of the key to refresh the color of.
* @param col is the column coordinate of the key to refresh the color of.
*/
virtual void refreshAt(byte row, byte col) {}
public:
/** Activate the current object as the LED mode.
*/
void activate(void);
/** Plugin initialization.
*
* Called via `Kaleidoscope.use()`, registers the LED mode, and does the
* necessary initialization steps. Calls @ref setup at the end.
*/
kaleidoscope::EventHandlerResult onSetup();
};
class LEDControl : public kaleidoscope::Plugin {
public:
LEDControl(void);
static void next_mode(void);
static void prev_mode(void);
static void setup(void);
static void update(void) {
if (modes[mode])
modes[mode]->update();
}
static void refreshAt(byte row, byte col) {
if (modes[mode])
modes[mode]->refreshAt(row, col);
}
static void set_mode(uint8_t mode);
static uint8_t get_mode_index();
static LEDMode *get_mode();
static void refreshAll() {
if (paused)
return;
set_all_leds_to({0, 0, 0});
if (modes[mode])
modes[mode]->onActivate();
}
static int8_t mode_add(LEDMode *mode);
static void setCrgbAt(uint8_t i, cRGB crgb);
static void setCrgbAt(byte row, byte col, cRGB color);
static cRGB getCrgbAt(uint8_t i);
static void syncLeds(void);
static void set_all_leds_to(uint8_t r, uint8_t g, uint8_t b);
static void set_all_leds_to(cRGB color);
static void activate(LEDMode *mode);
static uint16_t syncDelay;
static bool paused;
kaleidoscope::EventHandlerResult onSetup();
kaleidoscope::EventHandlerResult onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState);
kaleidoscope::EventHandlerResult beforeReportingState();
private:
static uint16_t syncTimer;
static LEDMode *modes[LED_MAX_MODES];
static uint8_t mode;
};
class FocusLEDCommand : public Plugin {
public:
FocusLEDCommand() {}
EventHandlerResult onFocusEvent(const char *command);
};
}
extern kaleidoscope::LEDControl LEDControl;
extern kaleidoscope::FocusLEDCommand FocusLEDCommand;
#include <kaleidoscope/plugin/LEDControl.h>
#include <kaleidoscope/plugin/LEDUtils.h>
#include <kaleidoscope/plugin/LED-Off.h>

@ -16,17 +16,6 @@
#pragma once
#include "Kaleidoscope-LEDControl.h"
#warning Please migrate to including "kaleidoscope/plugin/LED-Off.h" instead of "LED-Off.h", or even consider dropping the include, because <Kaleidoscope-LEDControl.h> will pull the right header in anyway.
namespace kaleidoscope {
class LEDOff : public LEDMode {
public:
LEDOff(void) { }
protected:
void onActivate(void) final;
void refreshAt(byte row, byte col) final;
};
}
extern kaleidoscope::LEDOff LEDOff;
#include "kaleidoscope/plugin/LED-Off.h"

@ -16,7 +16,6 @@
#pragma once
#include <Kaleidoscope.h>
#warning Please migrate to including "kaleidoscope/plugin/LEDUtils.h" instead of "LEDUtils.h", or even consider dropping the include, because <Kaleidoscope-LEDControl.h> will pull the right header in anyway.
cRGB breath_compute(uint8_t hue = 170, uint8_t saturation = 255);
cRGB hsvToRgb(uint16_t h, uint16_t s, uint16_t v);
#include "kaleidoscope/plugin/LEDUtils.h"

@ -14,7 +14,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "BootAnimation.h"
#include "kaleidoscope/plugin/BootAnimation.h"
#include "Kaleidoscope-LEDControl.h"
#ifdef ARDUINO_AVR_MODEL01

@ -14,9 +14,10 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "LED-Off.h"
#include "kaleidoscope/plugin/LED-Off.h"
namespace kaleidoscope {
namespace plugin {
void LEDOff::onActivate(void) {
::LEDControl.set_all_leds_to({0, 0, 0});
}
@ -25,5 +26,6 @@ void LEDOff::refreshAt(byte row, byte col) {
::LEDControl.setCrgbAt(row, col, {0, 0, 0});
}
}
}
kaleidoscope::LEDOff LEDOff;
kaleidoscope::plugin::LEDOff LEDOff;

@ -0,0 +1,34 @@
/* Kaleidoscope-LEDControl - LED control plugin for Kaleidoscope
* Copyright (C) 2017-2018 Keyboard.io, Inc.
*
* 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, version 3.
*
* 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-LEDControl.h"
namespace kaleidoscope {
namespace plugin {
class LEDOff : public LEDMode {
public:
LEDOff(void) { }
protected:
void onActivate(void) final;
void refreshAt(byte row, byte col) final;
};
}
}
extern kaleidoscope::plugin::LEDOff LEDOff;

@ -18,6 +18,7 @@
#include "Kaleidoscope-FocusSerial.h"
namespace kaleidoscope {
namespace plugin {
LEDMode *LEDControl::modes[LED_MAX_MODES];
uint8_t LEDControl::mode;
@ -274,7 +275,8 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
return EventHandlerResult::EVENT_CONSUMED;
}
}
}
kaleidoscope::LEDControl LEDControl;
kaleidoscope::FocusLEDCommand FocusLEDCommand;
kaleidoscope::plugin::LEDControl LEDControl;
kaleidoscope::plugin::FocusLEDCommand FocusLEDCommand;

@ -0,0 +1,170 @@
/* Kaleidoscope-LEDControl - LED control plugin for Kaleidoscope
* Copyright (C) 2017-2018 Keyboard.io, Inc.
*
* 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, version 3.
*
* 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 LED_MAX_MODES 24
#define LED_TOGGLE B00000001 // Synthetic, internal
#define Key_LEDEffectNext (Key) { 0, KEY_FLAGS | SYNTHETIC | IS_INTERNAL | LED_TOGGLE }
#define Key_LEDEffectPrevious (Key) { 1, KEY_FLAGS | SYNTHETIC | IS_INTERNAL | LED_TOGGLE }
namespace kaleidoscope {
namespace plugin {
/** Base class for LED modes.
*
* LED modes are a special kind of plugin, they are in charge of updating LED
* colors, setting a theme. While it is possible to have other plugins
* override the mode's colors, the LED mode is the baseline.
*
* Most of its functionality is called via @ref LEDControl, with only a few
* public methods.
*
* A LED mode **must** implement at least one of @ref onActivate or @ref
* update, and possibly @ref refreshAt too.
*/
class LEDMode : public kaleidoscope::Plugin {
friend class LEDControl;
protected:
// These methods should only be called by LEDControl.
/** One-time setup, called at keyboard boot.
*
* Any hooks that need registering, any one-time setup that needs to be
* performed, shall be done here. This is purely for preparation purposes, the
* LEDs should not be touched yet at this time.
*/
virtual void setup(void) {}
/** Function to call whenever the mode is activated.
*
* Like @ref setup, this method need not touch LEDs, @ref update will be
* called right after it. The purpose of this callback is to allow a plugin to
* do some preparation whenever it is activated, instead of only on boot, or
* always at each cycle.
*
* However, unlike @ref setup, this method can change LED colors, if so
* desired. Either to provide an initial state, or a static color set. In the
* latter case, consider implementing @ref refreshAt too, because other
* plugins may override some of the colors set at activation time, and @ref
* refreshAt can be used to restore them when needed.
*
* Before the callback runs, LEDs will be blanked.
*/
virtual void onActivate(void) {}
/** Update the LEDs once per cycle.
*
* Usually the brains of the plugin, which updates the LEDs each cycle. It is
* called after the matrix has been scanned, once per cycle.
*/
virtual void update(void) {}
/** Refresh the color of a given key.
*
* If we have another plugin that overrides colors set by the active LED mode
* (either at @onActivate time, or via @ref update), if that plugin wants to
* restore whatever color the mode would set the key color to, this is the
* method it will call.
*
* @param row is the row coordinate of the key to refresh the color of.
* @param col is the column coordinate of the key to refresh the color of.
*/
virtual void refreshAt(byte row, byte col) {}
public:
/** Activate the current object as the LED mode.
*/
void activate(void);
/** Plugin initialization.
*
* Called via `Kaleidoscope.use()`, registers the LED mode, and does the
* necessary initialization steps. Calls @ref setup at the end.
*/
kaleidoscope::EventHandlerResult onSetup();
};
class LEDControl : public kaleidoscope::Plugin {
public:
LEDControl(void);
static void next_mode(void);
static void prev_mode(void);
static void setup(void);
static void update(void) {
if (modes[mode])
modes[mode]->update();
}
static void refreshAt(byte row, byte col) {
if (modes[mode])
modes[mode]->refreshAt(row, col);
}
static void set_mode(uint8_t mode);
static uint8_t get_mode_index();
static LEDMode *get_mode();
static void refreshAll() {
if (paused)
return;
set_all_leds_to({0, 0, 0});
if (modes[mode])
modes[mode]->onActivate();
}
static int8_t mode_add(LEDMode *mode);
static void setCrgbAt(uint8_t i, cRGB crgb);
static void setCrgbAt(byte row, byte col, cRGB color);
static cRGB getCrgbAt(uint8_t i);
static void syncLeds(void);
static void set_all_leds_to(uint8_t r, uint8_t g, uint8_t b);
static void set_all_leds_to(cRGB color);
static void activate(LEDMode *mode);
static uint16_t syncDelay;
static bool paused;
kaleidoscope::EventHandlerResult onSetup();
kaleidoscope::EventHandlerResult onKeyswitchEvent(Key &mappedKey, byte row, byte col, uint8_t keyState);
kaleidoscope::EventHandlerResult beforeReportingState();
private:
static uint16_t syncTimer;
static LEDMode *modes[LED_MAX_MODES];
static uint8_t mode;
};
class FocusLEDCommand : public Plugin {
public:
FocusLEDCommand() {}
EventHandlerResult onFocusEvent(const char *command);
};
}
// Backwards compatibility
typedef plugin::LEDMode LEDMode;
}
extern kaleidoscope::plugin::LEDControl LEDControl;
extern kaleidoscope::plugin::FocusLEDCommand FocusLEDCommand;

@ -14,7 +14,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "LEDUtils.h"
#include "kaleidoscope/plugin/LEDUtils.h"
cRGB
breath_compute(uint8_t hue, uint8_t saturation) {

@ -0,0 +1,22 @@
/* Kaleidoscope-LEDControl - LED control plugin for Kaleidoscope
* Copyright (C) 2017-2018 Keyboard.io, Inc.
*
* 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, version 3.
*
* 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>
cRGB breath_compute(uint8_t hue = 170, uint8_t saturation = 255);
cRGB hsvToRgb(uint16_t h, uint16_t s, uint16_t v);
Loading…
Cancel
Save