Skip to content
Open
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
* 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-EEPROM-Settings.h>
#include <Kaleidoscope-LED-Palette-Theme.h>
#include <Kaleidoscope-Colormap-Overlay.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"cpu": {
"fqbn": "keyboardio:gd32:keyboardio_model_100",
"port": ""
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_fqbn: keyboardio:gd32:keyboardio_model_100
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,20 @@
#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
#include <Kaleidoscope-FocusSerial.h> // for Focus
#include <Kaleidoscope-LED-Palette-Theme.h> // for LEDPaletteTheme

namespace kaleidoscope {
namespace plugin {
uint16_t ColormapOverlay::map_base_;

void ColormapOverlay::setup() {
// It appears that a call to ::LEDPaletteTheme.reserveThemes() is needed
// because it's where palette_base_ gets initialized. Since this plugin (and
// possibly others) don't actually use themes, requesting memory for storing
// themes doesn't make much sense. Maybe initialisation of palette_base_
// could be moved to a setup() method, though maybe the palette should be
// split from palette theme altogether?
map_base_ = ::LEDPaletteTheme.reserveThemes(1);
}

Expand Down Expand Up @@ -84,6 +91,60 @@ EventHandlerResult ColormapOverlay::beforeSyncingLeds() {
return EventHandlerResult::OK;
}

EventHandlerResult ColormapOverlay::onFocusEvent(const char *input) {
if (!Runtime.has_leds)
return EventHandlerResult::OK;

const char *cmd = PSTR("colormap.overlay");

if (::Focus.inputMatchesHelp(input))
return ::Focus.printHelp(cmd);

if (!::Focus.inputMatchesCommand(input, cmd))
return EventHandlerResult::OK;

if (::Focus.isEOL()) {
for (uint8_t layer = 0; layer < layer_count; layer++) {
for (uint8_t key_index_ = 0; key_index_ < Runtime.device().numKeys(); key_index_++) {
KeyAddr k = KeyAddr(key_index_);
for (uint8_t overlay_index{0}; overlay_index < overlay_count_; ++overlay_index) {
Overlay overlay = overlays_[overlay_index];
if ((overlay.addr == k) && (overlay.layer == layer)) {
::Focus.send(overlay.palette_index);
}
}
::Focus.send(-1);
}
}
return EventHandlerResult::EVENT_CONSUMED;
}

overlays_ = nullptr;
overlay_count_ = 0;
uint16_t i = 0;
while (!::Focus.isEOL() && (i < (uint16_t)Runtime.device().numKeys() * layer_count)) {
int8_t color_index_;

// Ref: plugins/Kaleidoscope-FocusSerial/src/kaleidoscope/plugin/FocusSerial.h:99-115
// -> No overload for signed integers
// Ref: src/kaleidoscope/device/Base.h:90-92
// -> parseInt() seems to support signed values?
::Focus.read(color_index_);
if (color_index_ >= 0) {
uint8_t key_index_ = i % Runtime.device().numKeys();
uint8_t layer_ = (i - key_index_) / Runtime.device().numKeys();

overlays_[overlay_count_] = Overlay(layer_, KeyAddr(key_index_), color_index_);
overlay_count_++;
}
}
Runtime.storage().commit();

::LEDControl.refreshAll();

return EventHandlerResult::EVENT_CONSUMED;
}

} // namespace plugin
} // namespace kaleidoscope

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class ColormapOverlay : public kaleidoscope::Plugin {
void configureOverlays(uint8_t **overlays) {
// First count how many overlays we'll need
uint8_t count = 0;
for (int layer_ = 0; layer_ < _layer_count; layer_++) {
for (int key_index_ = 0; key_index_ < kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns; key_index_++) {
for (uint8_t layer_ = 0; layer_ < _layer_count; layer_++) {
for (uint8_t key_index_ = 0; key_index_ < kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns; key_index_++) {
int8_t color_index_ = overlays[layer_][key_index_];
if (color_index_ >= 0 && color_index_ < ::LEDPaletteTheme.getPaletteSize() &&
color_index_ != no_color_overlay) {
Expand Down Expand Up @@ -113,12 +113,14 @@ class ColormapOverlay : public kaleidoscope::Plugin {
overlays_ = new_overlays;
overlay_count_ = count;
}

// A wildcard value for an overlay that applies on every layer.
static constexpr int8_t layer_wildcard{-1};
static constexpr int8_t no_color_overlay{-1};

EventHandlerResult onSetup();
EventHandlerResult beforeSyncingLeds();
EventHandlerResult onFocusEvent(const char *input);

~ColormapOverlay() {
if (overlays_ != nullptr) {
Expand All @@ -128,7 +130,7 @@ class ColormapOverlay : public kaleidoscope::Plugin {

private:
static uint16_t map_base_;
Overlay *overlays_;
Overlay *overlays_; // TODO: store overlays in EEPROM
uint8_t overlay_count_;
cRGB selectedColor;

Expand Down
Loading