Merge pull request #1194 from gedankenexperimenter/plugin-style

Plugin code style standardization
pull/1196/head
Jesse Vincent 3 years ago committed by GitHub
commit cb9ad9f753
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -59,7 +59,7 @@ void setup() {
SPACECADET_MAP_END, SPACECADET_MAP_END,
}; };
//Set the map. //Set the map.
SpaceCadet.map = spacecadetmap; SpaceCadet.setMap(spacecadetmap);
} }
void loop() { void loop() {

@ -29,25 +29,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
// =============================================================================
// AutoShift static class variables
// Configuration settings that can be saved to persistent storage.
AutoShift::Settings AutoShift::settings_ = {
.enabled = true,
.timeout = 175,
.enabled_categories = AutoShift::Categories::printableKeys(),
};
// The event tracker ensures that the `onKeyswitchEvent()` handler will follow
// the rules in order to avoid interference with other plugins and prevent
// processing the same event more than once.
KeyEventTracker AutoShift::event_tracker_;
// If there's a delayed keypress from AutoShift, this stored event will contain
// a valid `KeyAddr`. The default constructor produces an event addr of
// `KeyAddr::none()`, so the plugin will start in an inactive state.
KeyEvent pending_event_;
// ============================================================================= // =============================================================================
// AutoShift functions // AutoShift functions

@ -134,17 +134,17 @@ class AutoShift : public Plugin {
// Configuration functions // Configuration functions
/// Returns `true` if AutoShift is active, `false` otherwise /// Returns `true` if AutoShift is active, `false` otherwise
static bool enabled() { bool enabled() {
return settings_.enabled; return settings_.enabled;
} }
/// Activates the AutoShift plugin (held keys will trigger auto-shift) /// Activates the AutoShift plugin (held keys will trigger auto-shift)
static void enable() { void enable() {
settings_.enabled = true; settings_.enabled = true;
} }
/// Deactivates the AutoShift plugin (held keys will not trigger auto-shift) /// Deactivates the AutoShift plugin (held keys will not trigger auto-shift)
static void disable(); void disable();
/// Turns AutoShift on if it's off, and vice versa /// Turns AutoShift on if it's off, and vice versa
static void toggle() { void toggle() {
if (settings_.enabled) { if (settings_.enabled) {
disable(); disable();
} else { } else {
@ -153,16 +153,16 @@ class AutoShift : public Plugin {
} }
/// Returns the hold time required to trigger auto-shift (in ms) /// Returns the hold time required to trigger auto-shift (in ms)
static uint16_t timeout() { uint16_t timeout() {
return settings_.timeout; return settings_.timeout;
} }
/// Sets the hold time required to trigger auto-shift (in ms) /// Sets the hold time required to trigger auto-shift (in ms)
static void setTimeout(uint16_t new_timeout) { void setTimeout(uint16_t new_timeout) {
settings_.timeout = new_timeout; settings_.timeout = new_timeout;
} }
/// Returns the set of categories currently eligible for auto-shift /// Returns the set of categories currently eligible for auto-shift
static Categories enabledCategories() { Categories enabledCategories() {
return settings_.enabled_categories; return settings_.enabled_categories;
} }
/// Adds `category` to the set eligible for auto-shift /// Adds `category` to the set eligible for auto-shift
@ -175,19 +175,19 @@ class AutoShift : public Plugin {
/// - `AutoShift::Categories::functionKeys()` /// - `AutoShift::Categories::functionKeys()`
/// - `AutoShift::Categories::printableKeys()` /// - `AutoShift::Categories::printableKeys()`
/// - `AutoShift::Categories::allKeys()` /// - `AutoShift::Categories::allKeys()`
static void enable(Categories category) { void enable(Categories category) {
settings_.enabled_categories.add(category); settings_.enabled_categories.add(category);
} }
/// Removes a `Key` category from the set eligible for auto-shift /// Removes a `Key` category from the set eligible for auto-shift
static void disable(Categories category) { void disable(Categories category) {
settings_.enabled_categories.remove(category); settings_.enabled_categories.remove(category);
} }
/// Replaces the list of `Key` categories eligible for auto-shift /// Replaces the list of `Key` categories eligible for auto-shift
static void setEnabled(Categories categories) { void setEnabled(Categories categories) {
settings_.enabled_categories = categories; settings_.enabled_categories = categories;
} }
/// Returns `true` if the given category is eligible for auto-shift /// Returns `true` if the given category is eligible for auto-shift
static bool isEnabled(Categories category) { bool isEnabled(Categories category) {
return settings_.enabled_categories.contains(category); return settings_.enabled_categories.contains(category);
} }
@ -225,7 +225,7 @@ class AutoShift : public Plugin {
/// ///
/// This function can be overridden by the user sketch to configure which keys /// This function can be overridden by the user sketch to configure which keys
/// can trigger auto-shift. /// can trigger auto-shift.
static bool isAutoShiftable(Key key); bool isAutoShiftable(Key key);
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Event handlers // Event handlers
@ -237,19 +237,19 @@ class AutoShift : public Plugin {
/// A container for AutoShift configuration settings /// A container for AutoShift configuration settings
struct Settings { struct Settings {
/// The overall state of the plugin (on/off) /// The overall state of the plugin (on/off)
bool enabled; bool enabled = true;
/// The length of time (ms) a key must be held to trigger auto-shift /// The length of time (ms) a key must be held to trigger auto-shift
uint16_t timeout; uint16_t timeout = 175;
/// The set of `Key` categories eligible to be auto-shifted /// The set of `Key` categories eligible to be auto-shifted
Categories enabled_categories; Categories enabled_categories = AutoShift::Categories::printableKeys();
}; };
static Settings settings_; Settings settings_;
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Key event queue state variables // Key event queue state variables
// A device for processing only new events // A device for processing only new events
static KeyEventTracker event_tracker_; KeyEventTracker event_tracker_;
// The maximum number of events in the queue at a time. // The maximum number of events in the queue at a time.
static constexpr uint8_t queue_capacity_{4}; static constexpr uint8_t queue_capacity_{4};
@ -257,12 +257,17 @@ class AutoShift : public Plugin {
// The event queue stores a series of press and release events. // The event queue stores a series of press and release events.
KeyAddrEventQueue<queue_capacity_> queue_; KeyAddrEventQueue<queue_capacity_> queue_;
// If there's a delayed keypress from AutoShift, this stored event will
// contain a valid `KeyAddr`. The default constructor produces an event addr
// of `KeyAddr::none()`, so the plugin will start in an inactive state.
KeyEvent pending_event_;
void flushQueue(); void flushQueue();
void flushEvent(bool is_long_press = false); void flushEvent(bool is_long_press = false);
bool checkForRelease() const; bool checkForRelease() const;
/// The default function for `isAutoShiftable()` /// The default function for `isAutoShiftable()`
static bool enabledForKey(Key key); bool enabledForKey(Key key);
}; };
// ============================================================================= // =============================================================================
@ -274,7 +279,7 @@ class AutoShiftConfig : public Plugin {
private: private:
// The base address in persistent storage for configuration data // The base address in persistent storage for configuration data
static uint16_t settings_base_; uint16_t settings_base_;
}; };
} // namespace plugin } // namespace plugin

@ -20,7 +20,7 @@
#include <Arduino.h> // for PSTR, strcmp_P, strncmp_P #include <Arduino.h> // for PSTR, strcmp_P, strncmp_P
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings #include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t, uint8_t #include <stdint.h> // for uint8_t, uint16_t
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for VirtualProps::Storage, Base<>::Storage #include "kaleidoscope/device/device.h" // for VirtualProps::Storage, Base<>::Storage
@ -32,20 +32,18 @@ namespace plugin {
// ============================================================================= // =============================================================================
// AutoShift configurator // AutoShift configurator
uint16_t AutoShiftConfig::settings_base_;
EventHandlerResult AutoShiftConfig::onSetup() { EventHandlerResult AutoShiftConfig::onSetup() {
settings_base_ = ::EEPROMSettings.requestSlice(sizeof(AutoShift::settings_)); settings_base_ = ::EEPROMSettings.requestSlice(sizeof(AutoShift::Settings));
if (Runtime.storage().isSliceUninitialized( if (Runtime.storage().isSliceUninitialized(
settings_base_, settings_base_,
sizeof(AutoShift::settings_))) { sizeof(AutoShift::Settings))) {
// If our slice is uninitialized, set sensible defaults. // If our slice is uninitialized, set sensible defaults.
Runtime.storage().put(settings_base_, AutoShift::settings_); Runtime.storage().put(settings_base_, ::AutoShift.settings_);
Runtime.storage().commit(); Runtime.storage().commit();
} }
Runtime.storage().get(settings_base_, AutoShift::settings_); Runtime.storage().get(settings_base_, ::AutoShift.settings_);
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -112,7 +110,7 @@ EventHandlerResult AutoShiftConfig::onFocusEvent(const char *command) {
break; break;
} }
Runtime.storage().put(settings_base_, AutoShift::settings_); Runtime.storage().put(settings_base_, ::AutoShift.settings_);
Runtime.storage().commit(); Runtime.storage().commit();
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }

@ -35,14 +35,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
// =============================================================================
// CharShift class variables
CharShift::KeyPair const *CharShift::progmem_keypairs_{nullptr};
uint8_t CharShift::num_keypairs_{0};
bool CharShift::reverse_shift_state_{false};
// ============================================================================= // =============================================================================
// Event handlers // Event handlers

@ -77,42 +77,42 @@ class CharShift : public Plugin {
/// Generally, it will be called via the `KEYPAIRS()` preprocessor macro, not /// Generally, it will be called via the `KEYPAIRS()` preprocessor macro, not
/// directly by user code. /// directly by user code.
template<uint8_t _num_keypairs> template<uint8_t _num_keypairs>
static void setProgmemKeyPairs(KeyPair const (&keypairs)[_num_keypairs]) { void setProgmemKeyPairs(KeyPair const (&keypairs)[_num_keypairs]) {
progmem_keypairs_ = keypairs; progmem_keypairs_ = keypairs;
num_keypairs_ = _num_keypairs; num_keypairs_ = _num_keypairs;
} }
private: private:
// A pointer to an array of `KeyPair` objects in PROGMEM // A pointer to an array of `KeyPair` objects in PROGMEM
static KeyPair const *progmem_keypairs_; KeyPair const *progmem_keypairs_ = nullptr;
// The size of the PROGMEM array of `KeyPair` objects // The size of the PROGMEM array of `KeyPair` objects
static uint8_t num_keypairs_; uint8_t num_keypairs_ = 0;
// If a `shift` key needs to be suppressed in `beforeReportingState()` // If a `shift` key needs to be suppressed in `beforeReportingState()`
static bool reverse_shift_state_; bool reverse_shift_state_ = false;
/// Test for keys that should be handled by CharShift /// Test for keys that should be handled by CharShift
static bool isCharShiftKey(Key key); bool isCharShiftKey(Key key);
/// Look up the `KeyPair` specified by the given keymap entry /// Look up the `KeyPair` specified by the given keymap entry
static KeyPair decodeCharShiftKey(Key key); KeyPair decodeCharShiftKey(Key key);
/// Get the total number of KeyPairs defined /// Get the total number of KeyPairs defined
/// ///
/// This function can be overridden in order to store the `KeyPair` array in /// This function can be overridden in order to store the `KeyPair` array in
/// EEPROM instead of PROGMEM. /// EEPROM instead of PROGMEM.
static uint8_t numKeyPairs(); uint8_t numKeyPairs();
/// Get the `KeyPair` at the specified index from the defined `KeyPair` array /// Get the `KeyPair` at the specified index from the defined `KeyPair` array
/// ///
/// This function can be overridden in order to store the `KeyPair` array in /// This function can be overridden in order to store the `KeyPair` array in
/// EEPROM instead of PROGMEM. /// EEPROM instead of PROGMEM.
static KeyPair readKeyPair(uint8_t n); KeyPair readKeyPair(uint8_t n);
// Default for `keypairsCount()`: size of the PROGMEM array // Default for `keypairsCount()`: size of the PROGMEM array
static uint8_t numProgmemKeyPairs(); uint8_t numProgmemKeyPairs();
// Default for `readKeypair(i)`: fetch the value from PROGMEM // Default for `readKeypair(i)`: fetch the value from PROGMEM
static KeyPair readKeyPairFromProgmem(uint8_t n); KeyPair readKeyPairFromProgmem(uint8_t n);
}; };
} // namespace plugin } // namespace plugin

@ -28,7 +28,7 @@ KALEIDOSCOPE_INIT_PLUGINS(EEPROMSettings,
ColormapEffect, ColormapEffect,
Focus); Focus);
void setup(void) { void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
ColormapEffect.max_layers(1); ColormapEffect.max_layers(1);

@ -47,7 +47,7 @@ EventHandlerResult ColormapEffect::onNameQuery() {
return ::Focus.sendName(F("ColormapEffect")); return ::Focus.sendName(F("ColormapEffect"));
} }
void ColormapEffect::TransientLEDMode::onActivate(void) { void ColormapEffect::TransientLEDMode::onActivate() {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;

@ -32,8 +32,6 @@ class ColormapEffect : public Plugin,
public LEDModeInterface, public LEDModeInterface,
public AccessTransientLEDMode { public AccessTransientLEDMode {
public: public:
ColormapEffect(void) {}
void max_layers(uint8_t max_); void max_layers(uint8_t max_);
EventHandlerResult onLayerChange(); EventHandlerResult onLayerChange();
@ -54,7 +52,7 @@ class ColormapEffect : public Plugin,
protected: protected:
friend class ColormapEffect; friend class ColormapEffect;
void onActivate(void) final; void onActivate() final;
void refreshAt(KeyAddr key_addr) final; void refreshAt(KeyAddr key_addr) final;
private: private:

@ -34,7 +34,7 @@ void cycleAction(Key previous_key, uint8_t cycle_count) {
KALEIDOSCOPE_INIT_PLUGINS(Cycle); KALEIDOSCOPE_INIT_PLUGINS(Cycle);
void setup(void) { void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
} }
``` ```

@ -31,11 +31,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
// --- state ---
Key Cycle::last_non_cycle_key_;
KeyAddr Cycle::cycle_key_addr_{KeyAddr::invalid_state};
uint8_t Cycle::current_modifier_flags_;
uint8_t Cycle::cycle_count_;
// --- helpers --- // --- helpers ---

@ -38,20 +38,18 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
class Cycle : public kaleidoscope::Plugin { class Cycle : public kaleidoscope::Plugin {
public: public:
Cycle(void) {} void replace(Key key);
void replace(uint8_t cycle_size, const Key cycle_steps[]);
static void replace(Key key);
static void replace(uint8_t cycle_size, const Key cycle_steps[]);
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
private: private:
static uint8_t toModFlag(uint8_t keyCode); uint8_t toModFlag(uint8_t keyCode);
static Key last_non_cycle_key_; Key last_non_cycle_key_;
static KeyAddr cycle_key_addr_; KeyAddr cycle_key_addr_{KeyAddr::invalid_state};
static uint8_t cycle_count_; uint8_t cycle_count_;
static uint8_t current_modifier_flags_; uint8_t current_modifier_flags_;
}; };
} // namespace plugin } // namespace plugin

@ -15,7 +15,7 @@ the box, without any further configuration:
/* ... */ /* ... */
void setup (void) { void setup () {
Kaleidoscope.setup (); Kaleidoscope.setup ();
TRACE() TRACE()
} }

@ -34,12 +34,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
uint16_t DynamicMacros::storage_base_;
uint16_t DynamicMacros::storage_size_;
uint16_t DynamicMacros::map_[];
uint8_t DynamicMacros::macro_count_;
Key DynamicMacros::active_macro_keys_[];
// ============================================================================= // =============================================================================
// It might be possible to use Macros instead of reproducing it // It might be possible to use Macros instead of reproducing it
void DynamicMacros::press(Key key) { void DynamicMacros::press(Key key) {

@ -42,20 +42,20 @@ class DynamicMacros : public kaleidoscope::Plugin {
EventHandlerResult beforeReportingState(const KeyEvent &event); EventHandlerResult beforeReportingState(const KeyEvent &event);
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
static void reserve_storage(uint16_t size); void reserve_storage(uint16_t size);
void play(uint8_t seq_id); void play(uint8_t seq_id);
private: private:
static uint16_t storage_base_; uint16_t storage_base_;
static uint16_t storage_size_; uint16_t storage_size_;
static uint16_t map_[32]; uint16_t map_[32];
static uint8_t macro_count_; uint8_t macro_count_;
static uint8_t updateDynamicMacroCache(); uint8_t updateDynamicMacroCache();
static Key active_macro_keys_[MAX_CONCURRENT_DYNAMIC_MACRO_KEYS]; Key active_macro_keys_[MAX_CONCURRENT_DYNAMIC_MACRO_KEYS];
static void press(Key key); void press(Key key);
static void release(Key key); void release(Key key);
static void tap(Key key); void tap(Key key);
}; };
} // namespace plugin } // namespace plugin

@ -34,13 +34,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
uint16_t DynamicTapDance::storage_base_;
uint16_t DynamicTapDance::storage_size_;
uint16_t DynamicTapDance::map_[];
uint8_t DynamicTapDance::offset_;
uint8_t DynamicTapDance::dance_count_;
constexpr uint8_t DynamicTapDance::reserved_tap_dance_key_count_;
void DynamicTapDance::updateDynamicTapDanceCache() { void DynamicTapDance::updateDynamicTapDanceCache() {
uint16_t pos = storage_base_; uint16_t pos = storage_base_;
uint8_t current_id = 0; uint8_t current_id = 0;

@ -30,23 +30,21 @@ namespace plugin {
class DynamicTapDance : public kaleidoscope::Plugin { class DynamicTapDance : public kaleidoscope::Plugin {
public: public:
DynamicTapDance() {}
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
static void setup(uint8_t dynamic_offset, uint16_t size); void setup(uint8_t dynamic_offset, uint16_t size);
static bool dance(uint8_t tap_dance_index, KeyAddr key_addr, uint8_t tap_count, TapDance::ActionType tap_dance_action); bool dance(uint8_t tap_dance_index, KeyAddr key_addr, uint8_t tap_count, TapDance::ActionType tap_dance_action);
private: private:
static uint16_t storage_base_; uint16_t storage_base_;
static uint16_t storage_size_; uint16_t storage_size_;
static constexpr uint8_t reserved_tap_dance_key_count_ = ranges::TD_LAST - ranges::TD_FIRST + 1; static constexpr uint8_t reserved_tap_dance_key_count_ = ranges::TD_LAST - ranges::TD_FIRST + 1;
static uint16_t map_[reserved_tap_dance_key_count_]; uint16_t map_[reserved_tap_dance_key_count_]; // NOLINT(runtime/arrays)
static uint8_t dance_count_; uint8_t dance_count_;
static uint8_t offset_; uint8_t offset_;
static void updateDynamicTapDanceCache(); void updateDynamicTapDanceCache();
}; };
} // namespace plugin } // namespace plugin

@ -33,12 +33,8 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
uint16_t EEPROMKeymapProgrammer::update_position_;
EEPROMKeymapProgrammer::state_t EEPROMKeymapProgrammer::state_;
EEPROMKeymapProgrammer::mode_t EEPROMKeymapProgrammer::mode;
Key EEPROMKeymapProgrammer::new_key_;
void EEPROMKeymapProgrammer::nextState(void) { void EEPROMKeymapProgrammer::nextState() {
switch (state_) { switch (state_) {
case INACTIVE: case INACTIVE:
state_ = WAIT_FOR_KEY; state_ = WAIT_FOR_KEY;
@ -58,7 +54,7 @@ void EEPROMKeymapProgrammer::nextState(void) {
} }
} }
void EEPROMKeymapProgrammer::cancel(void) { void EEPROMKeymapProgrammer::cancel() {
update_position_ = 0; update_position_ = 0;
new_key_ = Key_NoKey; new_key_ = Key_NoKey;
state_ = INACTIVE; state_ = INACTIVE;

@ -32,15 +32,13 @@ class EEPROMKeymapProgrammer : public kaleidoscope::Plugin {
CODE, CODE,
COPY, COPY,
} mode_t; } mode_t;
static mode_t mode; mode_t mode;
EEPROMKeymapProgrammer(void) {} void activate() {
static void activate(void) {
nextState(); nextState();
} }
static void nextState(void); void nextState();
static void cancel(void); void cancel();
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
@ -52,10 +50,10 @@ class EEPROMKeymapProgrammer : public kaleidoscope::Plugin {
WAIT_FOR_CODE, WAIT_FOR_CODE,
WAIT_FOR_SOURCE_KEY, WAIT_FOR_SOURCE_KEY,
} state_t; } state_t;
static state_t state_; state_t state_;
static uint16_t update_position_; // layer, row, col uint16_t update_position_; // layer, row, col
static Key new_key_; Key new_key_;
}; };
} // namespace plugin } // namespace plugin

@ -82,7 +82,7 @@ Key EEPROMKeymap::getKeyExtended(uint8_t layer, KeyAddr key_addr) {
return getKey(layer - progmem_layers_, key_addr); return getKey(layer - progmem_layers_, key_addr);
} }
uint16_t EEPROMKeymap::keymap_base(void) { uint16_t EEPROMKeymap::keymap_base() {
return keymap_base_; return keymap_base_;
} }

@ -33,8 +33,6 @@ class EEPROMKeymap : public kaleidoscope::Plugin {
EXTEND EXTEND
}; };
EEPROMKeymap(void) {}
EventHandlerResult onSetup(); EventHandlerResult onSetup();
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
@ -43,7 +41,7 @@ class EEPROMKeymap : public kaleidoscope::Plugin {
static void max_layers(uint8_t max); static void max_layers(uint8_t max);
static uint16_t keymap_base(void); static uint16_t keymap_base();
static Key getKey(uint8_t layer, KeyAddr key_addr); static Key getKey(uint8_t layer, KeyAddr key_addr);
static Key getKeyExtended(uint8_t layer, KeyAddr key_addr); static Key getKeyExtended(uint8_t layer, KeyAddr key_addr);
@ -55,7 +53,7 @@ class EEPROMKeymap : public kaleidoscope::Plugin {
static uint8_t max_layers_; static uint8_t max_layers_;
static uint8_t progmem_layers_; static uint8_t progmem_layers_;
static Key parseKey(void); static Key parseKey();
static void printKey(Key key); static void printKey(Key key);
static void dumpKeymap(uint8_t layers, Key (*getkey)(uint8_t, KeyAddr)); static void dumpKeymap(uint8_t layers, Key (*getkey)(uint8_t, KeyAddr));
}; };

@ -30,11 +30,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
struct EEPROMSettings::settings EEPROMSettings::settings_;
bool EEPROMSettings::is_valid_;
bool EEPROMSettings::sealed_;
uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings);
EventHandlerResult EEPROMSettings::onSetup() { EventHandlerResult EEPROMSettings::onSetup() {
Runtime.storage().get(0, settings_); Runtime.storage().get(0, settings_);
@ -70,11 +65,11 @@ EventHandlerResult EEPROMSettings::beforeEachCycle() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
bool EEPROMSettings::isValid(void) { bool EEPROMSettings::isValid() {
return is_valid_; return is_valid_;
} }
uint16_t EEPROMSettings::crc(void) { uint16_t EEPROMSettings::crc() {
if (sealed_) if (sealed_)
return settings_.crc; return settings_.crc;
return 0; return 0;
@ -105,7 +100,7 @@ void EEPROMSettings::ignoreHardcodedLayers(bool value) {
update(); update();
} }
void EEPROMSettings::seal(void) { void EEPROMSettings::seal() {
sealed_ = true; sealed_ = true;
CRCCalculator.finalize(); CRCCalculator.finalize();
@ -146,15 +141,15 @@ uint16_t EEPROMSettings::requestSlice(uint16_t size) {
return start; return start;
} }
void EEPROMSettings::invalidate(void) { void EEPROMSettings::invalidate() {
is_valid_ = false; is_valid_ = false;
} }
uint16_t EEPROMSettings::used(void) { uint16_t EEPROMSettings::used() {
return next_start_; return next_start_;
} }
void EEPROMSettings::update(void) { void EEPROMSettings::update() {
Runtime.storage().put(0, settings_); Runtime.storage().put(0, settings_);
Runtime.storage().commit(); Runtime.storage().commit();
is_valid_ = true; is_valid_ = true;

@ -24,10 +24,17 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
class EEPROMSettings : public kaleidoscope::Plugin { class EEPROMSettings : public kaleidoscope::Plugin {
public: private:
EEPROMSettings(void) {} struct Settings {
uint8_t default_layer : 7;
bool ignore_hardcoded_layers : 1;
uint8_t version;
uint16_t crc;
};
public:
EventHandlerResult onSetup(); EventHandlerResult onSetup();
EventHandlerResult beforeEachCycle(); EventHandlerResult beforeEachCycle();
@ -46,52 +53,44 @@ class EEPROMSettings : public kaleidoscope::Plugin {
* fall back to not using it. */ * fall back to not using it. */
static constexpr uint8_t VERSION_CURRENT = 0x01; static constexpr uint8_t VERSION_CURRENT = 0x01;
static void update(void); void update();
static bool isValid(void); bool isValid();
static void invalidate(void); void invalidate();
static uint8_t version(void) { uint8_t version() {
return settings_.version; return settings_.version;
} }
static uint16_t requestSlice(uint16_t size); uint16_t requestSlice(uint16_t size);
static void seal(void); void seal();
static uint16_t crc(void); uint16_t crc();
static uint16_t used(void); uint16_t used();
static uint8_t default_layer(uint8_t layer); uint8_t default_layer(uint8_t layer);
static uint8_t default_layer() { uint8_t default_layer() {
return settings_.default_layer; return settings_.default_layer;
} }
static void ignoreHardcodedLayers(bool value); void ignoreHardcodedLayers(bool value);
static bool ignoreHardcodedLayers() { bool ignoreHardcodedLayers() {
return settings_.ignore_hardcoded_layers; return settings_.ignore_hardcoded_layers;
} }
private: private:
static constexpr uint8_t IGNORE_HARDCODED_LAYER = 0x7e; static constexpr uint8_t IGNORE_HARDCODED_LAYER = 0x7e;
static uint16_t next_start_;
static bool is_valid_;
static bool sealed_;
static struct settings { uint16_t next_start_ = sizeof(EEPROMSettings::Settings);
uint8_t default_layer : 7; bool is_valid_;
bool ignore_hardcoded_layers : 1; bool sealed_;
uint8_t version;
uint16_t crc; Settings settings_;
} settings_;
}; };
class FocusSettingsCommand : public kaleidoscope::Plugin { class FocusSettingsCommand : public kaleidoscope::Plugin {
public: public:
FocusSettingsCommand() {}
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
}; };
class FocusEEPROMCommand : public kaleidoscope::Plugin { class FocusEEPROMCommand : public kaleidoscope::Plugin {
public: public:
FocusEEPROMCommand() {}
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
}; };

@ -34,10 +34,8 @@ class CRC_ {
public: public:
uint16_t crc = 0; uint16_t crc = 0;
CRC_(void){};
void update(const void *data, uint8_t len); void update(const void *data, uint8_t len);
void finalize(void) { void finalize() {
reflect(16); reflect(16);
} }
void reflect(uint8_t len); void reflect(uint8_t len);

@ -20,7 +20,6 @@
#include <Arduino.h> // for PSTR, F, __FlashStringHelper, strcmp_P #include <Arduino.h> // for PSTR, F, __FlashStringHelper, strcmp_P
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings #include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint16_t
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
#include "kaleidoscope/device/device.h" // for VirtualProps::Storage, Base<>::Storage #include "kaleidoscope/device/device.h" // for VirtualProps::Storage, Base<>::Storage
@ -30,20 +29,18 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
uint16_t EscapeOneShotConfig::settings_base_;
EventHandlerResult EscapeOneShotConfig::onSetup() { EventHandlerResult EscapeOneShotConfig::onSetup() {
settings_base_ = ::EEPROMSettings.requestSlice(sizeof(EscapeOneShot::settings_)); settings_base_ = ::EEPROMSettings.requestSlice(sizeof(EscapeOneShot::settings_));
if (Runtime.storage().isSliceUninitialized( if (Runtime.storage().isSliceUninitialized(
settings_base_, settings_base_,
sizeof(EscapeOneShot::settings_))) { sizeof(EscapeOneShot::Settings))) {
// If our slice is uninitialized, set sensible defaults. // If our slice is uninitialized, set sensible defaults.
Runtime.storage().put(settings_base_, EscapeOneShot::settings_); Runtime.storage().put(settings_base_, ::EscapeOneShot.settings_);
Runtime.storage().commit(); Runtime.storage().commit();
} }
Runtime.storage().get(settings_base_, EscapeOneShot::settings_); Runtime.storage().get(settings_base_, ::EscapeOneShot.settings_);
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -66,7 +63,7 @@ EventHandlerResult EscapeOneShotConfig::onFocusEvent(const char *command) {
::EscapeOneShot.setCancelKey(k); ::EscapeOneShot.setCancelKey(k);
} }
Runtime.storage().put(settings_base_, EscapeOneShot::settings_); Runtime.storage().put(settings_base_, ::EscapeOneShot.settings_);
Runtime.storage().commit(); Runtime.storage().commit();
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }

@ -21,15 +21,12 @@
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerResult::E... #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult, EventHandlerResult::E...
#include "kaleidoscope/key_defs.h" // for Key, Key_Escape, Key_NoKey #include "kaleidoscope/key_defs.h" // for Key, Key_NoKey
#include "kaleidoscope/keyswitch_state.h" // for keyIsInjected, keyToggledOn #include "kaleidoscope/keyswitch_state.h" // for keyIsInjected, keyToggledOn
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
EscapeOneShot::Settings EscapeOneShot::settings_ = {
.cancel_oneshot_key = Key_Escape};
EventHandlerResult EscapeOneShot::onKeyEvent(KeyEvent &event) { EventHandlerResult EscapeOneShot::onKeyEvent(KeyEvent &event) {
// We only act on an escape key (or `cancel_oneshot_key_`, if that has been // We only act on an escape key (or `cancel_oneshot_key_`, if that has been
// set) that has just been pressed, and not generated by some other // set) that has just been pressed, and not generated by some other

@ -22,7 +22,7 @@
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/key_defs.h" // for Key #include "kaleidoscope/key_defs.h" // for Key, Key_Escape
#include "kaleidoscope/plugin.h" // for Plugin #include "kaleidoscope/plugin.h" // for Plugin
// DEPRECATED: `OneShotCancelKey` doesn't match our normal naming, and should // DEPRECATED: `OneShotCancelKey` doesn't match our normal naming, and should
@ -35,14 +35,12 @@ namespace plugin {
class EscapeOneShot : public kaleidoscope::Plugin { class EscapeOneShot : public kaleidoscope::Plugin {
public: public:
EscapeOneShot(void) {}
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
static void setCancelKey(Key cancel_key) { void setCancelKey(Key cancel_key) {
settings_.cancel_oneshot_key = cancel_key; settings_.cancel_oneshot_key = cancel_key;
} }
static Key getCancelKey() { Key getCancelKey() {
return settings_.cancel_oneshot_key; return settings_.cancel_oneshot_key;
} }
@ -52,7 +50,7 @@ class EscapeOneShot : public kaleidoscope::Plugin {
struct Settings { struct Settings {
Key cancel_oneshot_key; Key cancel_oneshot_key;
}; };
static Settings settings_; Settings settings_ = {.cancel_oneshot_key = Key_Escape};
}; };
class EscapeOneShotConfig : public Plugin { class EscapeOneShotConfig : public Plugin {
@ -62,7 +60,7 @@ class EscapeOneShotConfig : public Plugin {
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
private: private:
static uint16_t settings_base_; uint16_t settings_base_;
}; };
} // namespace plugin } // namespace plugin

@ -33,9 +33,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
uint16_t FingerPainter::color_base_;
bool FingerPainter::edit_mode_;
EventHandlerResult FingerPainter::onNameQuery() { EventHandlerResult FingerPainter::onNameQuery() {
return ::Focus.sendName(F("FingerPainter")); return ::Focus.sendName(F("FingerPainter"));
} }
@ -45,7 +42,7 @@ EventHandlerResult FingerPainter::onSetup() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
void FingerPainter::update(void) { void FingerPainter::update() {
::LEDPaletteTheme.updateHandler(color_base_, 0); ::LEDPaletteTheme.updateHandler(color_base_, 0);
} }
@ -53,7 +50,7 @@ void FingerPainter::refreshAt(KeyAddr key_addr) {
::LEDPaletteTheme.refreshAt(color_base_, 0, key_addr); ::LEDPaletteTheme.refreshAt(color_base_, 0, key_addr);
} }
void FingerPainter::toggle(void) { void FingerPainter::toggle() {
edit_mode_ = !edit_mode_; edit_mode_ = !edit_mode_;
} }

@ -33,9 +33,7 @@ namespace plugin {
// //
class FingerPainter : public LEDMode { class FingerPainter : public LEDMode {
public: public:
FingerPainter(void) {} void toggle();
static void toggle(void);
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
@ -43,12 +41,12 @@ class FingerPainter : public LEDMode {
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
protected: protected:
void update(void) final; void update() final;
void refreshAt(KeyAddr key_addr) final; void refreshAt(KeyAddr key_addr) final;
private: private:
static uint16_t color_base_; uint16_t color_base_;
static bool edit_mode_; bool edit_mode_;
}; };
} // namespace plugin } // namespace plugin

@ -33,8 +33,6 @@ namespace plugin {
class FirmwareDump : public kaleidoscope::Plugin { class FirmwareDump : public kaleidoscope::Plugin {
public: public:
FirmwareDump() {}
EventHandlerResult onSetup(); EventHandlerResult onSetup();
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);

@ -20,8 +20,6 @@ Nevertheless, a very simple example is shown below:
namespace kaleidoscope { namespace kaleidoscope {
class FocusTestCommand : public Plugin { class FocusTestCommand : public Plugin {
public: public:
FocusTestCommand() {}
EventHandlerResult onNameQuery() { EventHandlerResult onNameQuery() {
return ::Focus.sendName(F("FocusTestCommand")); return ::Focus.sendName(F("FocusTestCommand"));
} }

@ -19,7 +19,6 @@
#include <Arduino.h> // for PSTR, __FlashStringHelper, F, strcmp_P #include <Arduino.h> // for PSTR, __FlashStringHelper, F, strcmp_P
#include <HardwareSerial.h> // for HardwareSerial #include <HardwareSerial.h> // for HardwareSerial
#include <stdint.h> // for uint8_t
#include <string.h> // for memset #include <string.h> // for memset
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_
@ -33,9 +32,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
char FocusSerial::command_[32];
uint8_t FocusSerial::buf_cursor_ = 0;
EventHandlerResult FocusSerial::afterEachCycle() { EventHandlerResult FocusSerial::afterEachCycle() {
// GD32 doesn't currently autoflush the very last packet. So manually flush here // GD32 doesn't currently autoflush the very last packet. So manually flush here
Runtime.serialPort().flush(); Runtime.serialPort().flush();

@ -33,8 +33,6 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
class FocusSerial : public kaleidoscope::Plugin { class FocusSerial : public kaleidoscope::Plugin {
public: public:
FocusSerial(void) {}
static constexpr char COMMENT = '#'; static constexpr char COMMENT = '#';
static constexpr char SEPARATOR = ' '; static constexpr char SEPARATOR = ' ';
static constexpr char NEWLINE = '\n'; static constexpr char NEWLINE = '\n';
@ -115,15 +113,15 @@ class FocusSerial : public kaleidoscope::Plugin {
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
private: private:
static char command_[32]; char command_[32];
static uint8_t buf_cursor_; uint8_t buf_cursor_ = 0;
static void printBool(bool b); void printBool(bool b);
// This is a hacky workaround for the host seemingly dropping characters // This is a hacky workaround for the host seemingly dropping characters
// when a client spams its serial port too quickly // when a client spams its serial port too quickly
// Verified on GD32 and macOS 12.3 2022-03-29 // Verified on GD32 and macOS 12.3 2022-03-29
static constexpr uint8_t focus_delay_us_after_character_ = 100; static constexpr uint8_t focus_delay_us_after_character_ = 100;
static void delayAfterPrint() { delayMicroseconds(focus_delay_us_after_character_); } void delayAfterPrint() { delayMicroseconds(focus_delay_us_after_character_); }
}; };
} // namespace plugin } // namespace plugin

@ -28,12 +28,8 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
const GhostInTheFirmware::GhostKey *GhostInTheFirmware::ghost_keys;
bool GhostInTheFirmware::is_active_ = false;
uint16_t GhostInTheFirmware::current_pos_ = 0;
uint16_t GhostInTheFirmware::start_time_;
void GhostInTheFirmware::activate(void) { void GhostInTheFirmware::activate() {
is_active_ = true; is_active_ = true;
} }

@ -32,18 +32,16 @@ class GhostInTheFirmware : public kaleidoscope::Plugin {
uint16_t press_time; uint16_t press_time;
uint16_t delay; uint16_t delay;
}; };
static const GhostKey *ghost_keys; const GhostKey *ghost_keys;
GhostInTheFirmware(void) {} void activate();
static void activate(void);
EventHandlerResult afterEachCycle(); EventHandlerResult afterEachCycle();
private: private:
static bool is_active_; bool is_active_ = false;
static uint16_t current_pos_; uint16_t current_pos_ = 0;
static uint16_t start_time_; uint16_t start_time_;
}; };
} // namespace plugin } // namespace plugin

@ -38,15 +38,9 @@ namespace kaleidoscope {
namespace device { namespace device {
namespace ez { namespace ez {
ErgoDoxScanner ErgoDox::scanner_;
uint8_t ErgoDox::previousKeyState_[matrix_rows];
uint8_t ErgoDox::keyState_[matrix_rows];
uint8_t ErgoDox::debounce_matrix_[matrix_rows][matrix_columns];
uint8_t ErgoDox::debounce = 5;
static bool do_scan_ = 1; static bool do_scan_ = 1;
void ErgoDox::setup(void) { void ErgoDox::setup() {
wdt_disable(); wdt_disable();
delay(100); delay(100);

@ -60,11 +60,9 @@ struct ErgoDoxProps : public kaleidoscope::device::ATmega32U4KeyboardProps {
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class ErgoDox : public kaleidoscope::device::ATmega32U4Keyboard<ErgoDoxProps> { class ErgoDox : public kaleidoscope::device::ATmega32U4Keyboard<ErgoDoxProps> {
public: public:
ErgoDox(void) {} void scanMatrix();
void readMatrix();
void scanMatrix(void); void actOnMatrixScan();
void readMatrix(void);
void actOnMatrixScan(void);
void setup(); void setup();
bool isKeyswitchPressed(KeyAddr key_addr); bool isKeyswitchPressed(KeyAddr key_addr);
@ -80,17 +78,17 @@ class ErgoDox : public kaleidoscope::device::ATmega32U4Keyboard<ErgoDoxProps> {
void setStatusLED(uint8_t led, bool state = true); void setStatusLED(uint8_t led, bool state = true);
void setStatusLEDBrightness(uint8_t led, uint8_t brightness); void setStatusLEDBrightness(uint8_t led, uint8_t brightness);
static uint8_t debounce; uint8_t debounce = 5;
private: private:
static ErgoDoxScanner scanner_; ErgoDoxScanner scanner_;
static uint8_t previousKeyState_[matrix_rows]; uint8_t previousKeyState_[matrix_rows]; // NOLINT(runtime/arrays)
static uint8_t keyState_[matrix_rows]; uint8_t keyState_[matrix_rows]; // NOLINT(runtime/arrays)
static uint8_t debounce_matrix_[matrix_rows][matrix_columns]; uint8_t debounce_matrix_[matrix_rows][matrix_columns];
static uint8_t debounceMaskForRow(uint8_t row); uint8_t debounceMaskForRow(uint8_t row);
static void debounceRow(uint8_t change, uint8_t row); void debounceRow(uint8_t change, uint8_t row);
static void readMatrixRow(uint8_t row); void readMatrixRow(uint8_t row);
}; };
#else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD #else // ifndef KALEIDOSCOPE_VIRTUAL_BUILD
class ErgoDox; class ErgoDox;

@ -35,8 +35,6 @@ namespace ez {
class ErgoDoxScanner { class ErgoDoxScanner {
public: public:
ErgoDoxScanner() {}
void begin(); void begin();
void toggleATMegaRow(int row); void toggleATMegaRow(int row);
void selectExtenderRow(int row); void selectExtenderRow(int row);

@ -102,7 +102,7 @@ void ImagoLEDDriver::twiSend(uint8_t addr, uint8_t Reg_Add, uint8_t Reg_Dat) {
uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0); uint8_t result = twi_writeTo(addr, data, ELEMENTS(data), 1, 0);
} }
void ImagoLEDDriver::unlockRegister(void) { void ImagoLEDDriver::unlockRegister() {
twiSend(LED_DRIVER_ADDR, CMD_WRITE_ENABLE, WRITE_ENABLE_ONCE); //unlock twiSend(LED_DRIVER_ADDR, CMD_WRITE_ENABLE, WRITE_ENABLE_ONCE); //unlock
} }

@ -56,7 +56,7 @@ struct Model01Hands {
driver::keyboardio::Model01Side Model01Hands::leftHand(0); driver::keyboardio::Model01Side Model01Hands::leftHand(0);
driver::keyboardio::Model01Side Model01Hands::rightHand(3); driver::keyboardio::Model01Side Model01Hands::rightHand(3);
void Model01Hands::setup(void) { void Model01Hands::setup() {
// This lets the keyboard pull up to 1.6 amps from the host. // This lets the keyboard pull up to 1.6 amps from the host.
// That violates the USB spec. But it sure is pretty looking // That violates the USB spec. But it sure is pretty looking
DDRE |= _BV(6); DDRE |= _BV(6);
@ -149,7 +149,7 @@ driver::keyboardio::keydata_t Model01KeyScanner::rightHandState;
driver::keyboardio::keydata_t Model01KeyScanner::previousLeftHandState; driver::keyboardio::keydata_t Model01KeyScanner::previousLeftHandState;
driver::keyboardio::keydata_t Model01KeyScanner::previousRightHandState; driver::keyboardio::keydata_t Model01KeyScanner::previousRightHandState;
void Model01KeyScanner::enableScannerPower(void) { void Model01KeyScanner::enableScannerPower() {
// Turn on power to the LED net // Turn on power to the LED net
DDRC |= _BV(7); DDRC |= _BV(7);
PORTC |= _BV(7); PORTC |= _BV(7);

@ -44,7 +44,7 @@ struct Model100Hands {
driver::keyboardio::Model100Side Model100Hands::leftHand(0); driver::keyboardio::Model100Side Model100Hands::leftHand(0);
driver::keyboardio::Model100Side Model100Hands::rightHand(3); driver::keyboardio::Model100Side Model100Hands::rightHand(3);
void Model100Hands::setup(void) { void Model100Hands::setup() {
Model100KeyScanner::enableScannerPower(); Model100KeyScanner::enableScannerPower();
Wire.begin(); Wire.begin();
Wire.setClock(400000); Wire.setClock(400000);
@ -123,7 +123,7 @@ driver::keyboardio::keydata_t Model100KeyScanner::rightHandState;
driver::keyboardio::keydata_t Model100KeyScanner::previousLeftHandState; driver::keyboardio::keydata_t Model100KeyScanner::previousLeftHandState;
driver::keyboardio::keydata_t Model100KeyScanner::previousRightHandState; driver::keyboardio::keydata_t Model100KeyScanner::previousRightHandState;
void Model100KeyScanner::enableScannerPower(void) { void Model100KeyScanner::enableScannerPower() {
// Turn on the switched 5V network. // Turn on the switched 5V network.
// make sure this happens at least 100ms after USB connect // make sure this happens at least 100ms after USB connect
// to satisfy inrush limits // to satisfy inrush limits
@ -137,7 +137,7 @@ void Model100KeyScanner::enableScannerPower(void) {
digitalWrite(PB15, LOW); digitalWrite(PB15, LOW);
} }
void Model100KeyScanner::disableScannerPower(void) { void Model100KeyScanner::disableScannerPower() {
// Turn on power to the 5V net // Turn on power to the 5V net
// //
pinMode(PB9, OUTPUT_OPEN_DRAIN); pinMode(PB9, OUTPUT_OPEN_DRAIN);

@ -53,7 +53,7 @@ void HardwareTestMode::setLeds(cRGB color) {
waitForKeypress(); waitForKeypress();
} }
void HardwareTestMode::testLeds(void) { void HardwareTestMode::testLeds() {
constexpr cRGB red = CRGB(255, 0, 0); constexpr cRGB red = CRGB(255, 0, 0);
constexpr cRGB blue = CRGB(0, 0, 255); constexpr cRGB blue = CRGB(0, 0, 255);
constexpr cRGB green = CRGB(0, 255, 0); constexpr cRGB green = CRGB(0, 255, 0);

@ -33,8 +33,6 @@ class HardwareTestMode : public kaleidoscope::Plugin {
} chatter_data; } chatter_data;
static uint8_t actionKey; static uint8_t actionKey;
HardwareTestMode(void) {}
static void runTests(); static void runTests();
static void setActionKey(uint8_t key); static void setActionKey(uint8_t key);

@ -107,7 +107,7 @@ cRGB Heatmap::TransientLEDMode::computeColor(float v) {
return {b, g, r}; return {b, g, r};
} }
void Heatmap::TransientLEDMode::shiftStats(void) { void Heatmap::TransientLEDMode::shiftStats() {
// this method is called when: // this method is called when:
// 1. a value in heatmap_ reach INT8_MAX // 1. a value in heatmap_ reach INT8_MAX
// 2. highest_ reach heat_colors_length*512 (see Heatmap::loopHook) // 2. highest_ reach heat_colors_length*512 (see Heatmap::loopHook)
@ -121,7 +121,7 @@ void Heatmap::TransientLEDMode::shiftStats(void) {
highest_ = highest_ >> 1; highest_ = highest_ >> 1;
} }
void Heatmap::resetMap(void) { void Heatmap::resetMap() {
if (::LEDControl.get_mode_index() != led_mode_id_) if (::LEDControl.get_mode_index() != led_mode_id_)
return; return;
@ -210,7 +210,7 @@ EventHandlerResult Heatmap::TransientLEDMode::beforeEachCycle() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
void Heatmap::TransientLEDMode::update(void) { void Heatmap::TransientLEDMode::update() {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;

@ -34,12 +34,10 @@ class Heatmap : public Plugin,
public LEDModeInterface, public LEDModeInterface,
public AccessTransientLEDMode { public AccessTransientLEDMode {
public: public:
Heatmap(void) {}
static uint16_t update_delay; static uint16_t update_delay;
static const cRGB *heat_colors; static const cRGB *heat_colors;
static uint8_t heat_colors_length; static uint8_t heat_colors_length;
void resetMap(void); void resetMap();
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
EventHandlerResult beforeEachCycle(); EventHandlerResult beforeEachCycle();
@ -66,7 +64,7 @@ class Heatmap : public Plugin,
uint16_t highest_; uint16_t highest_;
uint16_t last_heatmap_comp_time_; uint16_t last_heatmap_comp_time_;
void shiftStats(void); void shiftStats();
cRGB computeColor(float v); cRGB computeColor(float v);
friend class Heatmap; friend class Heatmap;

@ -21,7 +21,7 @@ The extension provides a `HostOS` singleton object.
#include <Kaleidoscope.h> #include <Kaleidoscope.h>
#include <Kaleidoscope-HostOS.h> #include <Kaleidoscope-HostOS.h>
void someFunction(void) { void someFunction() {
if (HostOS.os() == kaleidoscope::hostos::LINUX) { if (HostOS.os() == kaleidoscope::hostos::LINUX) {
// do something linux-y // do something linux-y
} }
@ -32,7 +32,7 @@ void someFunction(void) {
KALEIDOSCOPE_INIT_PLUGINS(HostOS) KALEIDOSCOPE_INIT_PLUGINS(HostOS)
void setup(void) { void setup() {
Kaleidoscope.setup (); Kaleidoscope.setup ();
} }
``` ```

@ -25,7 +25,6 @@ namespace plugin {
class FocusHostOSCommand : public kaleidoscope::Plugin { class FocusHostOSCommand : public kaleidoscope::Plugin {
public: public:
FocusHostOSCommand() {}
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
}; };

@ -26,7 +26,7 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
EventHandlerResult HostOS::onSetup(void) { EventHandlerResult HostOS::onSetup() {
if (is_configured_) if (is_configured_)
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -41,10 +41,9 @@ typedef enum {
class HostOS : public kaleidoscope::Plugin { class HostOS : public kaleidoscope::Plugin {
public: public:
HostOS() {}
EventHandlerResult onSetup(); EventHandlerResult onSetup();
hostos::Type os(void) { hostos::Type os() {
return os_; return os_;
} }
void os(hostos::Type new_os); void os(hostos::Type new_os);

@ -30,8 +30,6 @@ class HostPowerManagement : public kaleidoscope::Plugin {
Resume, Resume,
} Event; } Event;
HostPowerManagement(void) {}
EventHandlerResult beforeEachCycle(); EventHandlerResult beforeEachCycle();
private: private:

@ -25,7 +25,7 @@ the box, without any further configuration:
KALEIDOSCOPE_INIT_PLUGINS(LEDControl, IdleLEDs, LEDEffectRainbowWave); KALEIDOSCOPE_INIT_PLUGINS(LEDControl, IdleLEDs, LEDEffectRainbowWave);
void setup (void) { void setup () {
Kaleidoscope.setup (); Kaleidoscope.setup ();
} }
``` ```
@ -54,7 +54,7 @@ KALEIDOSCOPE_INIT_PLUGINS(
LEDEffectRainbowWave LEDEffectRainbowWave
); );
void setup (void) { void setup () {
Kaleidoscope.setup (); Kaleidoscope.setup ();
} }
``` ```

@ -29,8 +29,6 @@ namespace plugin {
class IdleLEDs : public kaleidoscope::Plugin { class IdleLEDs : public kaleidoscope::Plugin {
public: public:
IdleLEDs(void) {}
static uint32_t idle_time_limit; static uint32_t idle_time_limit;
static uint32_t idleTimeoutSeconds(); static uint32_t idleTimeoutSeconds();

@ -52,7 +52,7 @@ cRGB LEDActiveLayerColorEffect::TransientLEDMode::getActiveColor() {
return color; return color;
} }
void LEDActiveLayerColorEffect::TransientLEDMode::onActivate(void) { void LEDActiveLayerColorEffect::TransientLEDMode::onActivate() {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;

@ -31,8 +31,6 @@ class LEDActiveLayerColorEffect : public Plugin,
public LEDModeInterface, public LEDModeInterface,
public AccessTransientLEDMode { public AccessTransientLEDMode {
public: public:
LEDActiveLayerColorEffect(void) {}
EventHandlerResult onLayerChange(); EventHandlerResult onLayerChange();
void setColormap(const cRGB colormap[]); void setColormap(const cRGB colormap[]);
@ -47,7 +45,7 @@ class LEDActiveLayerColorEffect : public Plugin,
explicit TransientLEDMode(const LEDActiveLayerColorEffect *parent); explicit TransientLEDMode(const LEDActiveLayerColorEffect *parent);
protected: protected:
void onActivate(void) final; void onActivate() final;
void refreshAt(KeyAddr key_addr) final; void refreshAt(KeyAddr key_addr) final;
private: private:

@ -29,8 +29,6 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
class ActiveModColorEffect : public kaleidoscope::Plugin { class ActiveModColorEffect : public kaleidoscope::Plugin {
public: public:
ActiveModColorEffect(void) {}
static void setHighlightColor(cRGB color) { static void setHighlightColor(cRGB color) {
highlight_color_ = color; highlight_color_ = color;
} }

@ -41,8 +41,6 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
class AlphaSquare : public kaleidoscope::Plugin { class AlphaSquare : public kaleidoscope::Plugin {
public: public:
AlphaSquare(void) {}
static void display(Key key, KeyAddr key_addr, cRGB key_color); static void display(Key key, KeyAddr key_addr, cRGB key_color);
static void display(Key key, KeyAddr key_addr); static void display(Key key, KeyAddr key_addr);
static void display(Key key) { static void display(Key key) {

@ -38,7 +38,7 @@ AlphaSquareEffect::TransientLEDMode::TransientLEDMode(AlphaSquareEffect * /*pare
: last_key_left_(Key_NoKey), : last_key_left_(Key_NoKey),
last_key_right_(Key_NoKey) {} last_key_right_(Key_NoKey) {}
void AlphaSquareEffect::TransientLEDMode::update(void) { void AlphaSquareEffect::TransientLEDMode::update() {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;

@ -34,8 +34,6 @@ class AlphaSquareEffect : public Plugin,
public LEDModeInterface, public LEDModeInterface,
public AccessTransientLEDMode { public AccessTransientLEDMode {
public: public:
AlphaSquareEffect(void) {}
static uint16_t length; static uint16_t length;
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
@ -47,7 +45,7 @@ class AlphaSquareEffect : public Plugin,
explicit TransientLEDMode(AlphaSquareEffect *parent); explicit TransientLEDMode(AlphaSquareEffect *parent);
protected: protected:
void update(void) final; void update() final;
void refreshAt(KeyAddr key_addr) final; void refreshAt(KeyAddr key_addr) final;
private: private:

@ -20,12 +20,9 @@ full extent, we need to create our own plugin on top of it.
namespace example { namespace example {
class TestLEDMode : public LEDMode { class TestLEDMode : public LEDMode {
public:
TestLEDMode() {}
protected: protected:
void setup(void) final; void setup() final;
void update(void) final; void update() final;
kaleidoscope::EventHandlerResult onFocusEvent(const char *command); kaleidoscope::EventHandlerResult onFocusEvent(const char *command);
@ -35,11 +32,11 @@ class TestLEDMode : public LEDMode {
uint16_t TestLEDMode::map_base_; uint16_t TestLEDMode::map_base_;
void TestLEDMode::setup(void) { void TestLEDMode::setup() {
map_base_ = LEDPaletteTheme.reserveThemes(1); map_base_ = LEDPaletteTheme.reserveThemes(1);
} }
void TestLEDMode::update(void) { void TestLEDMode::update() {
LEDPaletteTheme.updateHandler(map_base_, 0); LEDPaletteTheme.updateHandler(map_base_, 0);
} }

@ -29,8 +29,6 @@ namespace plugin {
class LEDPaletteTheme : public kaleidoscope::Plugin { class LEDPaletteTheme : public kaleidoscope::Plugin {
public: public:
LEDPaletteTheme(void) {}
static uint16_t reserveThemes(uint8_t max_themes); static uint16_t reserveThemes(uint8_t max_themes);
static void updateHandler(uint16_t theme_base, uint8_t theme); static void updateHandler(uint16_t theme_base, uint8_t theme);
static void refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_addr); static void refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_addr);

@ -59,7 +59,7 @@ EventHandlerResult StalkerEffect::onKeyEvent(KeyEvent &event) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
void StalkerEffect::TransientLEDMode::update(void) { void StalkerEffect::TransientLEDMode::update() {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;
@ -111,7 +111,7 @@ cRGB Haunt::compute(uint8_t *step) {
} }
// BlazingTrail // BlazingTrail
BlazingTrail::BlazingTrail(void) { BlazingTrail::BlazingTrail() {
} }
constexpr uint8_t hue_start = 50.0 / 360 * 0xff; constexpr uint8_t hue_start = 50.0 / 360 * 0xff;
constexpr uint8_t hue_end = 0; constexpr uint8_t hue_end = 0;
@ -144,7 +144,7 @@ cRGB BlazingTrail::compute(uint8_t *step) {
} }
// Rainbow // Rainbow
Rainbow::Rainbow(void) { Rainbow::Rainbow() {
} }
cRGB Rainbow::compute(uint8_t *step) { cRGB Rainbow::compute(uint8_t *step) {

@ -41,8 +41,6 @@ class StalkerEffect : public Plugin,
virtual cRGB compute(uint8_t *step) = 0; virtual cRGB compute(uint8_t *step) = 0;
}; };
StalkerEffect(void) {}
static ColorComputer *variant; static ColorComputer *variant;
static uint16_t step_length; static uint16_t step_length;
static cRGB inactive_color; static cRGB inactive_color;
@ -77,7 +75,7 @@ namespace stalker {
class Haunt : public StalkerEffect::ColorComputer { class Haunt : public StalkerEffect::ColorComputer {
public: public:
explicit Haunt(const cRGB highlight_color); explicit Haunt(const cRGB highlight_color);
Haunt(void) Haunt()
: Haunt(CRGB(0x40, 0x80, 0x80)) {} : Haunt(CRGB(0x40, 0x80, 0x80)) {}
cRGB compute(uint8_t *step) final; cRGB compute(uint8_t *step) final;
@ -88,14 +86,14 @@ class Haunt : public StalkerEffect::ColorComputer {
class BlazingTrail : public StalkerEffect::ColorComputer { class BlazingTrail : public StalkerEffect::ColorComputer {
public: public:
BlazingTrail(void); BlazingTrail();
cRGB compute(uint8_t *step) final; cRGB compute(uint8_t *step) final;
}; };
class Rainbow : public StalkerEffect::ColorComputer { class Rainbow : public StalkerEffect::ColorComputer {
public: public:
Rainbow(void); Rainbow();
cRGB compute(uint8_t *step) final; cRGB compute(uint8_t *step) final;
}; };

@ -96,7 +96,7 @@ uint8_t WavepoolEffect::TransientLEDMode::wp_rand() {
return (Runtime.millisAtCycleStart() / MS_PER_FRAME) + pgm_read_byte((const uint8_t *)offset); return (Runtime.millisAtCycleStart() / MS_PER_FRAME) + pgm_read_byte((const uint8_t *)offset);
} }
void WavepoolEffect::TransientLEDMode::update(void) { void WavepoolEffect::TransientLEDMode::update() {
// limit the frame rate; one frame every 64 ms // limit the frame rate; one frame every 64 ms
static uint8_t prev_time = 0; static uint8_t prev_time = 0;

@ -41,8 +41,6 @@ class WavepoolEffect : public Plugin,
public LEDModeInterface, public LEDModeInterface,
public AccessTransientLEDMode { public AccessTransientLEDMode {
public: public:
WavepoolEffect(void) {}
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
// ms before idle animation starts after last keypress // ms before idle animation starts after last keypress

@ -28,8 +28,6 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
class BootAnimationEffect : public kaleidoscope::Plugin { class BootAnimationEffect : public kaleidoscope::Plugin {
public: public:
BootAnimationEffect(void) {}
static uint16_t timeout; static uint16_t timeout;
static cRGB color; static cRGB color;

@ -43,7 +43,7 @@ BootGreetingEffect::BootGreetingEffect(KeyAddr key_addr) {
user_key_addr = key_addr; user_key_addr = key_addr;
} }
void BootGreetingEffect::findLed(void) { void BootGreetingEffect::findLed() {
if (user_key_addr.isValid()) { if (user_key_addr.isValid()) {
key_addr_ = user_key_addr; key_addr_ = user_key_addr;
done_ = true; done_ = true;

@ -40,7 +40,7 @@ class BootGreetingEffect : public kaleidoscope::Plugin {
EventHandlerResult afterEachCycle(); EventHandlerResult afterEachCycle();
private: private:
static void findLed(void); static void findLed();
static bool done_; static bool done_;
static KeyAddr key_addr_; static KeyAddr key_addr_;
static uint16_t start_time; static uint16_t start_time;

@ -25,7 +25,7 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
void LEDBreatheEffect::TransientLEDMode::update(void) { void LEDBreatheEffect::TransientLEDMode::update() {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;

@ -27,8 +27,6 @@ namespace plugin {
class LEDBreatheEffect : public Plugin, class LEDBreatheEffect : public Plugin,
public LEDModeInterface { public LEDModeInterface {
public: public:
LEDBreatheEffect(void) {}
uint8_t hue = 170; uint8_t hue = 170;
uint8_t saturation = 255; uint8_t saturation = 255;
@ -44,7 +42,7 @@ class LEDBreatheEffect : public Plugin,
: parent_(parent) {} : parent_(parent) {}
protected: protected:
void update(void) final; void update() final;
private: private:
const LEDBreatheEffect *parent_; const LEDBreatheEffect *parent_;

@ -25,7 +25,7 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
void LEDChaseEffect::TransientLEDMode::update(void) { void LEDChaseEffect::TransientLEDMode::update() {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;

@ -28,8 +28,6 @@ namespace plugin {
class LEDChaseEffect : public Plugin, class LEDChaseEffect : public Plugin,
public LEDModeInterface { public LEDModeInterface {
public: public:
LEDChaseEffect(void) {}
uint8_t update_delay() { uint8_t update_delay() {
return update_delay_; return update_delay_;
} }

@ -27,7 +27,7 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
void LEDRainbowEffect::TransientLEDMode::update(void) { void LEDRainbowEffect::TransientLEDMode::update() {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;
@ -58,7 +58,7 @@ void LEDRainbowEffect::update_delay(byte delay) {
// --------- // ---------
void LEDRainbowWaveEffect::TransientLEDMode::update(void) { void LEDRainbowWaveEffect::TransientLEDMode::update() {
if (!Runtime.has_leds) if (!Runtime.has_leds)
return; return;

@ -27,14 +27,12 @@ namespace plugin {
class LEDRainbowEffect : public Plugin, class LEDRainbowEffect : public Plugin,
public LEDModeInterface { public LEDModeInterface {
public: public:
LEDRainbowEffect(void) {}
void brightness(uint8_t); void brightness(uint8_t);
uint8_t brightness(void) { uint8_t brightness() {
return rainbow_value; return rainbow_value;
} }
void update_delay(uint8_t); void update_delay(uint8_t);
uint8_t update_delay(void) { uint8_t update_delay() {
return rainbow_update_delay; return rainbow_update_delay;
} }
@ -70,14 +68,12 @@ class LEDRainbowEffect : public Plugin,
class LEDRainbowWaveEffect : public Plugin, public LEDModeInterface { class LEDRainbowWaveEffect : public Plugin, public LEDModeInterface {
public: public:
LEDRainbowWaveEffect(void) {}
void brightness(uint8_t); void brightness(uint8_t);
uint8_t brightness(void) { uint8_t brightness() {
return rainbow_value; return rainbow_value;
} }
void update_delay(uint8_t); void update_delay(uint8_t);
uint8_t update_delay(void) { uint8_t update_delay() {
return rainbow_update_delay; return rainbow_update_delay;
} }

@ -23,7 +23,7 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
void LEDSolidColor::TransientLEDMode::onActivate(void) { void LEDSolidColor::TransientLEDMode::onActivate() {
::LEDControl.set_all_leds_to(parent_->r_, ::LEDControl.set_all_leds_to(parent_->r_,
parent_->g_, parent_->g_,
parent_->b_); parent_->b_);

@ -43,7 +43,7 @@ class LEDSolidColor : public Plugin,
: parent_(parent) {} : parent_(parent) {}
protected: protected:
void onActivate(void) final; void onActivate() final;
void refreshAt(KeyAddr key_addr) final; void refreshAt(KeyAddr key_addr) final;
private: private:

@ -15,7 +15,7 @@ them.
KALEIDOSCOPE_INIT_PLUGINS(LEDControl, JukeBoxEffect); KALEIDOSCOPE_INIT_PLUGINS(LEDControl, JukeBoxEffect);
void setup(void) { void setup() {
Kaleidoscope.setup(); Kaleidoscope.setup();
} }
``` ```

@ -32,7 +32,7 @@ TriColor::TriColor(cRGB base_color, cRGB mod_color, cRGB esc_color) {
esc_color_ = esc_color; esc_color_ = esc_color;
} }
void TriColor::TransientLEDMode::update(void) { void TriColor::TransientLEDMode::update() {
for (auto key_addr : KeyAddr::all()) { for (auto key_addr : KeyAddr::all()) {
Key k = Layer.lookupOnActiveLayer(key_addr); Key k = Layer.lookupOnActiveLayer(key_addr);

@ -43,7 +43,7 @@ class TriColor : public Plugin,
: parent_(parent) {} : parent_(parent) {}
protected: protected:
void update(void) final; void update() final;
private: private:
const TriColor *parent_; const TriColor *parent_;

@ -26,8 +26,6 @@ namespace plugin {
class LayerFocus : public kaleidoscope::Plugin { class LayerFocus : public kaleidoscope::Plugin {
public: public:
LayerFocus() {}
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
EventHandlerResult onFocusEvent(const char *command); EventHandlerResult onFocusEvent(const char *command);
}; };

@ -34,15 +34,9 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
// --- state --- // --- state ---
Key Leader::sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1];
KeyEventTracker Leader::event_tracker_;
uint8_t Leader::sequence_pos_;
uint16_t Leader::start_time_ = 0;
#ifndef NDEPRECATED #ifndef NDEPRECATED
uint16_t Leader::time_out = 1000; uint16_t Leader::time_out = 1000;
#endif #endif
uint16_t Leader::timeout_ = 1000;
const Leader::dictionary_t *Leader::dictionary;
// --- helpers --- // --- helpers ---
@ -53,7 +47,7 @@ const Leader::dictionary_t *Leader::dictionary;
#define isActive() (sequence_[0] != Key_NoKey) #define isActive() (sequence_[0] != Key_NoKey)
// --- actions --- // --- actions ---
int8_t Leader::lookup(void) { int8_t Leader::lookup() {
bool match; bool match;
for (uint8_t seq_index = 0;; seq_index++) { for (uint8_t seq_index = 0;; seq_index++) {
@ -88,7 +82,7 @@ int8_t Leader::lookup(void) {
// --- api --- // --- api ---
void Leader::reset(void) { void Leader::reset() {
sequence_pos_ = 0; sequence_pos_ = 0;
sequence_[0] = Key_NoKey; sequence_[0] = Key_NoKey;
} }

@ -62,15 +62,14 @@ constexpr Key LeaderKey(uint8_t n) {
class Leader : public kaleidoscope::Plugin { class Leader : public kaleidoscope::Plugin {
public: public:
typedef void (*action_t)(uint8_t seq_index); typedef void (*action_t)(uint8_t seq_index);
typedef struct { struct dictionary_t {
Key sequence[LEADER_MAX_SEQUENCE_LENGTH + 1]; Key sequence[LEADER_MAX_SEQUENCE_LENGTH + 1];
action_t action; action_t action;
} dictionary_t; };
Leader(void) {} const dictionary_t *dictionary;
static const dictionary_t *dictionary;
static void reset(void); void reset();
#ifndef NDEPRECATED #ifndef NDEPRECATED
DEPRECATED(LEADER_TIME_OUT) DEPRECATED(LEADER_TIME_OUT)
@ -80,7 +79,7 @@ class Leader : public kaleidoscope::Plugin {
void inject(Key key, uint8_t key_state); void inject(Key key, uint8_t key_state);
#endif #endif
static void setTimeout(uint16_t timeout) { void setTimeout(uint16_t timeout) {
#ifndef NDEPRECATED #ifndef NDEPRECATED
#pragma GCC diagnostic push #pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations" #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
@ -95,13 +94,13 @@ class Leader : public kaleidoscope::Plugin {
EventHandlerResult afterEachCycle(); EventHandlerResult afterEachCycle();
private: private:
static Key sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1]; Key sequence_[LEADER_MAX_SEQUENCE_LENGTH + 1];
static KeyEventTracker event_tracker_; KeyEventTracker event_tracker_;
static uint8_t sequence_pos_; uint8_t sequence_pos_;
static uint16_t start_time_; uint16_t start_time_ = 0;
static uint16_t timeout_; uint16_t timeout_ = 1000;
static int8_t lookup(void); int8_t lookup();
}; };
} // namespace plugin } // namespace plugin

@ -42,9 +42,9 @@ that are part of a combination.
## Plugin properties ## Plugin properties
The extension provides a `MagicCombo` singleton object, with the following The extension provides a `MagicCombo` singleton object, with the following
property: method:
### `.min_interval` ### `.setMinInterval(min_interval)`
> Restrict the magic action to fire at most once every `min_interval` > Restrict the magic action to fire at most once every `min_interval`
> milliseconds. > milliseconds.

@ -28,8 +28,9 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
#ifndef NDEPRECATED
uint16_t MagicCombo::min_interval = 500; uint16_t MagicCombo::min_interval = 500;
uint16_t MagicCombo::start_time_ = 0; #endif
EventHandlerResult MagicCombo::onNameQuery() { EventHandlerResult MagicCombo::onNameQuery() {
return ::Focus.sendName(F("MagicCombo")); return ::Focus.sendName(F("MagicCombo"));
@ -54,7 +55,7 @@ EventHandlerResult MagicCombo::afterEachCycle() {
if (j != Runtime.device().pressedKeyswitchCount()) if (j != Runtime.device().pressedKeyswitchCount())
match = false; match = false;
if (match && Runtime.hasTimeExpired(start_time_, min_interval)) { if (match && Runtime.hasTimeExpired(start_time_, getMinInterval())) {
ComboAction action = (ComboAction)pgm_read_ptr((void const **)&(magiccombo::combos[i].action)); ComboAction action = (ComboAction)pgm_read_ptr((void const **)&(magiccombo::combos[i].action));
(*action)(i); (*action)(i);

@ -22,6 +22,15 @@
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin #include "kaleidoscope/plugin.h" // for Plugin
// -----------------------------------------------------------------------------
// Deprecation warning messages
#include "kaleidoscope_internal/deprecations.h" // for DEPRECATED
#define _DEPRECATED_MESSAGE_MAGICCOMBO_MIN_INTERVAL \
"The `MagicCombo.min_interval` variable is deprecated. Please use the\n" \
"`MagicCombo.setMinInterval()` function instead.\n" \
"This variable will be removed after 2022-09-01."
// -----------------------------------------------------------------------------
#define MAX_COMBO_LENGTH 5 #define MAX_COMBO_LENGTH 5
@ -43,27 +52,51 @@ namespace plugin {
class MagicCombo : public kaleidoscope::Plugin { class MagicCombo : public kaleidoscope::Plugin {
public: public:
typedef void (*ComboAction)(uint8_t combo_index); typedef void (*ComboAction)(uint8_t combo_index);
typedef struct { struct Combo {
ComboAction action; ComboAction action;
int8_t keys[MAX_COMBO_LENGTH + 1]; int8_t keys[MAX_COMBO_LENGTH + 1];
} Combo; };
MagicCombo(void) {}
#ifndef NDEPRECATED
DEPRECATED(MAGICCOMBO_MIN_INTERVAL)
static uint16_t min_interval; static uint16_t min_interval;
#endif
void setMinInterval(uint16_t interval) {
#ifndef NDEPRECATED
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
min_interval = interval;
#pragma GCC diagnostic pop
#else
min_interval_ = interval;
#endif
}
uint16_t getMinInterval() {
#ifndef NDEPRECATED
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
return min_interval;
#pragma GCC diagnostic pop
#else
return min_interval_;
#endif
}
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
EventHandlerResult afterEachCycle(); EventHandlerResult afterEachCycle();
private: private:
static uint16_t start_time_; uint16_t start_time_ = 0;
uint16_t min_interval_ = 500;
}; };
namespace magiccombo { namespace magiccombo {
extern const MagicCombo::Combo combos[]; extern const MagicCombo::Combo combos[];
extern const uint8_t combos_length; extern const uint8_t combos_length;
} // namespace magiccombo } // namespace magiccombo
} // namespace plugin } // namespace plugin
} // namespace kaleidoscope } // namespace kaleidoscope

@ -91,7 +91,7 @@ EventHandlerResult MouseKeys::onNameQuery() {
} }
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
EventHandlerResult MouseKeys::onSetup(void) { EventHandlerResult MouseKeys::onSetup() {
kaleidoscope::Runtime.hid().mouse().setup(); kaleidoscope::Runtime.hid().mouse().setup();
kaleidoscope::Runtime.hid().absoluteMouse().setup(); kaleidoscope::Runtime.hid().absoluteMouse().setup();

@ -38,11 +38,11 @@ uint8_t NumPad::lock_hue = 170;
KeyAddr NumPad::numpadLayerToggleKeyAddr; KeyAddr NumPad::numpadLayerToggleKeyAddr;
bool NumPad::numpadActive = false; bool NumPad::numpadActive = false;
EventHandlerResult NumPad::onSetup(void) { EventHandlerResult NumPad::onSetup() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
void NumPad::setKeyboardLEDColors(void) { void NumPad::setKeyboardLEDColors() {
::LEDControl.set_mode(::LEDControl.get_mode_index()); ::LEDControl.set_mode(::LEDControl.get_mode_index());
for (auto key_addr : KeyAddr::all()) { for (auto key_addr : KeyAddr::all()) {

@ -28,17 +28,15 @@ namespace plugin {
class NumPad : public kaleidoscope::Plugin { class NumPad : public kaleidoscope::Plugin {
public: public:
NumPad(void) {}
static uint8_t numPadLayer; static uint8_t numPadLayer;
static cRGB color; static cRGB color;
static uint8_t lock_hue; static uint8_t lock_hue;
EventHandlerResult onSetup(void); EventHandlerResult onSetup();
EventHandlerResult afterEachCycle(); EventHandlerResult afterEachCycle();
private: private:
void setKeyboardLEDColors(void); void setKeyboardLEDColors();
static KeyAddr numpadLayerToggleKeyAddr; static KeyAddr numpadLayerToggleKeyAddr;
static bool numpadActive; static bool numpadActive;

@ -50,9 +50,6 @@ constexpr Key OneShotLayerKey(uint8_t layer) {
class OneShot : public kaleidoscope::Plugin { class OneShot : public kaleidoscope::Plugin {
public: public:
// Constructor
// OneShot() {}
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Configuration functions // Configuration functions

@ -18,8 +18,9 @@
#include "kaleidoscope/plugin/PersistentLEDMode.h" #include "kaleidoscope/plugin/PersistentLEDMode.h"
#include <Arduino.h> // for PSTR, strcmp_P, F, __FlashStringHelper
#include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings #include <Kaleidoscope-EEPROM-Settings.h> // for EEPROMSettings
#include <Kaleidoscope-FocusSerial.h> // for Focus #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for uint8_t, uint16_t #include <stdint.h> // for uint8_t, uint16_t
#include "kaleidoscope/Runtime.h" // for Runtime, Runtime_ #include "kaleidoscope/Runtime.h" // for Runtime, Runtime_

@ -18,7 +18,7 @@
#pragma once #pragma once
#include <stdint.h> // for uint16_t, uint8_t #include <stdint.h> // for uint8_t, uint16_t
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/plugin.h" // for Plugin #include "kaleidoscope/plugin.h" // for Plugin
@ -28,8 +28,6 @@ namespace plugin {
class PersistentLEDMode : public kaleidoscope::Plugin { class PersistentLEDMode : public kaleidoscope::Plugin {
public: public:
PersistentLEDMode() {}
EventHandlerResult onSetup(); EventHandlerResult onSetup();
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
EventHandlerResult onLEDModeChange(); EventHandlerResult onLEDModeChange();

@ -28,8 +28,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
Key Redial::last_key_;
EventHandlerResult Redial::onNameQuery() { EventHandlerResult Redial::onNameQuery() {
return ::Focus.sendName(F("Redial")); return ::Focus.sendName(F("Redial"));
} }

@ -31,15 +31,13 @@ namespace plugin {
class Redial : public kaleidoscope::Plugin { class Redial : public kaleidoscope::Plugin {
public: public:
Redial(void) {}
static bool shouldRemember(Key mappedKey); static bool shouldRemember(Key mappedKey);
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
private: private:
static Key last_key_; Key last_key_;
}; };
} // namespace plugin } // namespace plugin

@ -28,8 +28,6 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
const ShapeShifter::dictionary_t *ShapeShifter::dictionary = nullptr;
EventHandlerResult ShapeShifter::onKeyEvent(KeyEvent &event) { EventHandlerResult ShapeShifter::onKeyEvent(KeyEvent &event) {
if (dictionary == nullptr) if (dictionary == nullptr)
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -27,13 +27,11 @@ namespace plugin {
class ShapeShifter : public kaleidoscope::Plugin { class ShapeShifter : public kaleidoscope::Plugin {
public: public:
typedef struct { struct dictionary_t {
Key original, replacement; Key original, replacement;
} dictionary_t; };
ShapeShifter(void) {} const dictionary_t *dictionary = nullptr;
static const dictionary_t *dictionary;
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
}; };

@ -75,16 +75,15 @@ void setup() {
, SPACECADET_MAP_END , SPACECADET_MAP_END
}; };
//Set the map. //Set the map.
SpaceCadet.map = spacecadetmap; SpaceCadet.setMap(spacecadetmap);
} }
``` ```
## Plugin methods ## Plugin methods
The plugin provides the `SpaceCadet` object, with the following methods and The plugin provides the `SpaceCadet` object, with the following methods:
properties:
### `.map` ### `.setMap(map)`
> Set the key map. This takes an array of > Set the key map. This takes an array of
> `kaleidoscope::plugin::SpaceCadet::KeyBinding` objects with the special > `kaleidoscope::plugin::SpaceCadet::KeyBinding` objects with the special
@ -103,9 +102,9 @@ properties:
> optional and may be set per-key or left out entirely (or set to `0`) to use > optional and may be set per-key or left out entirely (or set to `0`) to use
> the default timeout value. > the default timeout value.
### `.time_out` ### `.setTimeout(timeout)`
> Set this property to the number of milliseconds to wait before considering a > Sets the number of milliseconds to wait before considering a
> held key in isolation as its secondary role. That is, we'd have to hold a > held key in isolation as its secondary role. That is, we'd have to hold a
> `Shift` key this long, by itself, to trigger the `Shift` role in itself. This > `Shift` key this long, by itself, to trigger the `Shift` role in itself. This
> timeout setting can be overridden by an individual key in the keymap, but if > timeout setting can be overridden by an individual key in the keymap, but if

@ -48,21 +48,10 @@ SpaceCadet::KeyBinding::KeyBinding(Key input, Key output, uint16_t timeout)
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Plugin configuration variables // Plugin configuration variables
#ifndef NDEPRECATED
SpaceCadet::KeyBinding *SpaceCadet::map; SpaceCadet::KeyBinding *SpaceCadet::map;
uint16_t SpaceCadet::time_out = 200; uint16_t SpaceCadet::time_out = 200;
#endif
// -----------------------------------------------------------------------------
// State variables
uint8_t SpaceCadet::mode_ = SpaceCadet::Mode::ON;
// These variables are used to keep track of any pending unresolved SpaceCadet
// key that has been pressed. If `pending_map_index_` is negative, it means
// there is no such pending keypress. Otherwise, it holds the value of the index
// of that key in the array.
int8_t SpaceCadet::pending_map_index_ = -1;
KeyEventTracker SpaceCadet::event_tracker_;
// ============================================================================= // =============================================================================
// SpaceCadet functions // SpaceCadet functions
@ -82,7 +71,7 @@ SpaceCadet::SpaceCadet() {
*/ */
SPACECADET_MAP_END}; SPACECADET_MAP_END};
map = initialmap; setMap(initialmap);
} }
// ============================================================================= // =============================================================================
@ -174,7 +163,14 @@ EventHandlerResult SpaceCadet::afterEachCycle() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
// Get timeout value for the pending key. // Get timeout value for the pending key.
#ifndef NDEPRECATED
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
uint16_t pending_timeout = time_out; uint16_t pending_timeout = time_out;
#pragma GCC diagnostic pop
#else
uint16_t pending_timeout = timeout_;
#endif
if (map[pending_map_index_].timeout != 0) if (map[pending_map_index_].timeout != 0)
pending_timeout = map[pending_map_index_].timeout; pending_timeout = map[pending_map_index_].timeout;
uint16_t start_time = event_queue_.timestamp(0); uint16_t start_time = event_queue_.timestamp(0);

@ -27,6 +27,15 @@
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
#include "kaleidoscope/key_defs.h" // for Key, Key_NoKey #include "kaleidoscope/key_defs.h" // for Key, Key_NoKey
#include "kaleidoscope/plugin.h" // for Plugin #include "kaleidoscope/plugin.h" // for Plugin
// -----------------------------------------------------------------------------
// Deprecation warning messages
#include "kaleidoscope_internal/deprecations.h" // for DEPRECATED
#define _DEPRECATED_MESSAGE_SPACECADET_TIME_OUT \
"The `SpaceCadet.time_out` variable is deprecated. Please use the\n" \
"`SpaceCadet.setTimeout()` function instead.\n" \
"This variable will be removed after 2022-09-01."
// -----------------------------------------------------------------------------
#ifndef SPACECADET_MAP_END #ifndef SPACECADET_MAP_END
#define SPACECADET_MAP_END \ #define SPACECADET_MAP_END \
@ -63,25 +72,43 @@ class SpaceCadet : public kaleidoscope::Plugin {
} }
}; };
SpaceCadet(void); SpaceCadet();
// Methods // Methods
static void enable() { void enable() {
mode_ = Mode::ON; mode_ = Mode::ON;
} }
static void disable() { void disable() {
mode_ = Mode::OFF; mode_ = Mode::OFF;
} }
static void enableWithoutDelay() { void enableWithoutDelay() {
mode_ = Mode::NO_DELAY; mode_ = Mode::NO_DELAY;
} }
static bool active() { bool active() {
return (mode_ == Mode::ON || mode_ == Mode::NO_DELAY); return (mode_ == Mode::ON || mode_ == Mode::NO_DELAY);
} }
#ifndef NDEPRECATED
// Publically accessible variables // Publically accessible variables
DEPRECATED(SPACECADET_TIME_OUT)
static uint16_t time_out; // The global timeout in milliseconds static uint16_t time_out; // The global timeout in milliseconds
static SpaceCadet::KeyBinding *map; // The map of key bindings static SpaceCadet::KeyBinding *map; // The map of key bindings
#endif
void setTimeout(uint16_t timeout) {
#ifndef NDEPRECATED
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
time_out = timeout;
#pragma GCC diagnostic pop
#else
timeout_ = timeout;
#endif
}
void setMap(KeyBinding *bindings) {
map = bindings;
}
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
EventHandlerResult onKeyswitchEvent(KeyEvent &event); EventHandlerResult onKeyswitchEvent(KeyEvent &event);
@ -93,9 +120,19 @@ class SpaceCadet : public kaleidoscope::Plugin {
OFF, OFF,
NO_DELAY, NO_DELAY,
}; };
static uint8_t mode_; uint8_t mode_;
#ifdef NDEPRECATED
// Global timeout in milliseconds
uint16_t timeout_ = 200;
// The map of keybindings
KeyBinding *map = nullptr;
// When DEPRECATED public `map[]` variable is removed, this variable name
// should be given a trailing underscore to conform to code style guide.
#endif
static KeyEventTracker event_tracker_; KeyEventTracker event_tracker_;
// The maximum number of events in the queue at a time. // The maximum number of events in the queue at a time.
static constexpr uint8_t queue_capacity_{4}; static constexpr uint8_t queue_capacity_{4};
@ -103,7 +140,11 @@ class SpaceCadet : public kaleidoscope::Plugin {
// The event queue stores a series of press and release events. // The event queue stores a series of press and release events.
KeyAddrEventQueue<queue_capacity_> event_queue_; KeyAddrEventQueue<queue_capacity_> event_queue_;
static int8_t pending_map_index_; // This variable is used to keep track of any pending unresolved SpaceCadet
// key that has been pressed. If `pending_map_index_` is negative, it means
// there is no such pending keypress. Otherwise, it holds the value of the
// index of that key in the array.
int8_t pending_map_index_ = -1;
int8_t getSpaceCadetKeyIndex(Key key) const; int8_t getSpaceCadetKeyIndex(Key key) const;

@ -31,8 +31,6 @@ namespace plugin {
namespace steno { namespace steno {
class GeminiPR : public kaleidoscope::Plugin { class GeminiPR : public kaleidoscope::Plugin {
public: public:
GeminiPR(void) {}
EventHandlerResult onNameQuery(); EventHandlerResult onNameQuery();
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);

@ -19,7 +19,7 @@
#include <Arduino.h> // for F, __FlashStringHelper #include <Arduino.h> // for F, __FlashStringHelper
#include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial #include <Kaleidoscope-FocusSerial.h> // for Focus, FocusSerial
#include <stdint.h> // for int8_t, uint8_t #include <stdint.h> // for int8_t
#include "kaleidoscope/KeyAddr.h" // for KeyAddr #include "kaleidoscope/KeyAddr.h" // for KeyAddr
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
@ -31,19 +31,14 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
// --- state ---
char Syster::symbol_[SYSTER_MAX_SYMBOL_LENGTH + 1];
uint8_t Syster::symbol_pos_;
bool Syster::is_active_;
// --- api --- // --- api ---
void Syster::reset(void) { void Syster::reset() {
symbol_pos_ = 0; symbol_pos_ = 0;
symbol_[0] = 0; symbol_[0] = 0;
is_active_ = false; is_active_ = false;
} }
bool Syster::is_active(void) { bool Syster::is_active() {
return is_active_; return is_active_;
} }

@ -18,7 +18,7 @@
#pragma once #pragma once
#include <Kaleidoscope-Ranges.h> // for SYSTER #include <Kaleidoscope-Ranges.h> // for SYSTER
#include <stdint.h> // for int8_t, uint8_t #include <stdint.h> // for uint8_t, int8_t
#include "kaleidoscope/KeyEvent.h" // for KeyEvent #include "kaleidoscope/KeyEvent.h" // for KeyEvent
#include "kaleidoscope/event_handler_result.h" // for EventHandlerResult #include "kaleidoscope/event_handler_result.h" // for EventHandlerResult
@ -35,15 +35,13 @@ namespace plugin {
class Syster : public kaleidoscope::Plugin { class Syster : public kaleidoscope::Plugin {
public: public:
typedef enum { enum action_t : uint8_t {
StartAction, StartAction,
EndAction, EndAction,
SymbolAction SymbolAction
} action_t; };
Syster() {} void reset();
static void reset();
bool is_active(); bool is_active();
@ -51,9 +49,9 @@ class Syster : public kaleidoscope::Plugin {
EventHandlerResult onKeyEvent(KeyEvent &event); EventHandlerResult onKeyEvent(KeyEvent &event);
private: private:
static char symbol_[SYSTER_MAX_SYMBOL_LENGTH + 1]; char symbol_[SYSTER_MAX_SYMBOL_LENGTH + 1];
static uint8_t symbol_pos_; uint8_t symbol_pos_;
static bool is_active_; bool is_active_ = false;
}; };
} // namespace plugin } // namespace plugin

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save