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

Model100: Enable the AutoShift & AutoShiftConfig plugins by default #1303

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion examples/Devices/Keyboardio/Model100/Model100.ino
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@
// Support for the GeminiPR Stenography protocol
#include "Kaleidoscope-Steno.h"

// Support for using long-press to auto-shift keys
#include "Kaleidoscope-AutoShift.h"

/** This 'enum' is a list of all the macros used by the Model 100's firmware
* The names aren't particularly important. What is important is that each
* is unique.
Expand Down Expand Up @@ -601,7 +604,11 @@ KALEIDOSCOPE_INIT_PLUGINS(

// Enables the GeminiPR Stenography protocol. Unused by default, but with the
// plugin enabled, it becomes configurable - and then usable - via Chrysalis.
GeminiPR);
GeminiPR,

// Allows using long-press to auto-shift keys (configurable via Chrysalis).
AutoShift,
AutoShiftConfig);

/** The 'setup' function is one of the two standard Arduino sketch functions.
* It's called when your keyboard first powers up. This is where you set up
Expand Down Expand Up @@ -669,6 +676,10 @@ void setup() {
// firmware starts with LED effects off. This avoids over-taxing devices that
// don't have a lot of power to share with USB devices
DefaultLEDModeConfig.activateLEDModeIfUnconfigured(&LEDOff);

// Unless configured otherwise, we want to have the long-press auto-shifting
// feature turned off, to avoid surprises.
AutoShiftConfig.disableAutoShiftIfUnconfigured();
}

/** loop is the second of the standard Arduino sketch functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ class AutoShiftConfig : public Plugin {
public:
EventHandlerResult onSetup();
EventHandlerResult onFocusEvent(const char *input);
void disableAutoShiftIfUnconfigured();

private:
// The base address in persistent storage for configuration data
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,21 @@ namespace plugin {
EventHandlerResult AutoShiftConfig::onSetup() {
settings_base_ = ::EEPROMSettings.requestSlice(sizeof(AutoShift::Settings));

if (Runtime.storage().isSliceUninitialized(
if (!Runtime.storage().isSliceUninitialized(
settings_base_,
sizeof(AutoShift::Settings))) {
// If our slice is uninitialized, set sensible defaults.
Runtime.storage().put(settings_base_, ::AutoShift.settings_);
Runtime.storage().commit();
// If our slice is initialized, load the settings
Runtime.storage().get(settings_base_, ::AutoShift.settings_);
}

Runtime.storage().get(settings_base_, ::AutoShift.settings_);
return EventHandlerResult::OK;
}

void AutoShiftConfig::disableAutoShiftIfUnconfigured() {
if (Runtime.storage().isSliceUninitialized(settings_base_, sizeof(AutoShift::settings_)))
::AutoShift.disable();
}

EventHandlerResult AutoShiftConfig::onFocusEvent(const char *input) {
enum {
ENABLED,
Expand Down