keyboardio/Kaleidoscope-LED-Palette-Theme

Name: Kaleidoscope-LED-Palette-Theme

Owner: Keyboardio

Description: Support plugin for palette-based theme plugins

Created: 2017-05-31 11:08:57.0

Updated: 2018-05-15 05:12:42.0

Pushed: 2018-05-15 05:12:43.0

Homepage: null

Size: 35

Language: C++

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Kaleidoscope-LED-Palette-Theme

status Build Status

A common base for plugins that want to provide themes, or theme-related capabilities, using a 16 color palette. In other words, this is for plugin authors primarily. The primary aim of the plugin is to provide not only a common palette, but tools that make it easier to use it too.

Using the plugin

To use the plugin, one needs to do a bit more than include the header, and tell the firmware to use it. Itself being a mere building block, to use it to its full extent, we need to create our own plugin on top of it.

lude <Kaleidoscope.h>
lude <Kaleidoscope-EEPROM-Settings.h>
lude <Kaleidoscope-LED-Palette-Theme.h>
lude <Kaleidoscope-Focus.h>

space example {

s TestLEDMode : public LEDMode {
lic:
stLEDMode() {}

tected:
id setup(void) final;
id update(void) final;

atic bool focusHook(const char *command);

vate:
atic uint16_t map_base_;


16_t TestLEDMode::map_base_;

 TestLEDMode::setup(void) {
p_base_ = LEDPaletteTheme.reserveThemes(1);


 TestLEDMode::update(void) {
DPaletteTheme.updateHandler(map_base_, 0);



LEDMode::focusHook(const char *command) {
turn LEDPaletteTheme.themeFocusHandler(command, PSTR("testLedMode.map"), map_base_, 1);




ple::TestLEDMode TestLEDMode;

 setup() {
rial.begin(9600);

leidoscope.use(&Focus, &LEDPaletteTheme, &TestLEDMode, &EEPROMSettings);

leidoscope.setup();

PROMSettings.seal();
stLEDMode.activate();

cus.addHook(FOCUS_HOOK_LEDPALETTETHEME);
cus.addHook(FOCUS_HOOK(TestLEDMode.focusHook, "testLEDMode.map"));

This is a simple extension, where it provides a testLEDMode.map Focus command, with which one can set the theme which will be saved to EEPROM.

Plugin methods

The plugin provides the LEDPaletteTheme object, which has the following methods and properties:

.reserveThemes(max_themes)

Reserve space in EEPROM for max_themes. Each key on a theme uses half a byte of space. The function returns the theme_base to be used with the rest of the methods.

The theme_base is a pointer into the EEPROM where the theme storage starts.

.updateHandler(theme_base, theme)

A helper we can call in our plugin's .update() method: given an EEPROM location (theme_base), and a theme index, it will update the keyboard with the colors of the specified theme.

The theme argument can be any index between zero and max_themes. How the plugin decides which theme to display depends entirely on the plugin.

.themeFocusHandler(command, expected_command, theme_base, max_themes)

To be used in a custom Focus handler: handles the expected_command Focus command, and provides a way to query and update the themes supported by the plugin.

When queried, it will list the color indexes. When used as a setter, it expects one index per key.

The palette can be set via the palette focus command, implemented by the FOCUS_HOOK_LEDPALETTETHEME hook explained below.

Focus commands

The plugin provides a single Focus hook, FOCUS_HOOK_LEDPALETTETHEME, implementing the following command:

palette

Without arguments, prints the palette: RGB values for all 16 colors.

With arguments, updates the palette with new colors. One does not need to give the full palette, the plugin will process as many arguments as available, and ignore anything past the last index. It expects colors to have all three components specified, or none at all. Thus, partial palette updates are possible, but only on the color level, not at component level.

Dependencies
Further reading

Starting from the example is the recommended way of getting started with the plugin.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.