-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Evy Bongers <[email protected]>
- Loading branch information
1 parent
b01982f
commit 14e8920
Showing
5 changed files
with
213 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Colormap-Overlay | ||
|
||
The `Colormap-Overlay` extension provides an easier way to apply color to | ||
specific keys and layers, regardless of the active LED mode. | ||
|
||
## Using the extension | ||
|
||
To use the extension, include the header, tell it the number of layers you have, | ||
register the `Focus` hooks, and it will do the rest. We'll also set up a default | ||
for both the palette, and the colormap. | ||
|
||
```c++ | ||
#include <Kaleidoscope.h> | ||
#include <Kaleidoscope-LEDControl.h> | ||
#include <Kaleidoscope-Colormap-Overlay.h> | ||
|
||
KALEIDOSCOPE_INIT_PLUGINS(LEDControl, | ||
ColormapOverlay); | ||
|
||
void setup() { | ||
Kaleidoscope.setup(); | ||
|
||
COLORMAP_OVERLAYS( | ||
// Make the any key red | ||
kaleidoscope::plugin::Overlay(0, KeyAddr(0, 9), CRGB(0xff, 0x00, 0x00)), | ||
// Disable leds on the palm keys | ||
kaleidoscope::plugin::Overlay(0, KeyAddr(3, 6), CRGB(0x00, 0x00, 0x00)), | ||
kaleidoscope::plugin::Overlay(0, KeyAddr(3, 9), CRGB(0x00, 0x00, 0x00)), | ||
) | ||
} | ||
``` | ||
## Plugin methods | ||
TODO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name=Kaleidoscope-Colormap-Overlay | ||
version=0.0.0 | ||
sentence=Per key colors overlaying active LED effect | ||
maintainer=Kaleidoscope's Developers <[email protected]> | ||
url=https://github.com/keyboardio/Kaleidoscope | ||
author=Keyboardio | ||
paragraph= |
19 changes: 19 additions & 0 deletions
19
plugins/Kaleidoscope-Colormap-Overlay/src/Kaleidoscope-Colormap-Overlay.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* Kaleidoscope-Colormap-Overlay -- A LED 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/plugin/Colormap-Overlay.h" // IWYU pragma: export |
70 changes: 70 additions & 0 deletions
70
plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* Kaleidoscope-Colormap-Overlay - A LED 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/>. | ||
*/ | ||
|
||
#include "kaleidoscope/plugin/Colormap-Overlay.h" | ||
|
||
#include <stdint.h> // for uint8_t | ||
|
||
#include "kaleidoscope/KeyAddr.h" // for KeyAddr, MatrixAddr, MatrixAddr<>::... | ||
#include "kaleidoscope/device/device.h" // for cRGB, CRGB | ||
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerRes... | ||
#include "kaleidoscope/key_defs.h" // for Key, KEY_FLAGS, Key_NoKey, LockLayer | ||
#include "kaleidoscope/layers.h" // for Layer, Layer_ | ||
#include "kaleidoscope/plugin/LEDControl.h" // for LEDControl | ||
|
||
namespace kaleidoscope { | ||
namespace plugin { | ||
|
||
bool ColormapOverlay::hasOverlay(KeyAddr k) { | ||
uint8_t layer_index = Layer.lookupActiveLayer(k); | ||
for (uint8_t i{0}; i < overlay_count_; ++i) { | ||
Overlay overlay = overlays_[i]; | ||
if (overlay.addr == k) { | ||
if ((overlay.layer == layer_index) || | ||
(overlay.layer == layer_wildcard)) { | ||
selectedColor = &overlay.color; | ||
return true; | ||
} | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
EventHandlerResult ColormapOverlay::onSetup() { | ||
return EventHandlerResult::OK; | ||
} | ||
|
||
void ColormapOverlay::setKeyboardLEDColors() { | ||
for (auto key_addr : KeyAddr::all()) { | ||
if (ColormapOverlay::hasOverlay(key_addr)) { | ||
::LEDControl.setCrgbAt(KeyAddr(key_addr), *selectedColor); | ||
} else { | ||
::LEDControl.refreshAt(KeyAddr(key_addr)); | ||
} | ||
} | ||
} | ||
|
||
EventHandlerResult ColormapOverlay::afterEachCycle() { | ||
setKeyboardLEDColors(); | ||
|
||
return EventHandlerResult::OK; | ||
} | ||
|
||
} // namespace plugin | ||
} // namespace kaleidoscope | ||
|
||
kaleidoscope::plugin::ColormapOverlay ColormapOverlay; |
82 changes: 82 additions & 0 deletions
82
plugins/Kaleidoscope-Colormap-Overlay/src/kaleidoscope/plugin/Colormap-Overlay.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* Kaleidoscope-Colormap-Overlay - A LED 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 <stdint.h> // for uint8_t | ||
|
||
#include "kaleidoscope/KeyAddr.h" // for KeyAddr | ||
#include "kaleidoscope/device/device.h" // for cRGB | ||
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult | ||
#include "kaleidoscope/key_defs.h" // for Key, KEY_FLAGS, Key_NoKey, LockLayer | ||
#include "kaleidoscope/layers.h" // for Layer, Layer_ | ||
#include "kaleidoscope/plugin/LEDControl.h" // for LEDControl | ||
|
||
namespace kaleidoscope { | ||
namespace plugin { | ||
|
||
// Data structure for an individual qukey | ||
struct Overlay { | ||
// The layer this qukey is mapped on. | ||
int8_t layer; | ||
// The keyswitch address of the qukey. | ||
KeyAddr addr; | ||
// The alternake Key value this qukey should use (when held). | ||
cRGB color; | ||
|
||
// This is the constructor that should be used when creating a Overlay that | ||
// will be used by ColormapOverlay | ||
constexpr Overlay(int8_t layer, KeyAddr k, cRGB color) | ||
: layer(layer), addr(k), color(color) {} | ||
}; | ||
|
||
class ColormapOverlay : public kaleidoscope::Plugin { | ||
public: | ||
// Function for defining the array of overlays. It's a template function that | ||
// takes as its sole argument an array reference of size `_overlay_count`, so | ||
// there's no need to use `sizeof` to calculate the correct size, and pass it | ||
// as a separate parameter. | ||
template<uint8_t _overlay_count> | ||
void configureOverlays(Overlay const (&overlays)[_overlay_count]) { | ||
overlays_ = overlays; | ||
overlay_count_ = _overlay_count; | ||
} | ||
|
||
// A wildcard value for a qukey that exists on every layer. | ||
static constexpr int8_t layer_wildcard{-1}; | ||
|
||
EventHandlerResult onSetup(); | ||
EventHandlerResult afterEachCycle(); | ||
|
||
private: | ||
Overlay const *overlays_; | ||
uint8_t overlay_count_; | ||
cRGB *selectedColor; | ||
|
||
bool hasOverlay(KeyAddr k); | ||
void setKeyboardLEDColors(); | ||
}; | ||
|
||
} // namespace plugin | ||
} // namespace kaleidoscope | ||
|
||
extern kaleidoscope::plugin::ColormapOverlay ColormapOverlay; | ||
|
||
#define COLORMAP_OVERLAYS(overlays...) \ | ||
{ \ | ||
static kaleidoscope::plugin::Overlay const overlays_[] = {overlays}; \ | ||
ColormapOverlay.configureOverlays(overlays_); \ | ||
} |