Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Have ColormapOverlay behave more like Colormap #1427

Merged
merged 8 commits into from
Aug 7, 2024
Merged
Changes from all 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 @@ -24,13 +24,14 @@
#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-LED-Palette-Theme.h> // for LEDPaletteTheme

namespace kaleidoscope {
namespace plugin {

// Data structure for an individual qukey
struct Overlay {
int8_t layer;
uint8_t layer;
KeyAddr addr;
uint8_t palette_index;

Expand All @@ -53,8 +54,24 @@ class ColormapOverlay : public kaleidoscope::Plugin {
overlay_count_ = _overlay_count;
}

// A wildcard value for a qukey that exists on every layer.
template<uint8_t _layer_count>
void configureOverlays(uint8_t **overlays) {
overlays_ = nullptr;
overlay_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_++) {
int8_t color_index_ = overlays[layer_][key_index_];
if (color_index_ >= 0 && color_index_ < ::LEDPaletteTheme.getPaletteSize() &&
color_index_ != no_color_overlay) {
overlays_[overlay_count_] = Overlay(layer_, KeyAddr(key_index_), color_index_);
overlay_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();
Expand All @@ -69,6 +86,36 @@ class ColormapOverlay : public kaleidoscope::Plugin {
void setLEDOverlayColors();
};

// clang-format off

#define COLORMAP_OVERLAYS_MAP(layers...) \
namespace kaleidoscope { \
namespace plugin { \
const int8_t overlays_[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns] = { \
layers \
}; \
ColormapOverlay.configureOverlays(overlays_); \
} /* plugin */ \
} /* kaleidoscope */

#define __IDENTITY__(X) X

#ifdef PER_KEY_DATA_STACKED
#define COLORMAP_OVERLAY_STACKED(...) \
{ \
MAP_LIST(__IDENTITY__, PER_KEY_DATA_STACKED(0, __VA_ARGS__)) \
}
#endif

#ifdef PER_KEY_DATA
#define COLORMAP_OVERLAY(...) \
{ \
MAP_LIST(__IDENTITY__, PER_KEY_DATA(0, __VA_ARGS__)) \
}
#endif

// clang-format on

} // namespace plugin
} // namespace kaleidoscope

Expand Down
Loading