Merge pull request #737 from CapeLeidokos/pr_build_time_optimization

Build time optimization with include-what-you-use
pull/759/head
Jesse Vincent 5 years ago committed by GitHub
commit e425d8ac5a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -488,6 +488,10 @@ Older versions of the plugin required one to set up `Key_Redial` manually, and l
## Deprecated APIs and their replacements ## Deprecated APIs and their replacements
### Class/global instance Kaleidoscope_/Kaleidoscope renamed to kaleidoscope::Runtime_/kaleidoscope::Runtime
After renaming, some of the original symbols have been deprecated. The deprecated symbols in `kaleidoscope/Runtime.h` are scheduled for removal on **2019-03-10**.
### Transition to linear indexing ### Transition to linear indexing
Row/col based indexing was replaced by linear indexing throughout the whole firmware. A compatibility layer of functions was introduced that allows Row/col based indexing was replaced by linear indexing throughout the whole firmware. A compatibility layer of functions was introduced that allows

@ -16,4 +16,106 @@
#pragma once #pragma once
#include "kaleidoscope/Kaleidoscope.h" #include <Arduino.h>
//end of add your includes here
#ifdef __cplusplus
extern "C" {
#endif
void loop();
void setup();
#ifdef __cplusplus
} // extern "C"
#endif
//add your function definitions for the project KeyboardIO here
#define TS(X) //Serial.print(micros() );Serial.print("\t");Serial.println(X);
#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include "kaleidoscope/device/device.h"
#include "kaleidoscope/device/key_indexes.h"
#include "kaleidoscope_internal/device.h"
#include "kaleidoscope_internal/deprecations.h"
static constexpr DEPRECATED(KEYBOARDHARDWARE) kaleidoscope::Device &KeyboardHardware = kaleidoscope_internal::device;
#ifdef PER_KEY_DATA_STACKED
#define KEYMAP_STACKED(...) { PER_KEY_DATA_STACKED(XXX, __VA_ARGS__) }
#endif
#ifdef PER_KEY_DATA
#define KEYMAP(...) { PER_KEY_DATA(XXX, __VA_ARGS__) }
#endif
static constexpr DEPRECATED(ROWS) uint8_t ROWS = kaleidoscope_internal::device.matrix_rows;
static constexpr DEPRECATED(COLS) uint8_t COLS = kaleidoscope_internal::device.matrix_columns;
static constexpr DEPRECATED(LED_COUNT) uint8_t LED_COUNT = kaleidoscope_internal::device.led_count;
#include "kaleidoscope/KeyAddr.h"
#include "kaleidoscope/key_events.h"
#include "kaleidoscope/hid.h"
#include "kaleidoscope/layers.h"
#include "kaleidoscope_internal/sketch_exploration/sketch_exploration.h"
#include "kaleidoscope/macro_map.h"
#include "kaleidoscope_internal/event_dispatch.h"
#include "kaleidoscope_internal/LEDModeManager.h"
#include "kaleidoscope/macro_helpers.h"
#include "kaleidoscope/plugin.h"
#include "kaleidoscope/Runtime.h"
#define HOOK_MAX 64
#ifndef VERSION
#define VERSION "locally-built"
#endif
/** Kaleidoscope API (major) version.
*
* The API is guaranteed to be backwards compatible for the entire duration of a
* major version. However, breaking changes may come, and result in a major
* version bump. To help migration, the `KALEIDOSCOPE_API_VERSION` macro can be
* used to check the major version provided by the Kaleidoscope we are compiling
* against. This can be used to error out with a helpful message, or change how
* the API is used - it is entirely up to the plugin or sketch author. The point
* of this macro is to let them easily check the version.
*/
#define KALEIDOSCOPE_API_VERSION 2
/** Required Kaleidoscope major version.
*
* For the sake of convenience, defining `KALEIDOSCOPE_REQUIRED_API_VERSION`
* before including `Kaleidoscope.h` itself will result in comparing its value
* to `KALEIDOSCOPE_API_VERSION`. If they differ, a helpful error message is
* printed.
*
* Done so that a new API version would result in a helpful error message,
* instead of cryptic compile errors.
*/
#if defined(KALEIDOSCOPE_REQUIRED_API_VERSION) && (KALEIDOSCOPE_REQUIRED_API_VERSION != KALEIDOSCOPE_API_VERSION)
#define xstr(a) str(a)
#define str(a) #a
static_assert(KALEIDOSCOPE_REQUIRED_API_VERSION == KALEIDOSCOPE_API_VERSION,
"Kaleidoscope API version mismatch! We have version " xstr(KALEIDOSCOPE_API_VERSION)
" available, but version " xstr(KALEIDOSCOPE_REQUIRED_API_VERSION) " is required.");
#endif
// Use this function macro to register plugins with Kaleidoscope's
// hooking system. The macro accepts a list of plugin instances that
// must have been instantiated at global scope.
//
#define KALEIDOSCOPE_INIT_PLUGINS(...) _KALEIDOSCOPE_INIT_PLUGINS(__VA_ARGS__)
// For compatibility reasons we export class Runtime_ as Kaleidoscope_
// in global namespace.
//
DEPRECATED(GLOBAL_TYPENAME_KALEIDOSCOPE)
typedef kaleidoscope::Runtime_ Kaleidoscope_;
// For compatibility/usability reasons we enable the global variable
// Kaleidoscope in global namespace.
//
extern kaleidoscope::Runtime_ &Kaleidoscope;

@ -246,7 +246,7 @@ class Hardware {
* *
* Because different hardware has different ways to accomplish this, the * Because different hardware has different ways to accomplish this, the
* hardware plugin must provide these functions. Kaleidoscope will wrap them, * hardware plugin must provide these functions. Kaleidoscope will wrap them,
* so user code does not have to deal with `Kaleidoscope.device()`. * so user code does not have to deal with `Runtime.device()`.
* @{ * @{
*/ */
/** /**

@ -211,7 +211,7 @@ class MatrixAddr {
// cause ambiguous symbol lookup when used in the regular firmware. // cause ambiguous symbol lookup when used in the regular firmware.
// //
// To use them also for the regular firmware they would need to be // To use them also for the regular firmware they would need to be
// disambiguated by moving them to the Kaleidoscope.h header and replacing // disambiguated by moving them to the Runtime.h header and replacing
// them with non-template versions that operate on the actual typedefed // them with non-template versions that operate on the actual typedefed
// KeyAddr and KeyAddr. // KeyAddr and KeyAddr.

@ -14,18 +14,20 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "kaleidoscope/Kaleidoscope.h" #include "kaleidoscope/Runtime.h"
#include <stdarg.h> #include "kaleidoscope/hid.h"
#include "kaleidoscope/layers.h"
#include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope { namespace kaleidoscope {
uint32_t Kaleidoscope_::millis_at_cycle_start_; uint32_t Runtime_::millis_at_cycle_start_;
Kaleidoscope_::Kaleidoscope_(void) { Runtime_::Runtime_(void) {
} }
void void
Kaleidoscope_::setup(void) { Runtime_::setup(void) {
// We are explicitly initializing the Serial port as early as possible to // We are explicitly initializing the Serial port as early as possible to
// (temporarily, hopefully) work around an issue on OSX. If we initialize // (temporarily, hopefully) work around an issue on OSX. If we initialize
// Serial too late, no matter what we do, we'll end up reading garbage from // Serial too late, no matter what we do, we'll end up reading garbage from
@ -53,7 +55,7 @@ Kaleidoscope_::setup(void) {
} }
void void
Kaleidoscope_::loop(void) { Runtime_::loop(void) {
millis_at_cycle_start_ = millis(); millis_at_cycle_start_ = millis();
kaleidoscope::Hooks::beforeEachCycle(); kaleidoscope::Hooks::beforeEachCycle();
@ -68,6 +70,8 @@ Kaleidoscope_::loop(void) {
kaleidoscope::Hooks::afterEachCycle(); kaleidoscope::Hooks::afterEachCycle();
} }
Kaleidoscope_ Kaleidoscope; Runtime_ Runtime;
} // namespace kaleidoscope } // namespace kaleidoscope
kaleidoscope::Runtime_ &Kaleidoscope = kaleidoscope::Runtime;

@ -16,97 +16,15 @@
#pragma once #pragma once
#include <Arduino.h>
//end of add your includes here
#ifdef __cplusplus
extern "C" {
#endif
void loop();
void setup();
#ifdef __cplusplus
} // extern "C"
#endif
//add your function definitions for the project KeyboardIO here
#define TS(X) //Serial.print(micros() );Serial.print("\t");Serial.println(X);
#include <stdio.h>
#include <math.h>
#include <stdint.h>
#include "kaleidoscope/device/device.h"
#include "kaleidoscope/device/key_indexes.h"
#include "kaleidoscope_internal/device.h" #include "kaleidoscope_internal/device.h"
#include "kaleidoscope_internal/deprecations.h" #include "kaleidoscope/event_handler_result.h"
#include "kaleidoscope/hooks.h"
static constexpr DEPRECATED(KEYBOARDHARDWARE) kaleidoscope::Device &KeyboardHardware = kaleidoscope_internal::device;
#ifdef PER_KEY_DATA_STACKED
#define KEYMAP_STACKED(...) { PER_KEY_DATA_STACKED(XXX, __VA_ARGS__) }
#endif
#ifdef PER_KEY_DATA
#define KEYMAP(...) { PER_KEY_DATA(XXX, __VA_ARGS__) }
#endif
static constexpr DEPRECATED(ROWS) uint8_t ROWS = kaleidoscope_internal::device.matrix_rows;
static constexpr DEPRECATED(COLS) uint8_t COLS = kaleidoscope_internal::device.matrix_columns;
static constexpr DEPRECATED(LED_COUNT) uint8_t LED_COUNT = kaleidoscope_internal::device.led_count;
#include "kaleidoscope/KeyAddr.h"
#include "kaleidoscope/key_events.h"
#include "kaleidoscope/hid.h"
#include "kaleidoscope/layers.h"
#include "kaleidoscope_internal/sketch_exploration/sketch_exploration.h"
#include "kaleidoscope/macro_map.h"
#include "kaleidoscope_internal/event_dispatch.h"
#include "kaleidoscope_internal/LEDModeManager.h"
#include "kaleidoscope/macro_helpers.h"
#include "kaleidoscope/plugin.h"
#define HOOK_MAX 64
#ifndef VERSION
#define VERSION "locally-built"
#endif
/** Kaleidoscope API (major) version.
*
* The API is guaranteed to be backwards compatible for the entire duration of a
* major version. However, breaking changes may come, and result in a major
* version bump. To help migration, the `KALEIDOSCOPE_API_VERSION` macro can be
* used to check the major version provided by the Kaleidoscope we are compiling
* against. This can be used to error out with a helpful message, or change how
* the API is used - it is entirely up to the plugin or sketch author. The point
* of this macro is to let them easily check the version.
*/
#define KALEIDOSCOPE_API_VERSION 2
/** Required Kaleidoscope major version.
*
* For the sake of convenience, defining `KALEIDOSCOPE_REQUIRED_API_VERSION`
* before including `Kaleidoscope.h` itself will result in comparing its value
* to `KALEIDOSCOPE_API_VERSION`. If they differ, a helpful error message is
* printed.
*
* Done so that a new API version would result in a helpful error message,
* instead of cryptic compile errors.
*/
#if defined(KALEIDOSCOPE_REQUIRED_API_VERSION) && (KALEIDOSCOPE_REQUIRED_API_VERSION != KALEIDOSCOPE_API_VERSION)
#define xstr(a) str(a)
#define str(a) #a
static_assert(KALEIDOSCOPE_REQUIRED_API_VERSION == KALEIDOSCOPE_API_VERSION,
"Kaleidoscope API version mismatch! We have version " xstr(KALEIDOSCOPE_API_VERSION)
" available, but version " xstr(KALEIDOSCOPE_REQUIRED_API_VERSION) " is required.");
#endif
namespace kaleidoscope { namespace kaleidoscope {
class Kaleidoscope_ { class Runtime_ {
public: public:
Kaleidoscope_(void); Runtime_(void);
void setup(void); void setup(void);
void loop(void); void loop(void);
@ -121,7 +39,7 @@ class Kaleidoscope_ {
* *
* These two functions wrap the hardware plugin's similarly named functions. * These two functions wrap the hardware plugin's similarly named functions.
* We wrap them, because we'd like plugins and user-code not having to use * We wrap them, because we'd like plugins and user-code not having to use
* `Kaleidoscope.device()` directly. * `Runtime.device()` directly.
* *
* The methods themselves implement detaching from / attaching to the host, * The methods themselves implement detaching from / attaching to the host,
* without rebooting the device, and remaining powered in between. * without rebooting the device, and remaining powered in between.
@ -176,7 +94,7 @@ class Kaleidoscope_ {
* occurs, given a start time and a timeout. It takes two parameters: * occurs, given a start time and a timeout. It takes two parameters:
* *
* - start_time: A timestamp when the timer started, which should be set by * - start_time: A timestamp when the timer started, which should be set by
* calling `Kaleidoscope.millisAtCycleStart()`. It can be any integer * calling `Runtime.millisAtCycleStart()`. It can be any integer
* type. * type.
* *
* - ttl: The timeout value or interval to check (ttl = "time to live"). The * - ttl: The timeout value or interval to check (ttl = "time to live"). The
@ -210,22 +128,6 @@ class Kaleidoscope_ {
static uint32_t millis_at_cycle_start_; static uint32_t millis_at_cycle_start_;
}; };
extern kaleidoscope::Kaleidoscope_ Kaleidoscope; extern kaleidoscope::Runtime_ Runtime;
} // namespace kaleidoscope } // namespace kaleidoscope
// For compatibility reasons we enable class Kaleidoscope_ also to be available
// in global namespace.
//
typedef kaleidoscope::Kaleidoscope_ Kaleidoscope_;
// For compatibility reasons we enable the global variable Kaleidoscope
// in global namespace.
//
using kaleidoscope::Kaleidoscope;
// Use this function macro to register plugins with Kaleidoscope's
// hooking system. The macro accepts a list of plugin instances that
// must have been instantiated at global scope.
//
#define KALEIDOSCOPE_INIT_PLUGINS(...) _KALEIDOSCOPE_INIT_PLUGINS(__VA_ARGS__)

@ -14,7 +14,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Kaleidoscope.h" #include <Arduino.h>
#include "bitfields.h" #include "bitfields.h"

@ -17,6 +17,7 @@
#pragma once #pragma once
#include <stdint.h> #include <stdint.h>
#include <stddef.h>
namespace kaleidoscope { namespace kaleidoscope {
namespace bitfields { namespace bitfields {

@ -18,7 +18,7 @@
#ifdef ARDUINO_SAMD_RAISE #ifdef ARDUINO_SAMD_RAISE
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#include <KeyboardioHID.h> #include <KeyboardioHID.h>
@ -85,20 +85,20 @@ void RaiseHands::setup() {
// If keyscan is max, assume that EEPROM is uninitialized, and store the // If keyscan is max, assume that EEPROM is uninitialized, and store the
// defaults. // defaults.
uint16_t interval; uint16_t interval;
Kaleidoscope.storage().get(settings_base_, interval); Runtime.storage().get(settings_base_, interval);
if (interval == 0xffff) { if (interval == 0xffff) {
Kaleidoscope.storage().put(settings_base_, keyscan_interval_); Runtime.storage().put(settings_base_, keyscan_interval_);
Kaleidoscope.storage().commit(); Runtime.storage().commit();
} }
Kaleidoscope.storage().get(settings_base_, keyscan_interval_); Runtime.storage().get(settings_base_, keyscan_interval_);
} }
void RaiseHands::keyscanInterval(uint16_t interval) { void RaiseHands::keyscanInterval(uint16_t interval) {
leftHand.setKeyscanInterval(interval); leftHand.setKeyscanInterval(interval);
rightHand.setKeyscanInterval(interval); rightHand.setKeyscanInterval(interval);
keyscan_interval_ = interval; keyscan_interval_ = interval;
Kaleidoscope.storage().put(settings_base_, keyscan_interval_); Runtime.storage().put(settings_base_, keyscan_interval_);
Kaleidoscope.storage().commit(); Runtime.storage().commit();
} }
void RaiseHands::initializeSides() { void RaiseHands::initializeSides() {

@ -18,7 +18,7 @@
#ifdef ARDUINO_SAMD_RAISE #ifdef ARDUINO_SAMD_RAISE
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-FocusSerial.h> #include <Kaleidoscope-FocusSerial.h>
#include "kaleidoscope/device/dygma/raise/Focus.h" #include "kaleidoscope/device/dygma/raise/Focus.h"
@ -50,72 +50,72 @@ EventHandlerResult Focus::onFocusEvent(const char *command) {
if (strcmp_P(command + 9, PSTR("side_power")) == 0) if (strcmp_P(command + 9, PSTR("side_power")) == 0)
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
::Focus.send(Kaleidoscope.device().side.getPower()); ::Focus.send(Runtime.device().side.getPower());
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} else { } else {
uint8_t power; uint8_t power;
::Focus.read(power); ::Focus.read(power);
Kaleidoscope.device().side.setPower(power); Runtime.device().side.setPower(power);
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
if (strcmp_P(command + 9, PSTR("side_ver")) == 0) { if (strcmp_P(command + 9, PSTR("side_ver")) == 0) {
::Focus.send("left:"); ::Focus.send("left:");
::Focus.send(Kaleidoscope.device().side.leftVersion()); ::Focus.send(Runtime.device().side.leftVersion());
::Focus.send("\nright:"); ::Focus.send("\nright:");
::Focus.send(Kaleidoscope.device().side.rightVersion()); ::Focus.send(Runtime.device().side.rightVersion());
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
if (strcmp_P(command + 9, PSTR("crc_errors")) == 0) { if (strcmp_P(command + 9, PSTR("crc_errors")) == 0) {
::Focus.send("left:"); ::Focus.send("left:");
::Focus.send(Kaleidoscope.device().side.leftCRCErrors()); ::Focus.send(Runtime.device().side.leftCRCErrors());
::Focus.send("\nright:"); ::Focus.send("\nright:");
::Focus.send(Kaleidoscope.device().side.rightCRCErrors()); ::Focus.send(Runtime.device().side.rightCRCErrors());
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
if (strcmp_P(command + 9, PSTR("sled_ver")) == 0) { if (strcmp_P(command + 9, PSTR("sled_ver")) == 0) {
::Focus.send("left:"); ::Focus.send("left:");
::Focus.send(Kaleidoscope.device().side.leftSLEDVersion()); ::Focus.send(Runtime.device().side.leftSLEDVersion());
::Focus.send("\nright:"); ::Focus.send("\nright:");
::Focus.send(Kaleidoscope.device().side.rightSLEDVersion()); ::Focus.send(Runtime.device().side.rightSLEDVersion());
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
if (strcmp_P(command + 9, PSTR("sled_current")) == 0) if (strcmp_P(command + 9, PSTR("sled_current")) == 0)
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
::Focus.send("left:"); ::Focus.send("left:");
::Focus.send(Kaleidoscope.device().side.leftSLEDCurrent()); ::Focus.send(Runtime.device().side.leftSLEDCurrent());
::Focus.send("\nright:"); ::Focus.send("\nright:");
::Focus.send(Kaleidoscope.device().side.rightSLEDCurrent()); ::Focus.send(Runtime.device().side.rightSLEDCurrent());
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} else { } else {
uint8_t current; uint8_t current;
::Focus.read(current); ::Focus.read(current);
Kaleidoscope.device().side.setSLEDCurrent(current); Runtime.device().side.setSLEDCurrent(current);
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
if (strcmp_P(command + 9, PSTR("layout")) == 0) { if (strcmp_P(command + 9, PSTR("layout")) == 0) {
static const auto ANSI = Kaleidoscope.device().settings.Layout::ANSI; static const auto ANSI = Runtime.device().settings.Layout::ANSI;
::Focus.send(Kaleidoscope.device().settings.layout() == ANSI ? "ANSI" : "ISO"); ::Focus.send(Runtime.device().settings.layout() == ANSI ? "ANSI" : "ISO");
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
if (strcmp_P(command + 9, PSTR("joint")) == 0) { if (strcmp_P(command + 9, PSTR("joint")) == 0) {
::Focus.send(Kaleidoscope.device().settings.joint()); ::Focus.send(Runtime.device().settings.joint());
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
if (strcmp_P(command + 9, PSTR("keyscan")) == 0) { if (strcmp_P(command + 9, PSTR("keyscan")) == 0) {
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
::Focus.send(Kaleidoscope.device().settings.keyscanInterval()); ::Focus.send(Runtime.device().settings.keyscanInterval());
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} else { } else {
uint8_t keyscan; uint8_t keyscan;
::Focus.read(keyscan); ::Focus.read(keyscan);
Kaleidoscope.device().settings.keyscanInterval(keyscan); Runtime.device().settings.keyscanInterval(keyscan);
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
} }

@ -20,7 +20,7 @@
#ifdef ARDUINO_SAMD_RAISE #ifdef ARDUINO_SAMD_RAISE
#include <Kaleidoscope.h> #include "kaleidoscope/plugin.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {

@ -20,7 +20,8 @@
#ifdef ARDUINO_SAMD_RAISE #ifdef ARDUINO_SAMD_RAISE
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/plugin.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {
@ -39,9 +40,9 @@ class SideFlash : public kaleidoscope::Plugin {
if (strncmp_P(command, PSTR("hardware."), 9) != 0) if (strncmp_P(command, PSTR("hardware."), 9) != 0)
return EventHandlerResult::OK; return EventHandlerResult::OK;
auto sideFlasher = Kaleidoscope.device().sideFlasher(); auto sideFlasher = Runtime.device().sideFlasher();
uint8_t left_boot_address = Kaleidoscope.device().side.left_boot_address; uint8_t left_boot_address = Runtime.device().side.left_boot_address;
uint8_t right_boot_address = Kaleidoscope.device().side.right_boot_address; uint8_t right_boot_address = Runtime.device().side.right_boot_address;
enum { enum {
FLASH, FLASH,
VERIFY VERIFY
@ -65,7 +66,7 @@ class SideFlash : public kaleidoscope::Plugin {
} }
bool result; bool result;
Kaleidoscope.device().side.prepareForFlash(); Runtime.device().side.prepareForFlash();
if (sub_command == FLASH) if (sub_command == FLASH)
result = sideFlasher.flash(address, firmware); result = sideFlasher.flash(address, firmware);
else else

@ -27,10 +27,11 @@
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#ifdef ARDUINO_AVR_ERGODOX #ifdef ARDUINO_AVR_ERGODOX
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <KeyboardioHID.h> #include <KeyboardioHID.h>
#include <avr/wdt.h> #include <avr/wdt.h>
#include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h" #include "kaleidoscope/device/ez/ErgoDox/ErgoDoxScanner.h"
#include "kaleidoscope/key_events.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {

@ -18,7 +18,10 @@
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#ifdef ARDUINO_AVR_KBD4X #ifdef ARDUINO_AVR_KBD4X
#include <Kaleidoscope.h> #include "kaleidoscope/key_events.h"
#include "kaleidoscope/driver/keyscanner/ATmega.h"
#include "kaleidoscope/driver/keyscanner/Base_Impl.h"
#include "kaleidoscope/Runtime.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {

@ -17,7 +17,8 @@
#ifdef ARDUINO_AVR_KEYBOARDIO_IMAGO #ifdef ARDUINO_AVR_KEYBOARDIO_IMAGO
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/driver/keyscanner/Base_Impl.h"
extern "C" { extern "C" {
#include "twi.h" #include "twi.h"
@ -81,7 +82,7 @@ void ImagoLEDDriver::selectRegister(uint8_t page) {
} }
void ImagoLEDDriver::setCrgbAt(uint8_t i, cRGB crgb) { void ImagoLEDDriver::setCrgbAt(uint8_t i, cRGB crgb) {
if (!Kaleidoscope.device().LEDs().isValid(i)) if (!Runtime.device().LEDs().isValid(i))
return; return;
cRGB oldColor = getCrgbAt(i); cRGB oldColor = getCrgbAt(i);
@ -91,7 +92,7 @@ void ImagoLEDDriver::setCrgbAt(uint8_t i, cRGB crgb) {
} }
cRGB ImagoLEDDriver::getCrgbAt(uint8_t i) { cRGB ImagoLEDDriver::getCrgbAt(uint8_t i) {
if (!Kaleidoscope.device().LEDs().isValid(i)) if (!Runtime.device().LEDs().isValid(i))
return {0, 0, 0}; return {0, 0, 0};
return led_data[i]; return led_data[i];

@ -17,7 +17,10 @@
#ifdef ARDUINO_AVR_MODEL01 #ifdef ARDUINO_AVR_MODEL01
#include <Kaleidoscope.h> #include "Arduino.h" // for PROGMEM
#include "kaleidoscope/device/keyboardio/Model01.h" // for Model01LEDDriver...
#include "kaleidoscope/key_events.h"
#include "kaleidoscope/driver/keyscanner/Base_Impl.h"
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#include <KeyboardioHID.h> #include <KeyboardioHID.h>

@ -18,7 +18,8 @@
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#ifdef ARDUINO_AVR_PLANCK #ifdef ARDUINO_AVR_PLANCK
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/driver/keyscanner/Base_Impl.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {

@ -25,7 +25,8 @@
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#ifdef ARDUINO_AVR_SPLITOGRAPHY #ifdef ARDUINO_AVR_SPLITOGRAPHY
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/driver/keyscanner/Base_Impl.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {

@ -27,7 +27,8 @@
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#ifdef ARDUINO_AVR_ATREUS #ifdef ARDUINO_AVR_ATREUS
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/driver/keyscanner/Base_Impl.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {

@ -19,7 +19,8 @@
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#ifdef ARDUINO_AVR_ATREUS2 #ifdef ARDUINO_AVR_ATREUS2
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/driver/keyscanner/Base_Impl.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace device { namespace device {

@ -22,7 +22,10 @@
#include "kaleidoscope/device/virtual/Logging.h" #include "kaleidoscope/device/virtual/Logging.h"
#include "kaleidoscope/keyswitch_state.h" #include "kaleidoscope/keyswitch_state.h"
#include "Kaleidoscope.h" #include "kaleidoscope/MatrixAddr.h"
#include "kaleidoscope/key_defs.h"
#include "kaleidoscope/key_events.h"
#include "HIDReportObserver.h" #include "HIDReportObserver.h"
#include "virtual_io.h" #include "virtual_io.h"
@ -30,7 +33,6 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <iomanip>
// FIXME: This relates to virtual/cores/arduino/EEPROM.h. // FIXME: This relates to virtual/cores/arduino/EEPROM.h.
// EEPROM static data must be defined here as only // EEPROM static data must be defined here as only

@ -16,7 +16,7 @@
*/ */
#ifndef KALEIDOSCOPE_VIRTUAL_BUILD #ifndef KALEIDOSCOPE_VIRTUAL_BUILD
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#ifdef KALEIDOSCOPE_BOOTLOADER_FLIP_WORKAROUND #ifdef KALEIDOSCOPE_BOOTLOADER_FLIP_WORKAROUND
#include "kaleidoscope/driver/bootloader/avr/FLIP.h" #include "kaleidoscope/driver/bootloader/avr/FLIP.h"

@ -57,7 +57,7 @@
uint8_t kaleidoscope::Device::KeyScanner::debounce_matrix_[kaleidoscope::Device::KeyScannerProps::matrix_rows][kaleidoscope::Device::KeyScannerProps::matrix_columns] = {}; \ uint8_t kaleidoscope::Device::KeyScanner::debounce_matrix_[kaleidoscope::Device::KeyScannerProps::matrix_rows][kaleidoscope::Device::KeyScannerProps::matrix_columns] = {}; \
\ \
ISR(TIMER1_OVF_vect) { \ ISR(TIMER1_OVF_vect) { \
Kaleidoscope.device().readMatrix(); \ Runtime.device().readMatrix(); \
} }
namespace kaleidoscope { namespace kaleidoscope {

@ -0,0 +1,33 @@
/* -*- mode: c++ -*-
* kaleidoscope::driver::keyscanner::base -- Keyscanner base class
* Copyright (C) 2019 Keyboard.io, Inc
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "kaleidoscope/driver/keyscanner/Base.h"
#include "kaleidoscope/device/device.h"
namespace kaleidoscope {
namespace driver {
namespace keyscanner {
template<>
void Base<kaleidoscope::Device::Props::KeyScannerProps>::handleKeyswitchEvent(Key mappedKey, kaleidoscope::Device::Props::KeyScannerProps::KeyAddr key_addr, uint8_t keyState) {
::handleKeyswitchEvent(mappedKey, key_addr, keyState);
}
} // namespace keyscanner
} // namespace driver
} // namespace kaleidoscope

@ -14,7 +14,9 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Kaleidoscope.h" #include "kaleidoscope/event_handler_result.h"
#include "kaleidoscope/event_handlers.h"
#include "kaleidoscope/macro_helpers.h"
#include "kaleidoscope/hooks.h" #include "kaleidoscope/hooks.h"
namespace kaleidoscope { namespace kaleidoscope {

@ -59,9 +59,9 @@ class Hooks {
// The following friend declarations restrict access to // The following friend declarations restrict access to
// the hook routing system. // the hook routing system.
// Kaleidoscope_ calls Hooks::onSetup, Hooks::beforeReportingState // Runtime_ calls Hooks::onSetup, Hooks::beforeReportingState
// and Hooks::afterEachCycle. // and Hooks::afterEachCycle.
friend class Kaleidoscope_; friend class Runtime_;
friend class ::kaleidoscope::Layer_; friend class ::kaleidoscope::Layer_;
friend class ::kaleidoscope::plugin::LEDControl; friend class ::kaleidoscope::plugin::LEDControl;
friend void ::kaleidoscope::sketch_exploration::pluginsExploreSketch(); friend void ::kaleidoscope::sketch_exploration::pluginsExploreSketch();

@ -16,6 +16,8 @@
#pragma once #pragma once
#include <stdint.h>
#include "kaleidoscope_internal/deprecations.h" #include "kaleidoscope_internal/deprecations.h"
static const uint8_t LAYER_SHIFT_OFFSET = 42; static const uint8_t LAYER_SHIFT_OFFSET = 42;

@ -14,9 +14,11 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "kaleidoscope/Kaleidoscope.h" #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/hooks.h" #include "kaleidoscope/hooks.h"
#include "kaleidoscope/plugin.h" #include "kaleidoscope/keyswitch_state.h"
#include "kaleidoscope/hid.h"
#include "kaleidoscope/layers.h"
static bool handleSyntheticKeyswitchEvent(Key mappedKey, uint8_t keyState) { static bool handleSyntheticKeyswitchEvent(Key mappedKey, uint8_t keyState) {
if (mappedKey.getFlags() & RESERVED) if (mappedKey.getFlags() & RESERVED)
@ -60,6 +62,9 @@ static bool handleKeyswitchEventDefault(Key mappedKey, KeyAddr key_addr, uint8_t
} }
void handleKeyswitchEvent(Key mappedKey, KeyAddr key_addr, uint8_t keyState) { void handleKeyswitchEvent(Key mappedKey, KeyAddr key_addr, uint8_t keyState) {
using kaleidoscope::Runtime;
/* These first steps are only done for keypresses that have a valid key_addr. /* These first steps are only done for keypresses that have a valid key_addr.
* In particular, doing them for keypresses with out-of-bounds key_addr * In particular, doing them for keypresses with out-of-bounds key_addr
* would cause out-of-bounds array accesses in Layer.lookup(), * would cause out-of-bounds array accesses in Layer.lookup(),
@ -96,9 +101,9 @@ void handleKeyswitchEvent(Key mappedKey, KeyAddr key_addr, uint8_t keyState) {
* See layers.cpp for an example that masks keys, and the reason why it does * See layers.cpp for an example that masks keys, and the reason why it does
* so. * so.
*/ */
if (Kaleidoscope.device().isKeyMasked(key_addr)) { if (Runtime.device().isKeyMasked(key_addr)) {
if (keyToggledOff(keyState)) { if (keyToggledOff(keyState)) {
Kaleidoscope.device().unMaskKey(key_addr); Runtime.device().unMaskKey(key_addr);
} else { } else {
return; return;
} }

@ -17,9 +17,11 @@
#pragma once #pragma once
#include <Arduino.h> #include <Arduino.h>
#include "kaleidoscope/driver/keyscanner/Base.h"
#include "kaleidoscope/device/device.h" #include "kaleidoscope/device/device.h"
#include "kaleidoscope/key_defs.h" #include "kaleidoscope/key_defs.h"
#include "kaleidoscope/keyswitch_state.h" #include "kaleidoscope/keyswitch_state.h"
#include "kaleidoscope/KeyAddr.h"
// Code can use this macro on injected key events to signal that // Code can use this macro on injected key events to signal that
@ -76,16 +78,3 @@ void handleKeyswitchEvent(Key mappedKey, kaleidoscope::Device::Props::KeyScanner
DEPRECATED(ROW_COL_FUNC) inline void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) { DEPRECATED(ROW_COL_FUNC) inline void handleKeyswitchEvent(Key mappedKey, byte row, byte col, uint8_t keyState) {
handleKeyswitchEvent(mappedKey, KeyAddr(row, col), keyState); handleKeyswitchEvent(mappedKey, KeyAddr(row, col), keyState);
} }
namespace kaleidoscope {
namespace driver {
namespace keyscanner {
template<>
inline
void Base<kaleidoscope::Device::Props::KeyScannerProps>::handleKeyswitchEvent(Key mappedKey, kaleidoscope::Device::Props::KeyScannerProps::KeyAddr key_addr, uint8_t keyState) {
::handleKeyswitchEvent(mappedKey, key_addr, keyState);
}
} // namespace keyscanner
} // namespace driver
} // namespace kaleidoscope

@ -17,6 +17,8 @@
#pragma once #pragma once
#include "kaleidoscope/key_defs.h" #include "kaleidoscope/key_defs.h"
#include "kaleidoscope/KeyAddr.h"
#include "kaleidoscope_internal/device.h"
extern const Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns]; extern const Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows * kaleidoscope_internal::device.matrix_columns];

@ -14,7 +14,9 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "kaleidoscope/Kaleidoscope.h" #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/layers.h"
#include "kaleidoscope/keyswitch_state.h"
// The maximum number of layers allowed. `layer_state_`, which stores // The maximum number of layers allowed. `layer_state_`, which stores
// the on/off status of the layers in a bitfield has only 32 bits, and // the on/off status of the layers in a bitfield has only 32 bits, and
@ -38,8 +40,8 @@ extern constexpr Key keymaps_linear[][kaleidoscope_internal::device.matrix_rows
namespace kaleidoscope { namespace kaleidoscope {
uint32_t Layer_::layer_state_; uint32_t Layer_::layer_state_;
uint8_t Layer_::top_active_layer_; uint8_t Layer_::top_active_layer_;
Key Layer_::live_composite_keymap_[Kaleidoscope.device().numKeys()]; Key Layer_::live_composite_keymap_[Runtime.device().numKeys()];
uint8_t Layer_::active_layers_[Kaleidoscope.device().numKeys()]; uint8_t Layer_::active_layers_[Runtime.device().numKeys()];
Layer_::GetKeyFunction Layer_::getKey = &Layer_::getKeyFromPROGMEM; Layer_::GetKeyFunction Layer_::getKey = &Layer_::getKeyFromPROGMEM;
void Layer_::handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) { void Layer_::handleKeymapKeyswitchEvent(Key keymapEntry, uint8_t keyState) {
@ -111,7 +113,7 @@ void Layer_::updateLiveCompositeKeymap(KeyAddr key_addr) {
} }
void Layer_::updateActiveLayers(void) { void Layer_::updateActiveLayers(void) {
memset(active_layers_, 0, Kaleidoscope.device().numKeys()); memset(active_layers_, 0, Runtime.device().numKeys());
for (auto key_addr : KeyAddr::all()) { for (auto key_addr : KeyAddr::all()) {
int8_t layer = top_active_layer_; int8_t layer = top_active_layer_;

@ -19,6 +19,7 @@
#include <Kaleidoscope-Colormap.h> #include <Kaleidoscope-Colormap.h>
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-FocusSerial.h> #include <Kaleidoscope-FocusSerial.h>
#include "kaleidoscope/layers.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -36,7 +37,7 @@ void ColormapEffect::max_layers(uint8_t max_) {
} }
void ColormapEffect::TransientLEDMode::onActivate(void) { void ColormapEffect::TransientLEDMode::onActivate(void) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
parent_->top_layer_ = Layer.top(); parent_->top_layer_ = Layer.top();

@ -15,9 +15,11 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-Cycle.h> #include <Kaleidoscope-Cycle.h>
#include "kaleidoscope/hid.h" #include "kaleidoscope/hid.h"
#include "kaleidoscope/keyswitch_state.h"
#include "kaleidoscope/key_events.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-Ranges.h> #include <Kaleidoscope-Ranges.h>
#define Key_Cycle Key(kaleidoscope::ranges::CYCLE) #define Key_Cycle Key(kaleidoscope::ranges::CYCLE)

@ -25,7 +25,7 @@ uint32_t CycleTimeReport::loop_start_time_;
uint32_t CycleTimeReport::average_loop_time; uint32_t CycleTimeReport::average_loop_time;
EventHandlerResult CycleTimeReport::onSetup() { EventHandlerResult CycleTimeReport::onSetup() {
last_report_time_ = Kaleidoscope.millisAtCycleStart(); last_report_time_ = Runtime.millisAtCycleStart();
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -42,11 +42,11 @@ EventHandlerResult CycleTimeReport::afterEachCycle() {
else else
average_loop_time = loop_time; average_loop_time = loop_time;
if (Kaleidoscope.hasTimeExpired(last_report_time_, uint16_t(1000))) { if (Runtime.hasTimeExpired(last_report_time_, uint16_t(1000))) {
cycleTimeReport(); cycleTimeReport();
average_loop_time = 0; average_loop_time = 0;
last_report_time_ = Kaleidoscope.millisAtCycleStart(); last_report_time_ = Runtime.millisAtCycleStart();
} }
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -17,6 +17,8 @@
#include "Kaleidoscope-DynamicMacros.h" #include "Kaleidoscope-DynamicMacros.h"
#include "kaleidoscope/hid.h" #include "kaleidoscope/hid.h"
#include "Kaleidoscope-FocusSerial.h" #include "Kaleidoscope-FocusSerial.h"
#include "kaleidoscope/keyswitch_state.h"
#include "kaleidoscope/key_events.h"
using namespace kaleidoscope::ranges; using namespace kaleidoscope::ranges;
@ -47,7 +49,7 @@ static void playKeyCode(Key key, uint8_t keyStates, bool explicit_report) {
} }
static void readKeyCodeAndPlay(uint16_t pos, uint8_t flags, uint8_t keyStates, bool explicit_report) { static void readKeyCodeAndPlay(uint16_t pos, uint8_t flags, uint8_t keyStates, bool explicit_report) {
Key key(Kaleidoscope.storage().read(pos++), // key_code Key key(Runtime.storage().read(pos++), // key_code
flags); flags);
playKeyCode(key, keyStates, explicit_report); playKeyCode(key, keyStates, explicit_report);
@ -62,7 +64,7 @@ void DynamicMacros::updateDynamicMacroCache(void) {
map_[0] = 0; map_[0] = 0;
while (pos < storage_base_ + storage_size_) { while (pos < storage_base_ + storage_size_) {
macro = Kaleidoscope.storage().read(pos++); macro = Runtime.storage().read(pos++);
switch (macro) { switch (macro) {
case MACRO_ACTION_STEP_EXPLICIT_REPORT: case MACRO_ACTION_STEP_EXPLICIT_REPORT:
case MACRO_ACTION_STEP_IMPLICIT_REPORT: case MACRO_ACTION_STEP_IMPLICIT_REPORT:
@ -90,8 +92,8 @@ void DynamicMacros::updateDynamicMacroCache(void) {
previous_macro_ended = false; previous_macro_ended = false;
uint8_t keyCode, flags; uint8_t keyCode, flags;
do { do {
flags = Kaleidoscope.storage().read(pos++); flags = Runtime.storage().read(pos++);
keyCode = Kaleidoscope.storage().read(pos++); keyCode = Runtime.storage().read(pos++);
} while (!(flags == 0 && keyCode == 0)); } while (!(flags == 0 && keyCode == 0));
break; break;
} }
@ -100,7 +102,7 @@ void DynamicMacros::updateDynamicMacroCache(void) {
previous_macro_ended = false; previous_macro_ended = false;
uint8_t keyCode, flags; uint8_t keyCode, flags;
do { do {
keyCode = Kaleidoscope.storage().read(pos++); keyCode = Runtime.storage().read(pos++);
} while (keyCode != 0); } while (keyCode != 0);
break; break;
} }
@ -127,7 +129,7 @@ void DynamicMacros::play(uint8_t macro_id) {
pos = storage_base_ + map_[macro_id]; pos = storage_base_ + map_[macro_id];
while (true) { while (true) {
switch (macro = Kaleidoscope.storage().read(pos++)) { switch (macro = Runtime.storage().read(pos++)) {
case MACRO_ACTION_STEP_EXPLICIT_REPORT: case MACRO_ACTION_STEP_EXPLICIT_REPORT:
explicit_report = true; explicit_report = true;
break; break;
@ -139,23 +141,23 @@ void DynamicMacros::play(uint8_t macro_id) {
kaleidoscope::hid::sendMouseReport(); kaleidoscope::hid::sendMouseReport();
break; break;
case MACRO_ACTION_STEP_INTERVAL: case MACRO_ACTION_STEP_INTERVAL:
interval = Kaleidoscope.storage().read(pos++); interval = Runtime.storage().read(pos++);
break; break;
case MACRO_ACTION_STEP_WAIT: { case MACRO_ACTION_STEP_WAIT: {
uint8_t wait = Kaleidoscope.storage().read(pos++); uint8_t wait = Runtime.storage().read(pos++);
delay(wait); delay(wait);
break; break;
} }
case MACRO_ACTION_STEP_KEYDOWN: case MACRO_ACTION_STEP_KEYDOWN:
flags = Kaleidoscope.storage().read(pos++); flags = Runtime.storage().read(pos++);
readKeyCodeAndPlay(pos++, flags, IS_PRESSED, explicit_report); readKeyCodeAndPlay(pos++, flags, IS_PRESSED, explicit_report);
break; break;
case MACRO_ACTION_STEP_KEYUP: case MACRO_ACTION_STEP_KEYUP:
flags = Kaleidoscope.storage().read(pos++); flags = Runtime.storage().read(pos++);
readKeyCodeAndPlay(pos++, flags, WAS_PRESSED, explicit_report); readKeyCodeAndPlay(pos++, flags, WAS_PRESSED, explicit_report);
break; break;
case MACRO_ACTION_STEP_TAP: case MACRO_ACTION_STEP_TAP:
flags = Kaleidoscope.storage().read(pos++); flags = Runtime.storage().read(pos++);
readKeyCodeAndPlay(pos++, flags, IS_PRESSED | WAS_PRESSED, false); readKeyCodeAndPlay(pos++, flags, IS_PRESSED | WAS_PRESSED, false);
break; break;
@ -172,8 +174,8 @@ void DynamicMacros::play(uint8_t macro_id) {
case MACRO_ACTION_STEP_TAP_SEQUENCE: { case MACRO_ACTION_STEP_TAP_SEQUENCE: {
uint8_t keyCode; uint8_t keyCode;
do { do {
flags = Kaleidoscope.storage().read(pos++); flags = Runtime.storage().read(pos++);
keyCode = Kaleidoscope.storage().read(pos++); keyCode = Runtime.storage().read(pos++);
playKeyCode(Key(keyCode, flags), IS_PRESSED | WAS_PRESSED, false); playKeyCode(Key(keyCode, flags), IS_PRESSED | WAS_PRESSED, false);
delay(interval); delay(interval);
} while (!(flags == 0 && keyCode == 0)); } while (!(flags == 0 && keyCode == 0));
@ -182,7 +184,7 @@ void DynamicMacros::play(uint8_t macro_id) {
case MACRO_ACTION_STEP_TAP_CODE_SEQUENCE: { case MACRO_ACTION_STEP_TAP_CODE_SEQUENCE: {
uint8_t keyCode; uint8_t keyCode;
do { do {
keyCode = Kaleidoscope.storage().read(pos++); keyCode = Runtime.storage().read(pos++);
playKeyCode(Key(keyCode, 0), IS_PRESSED | WAS_PRESSED, false); playKeyCode(Key(keyCode, 0), IS_PRESSED | WAS_PRESSED, false);
delay(interval); delay(interval);
} while (keyCode != 0); } while (keyCode != 0);
@ -220,7 +222,7 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) {
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
for (uint16_t i = 0; i < storage_size_; i++) { for (uint16_t i = 0; i < storage_size_; i++) {
uint8_t b; uint8_t b;
b = Kaleidoscope.storage().read(storage_base_ + i); b = Runtime.storage().read(storage_base_ + i);
::Focus.send(b); ::Focus.send(b);
} }
} else { } else {
@ -230,9 +232,9 @@ EventHandlerResult DynamicMacros::onFocusEvent(const char *command) {
uint8_t b; uint8_t b;
::Focus.read(b); ::Focus.read(b);
Kaleidoscope.storage().update(storage_base_ + pos++, b); Runtime.storage().update(storage_base_ + pos++, b);
} }
Kaleidoscope.storage().commit(); Runtime.storage().commit();
updateDynamicMacroCache(); updateDynamicMacroCache();
} }
} }

@ -16,7 +16,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-Ranges.h> #include <Kaleidoscope-Ranges.h>

@ -17,6 +17,8 @@
#include <Kaleidoscope-EEPROM-Keymap-Programmer.h> #include <Kaleidoscope-EEPROM-Keymap-Programmer.h>
#include <Kaleidoscope-FocusSerial.h> #include <Kaleidoscope-FocusSerial.h>
#include "kaleidoscope/keyswitch_state.h"
#include "kaleidoscope/layers.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -39,7 +41,7 @@ void EEPROMKeymapProgrammer::nextState(void) {
case WAIT_FOR_CODE: case WAIT_FOR_CODE:
case WAIT_FOR_SOURCE_KEY: case WAIT_FOR_SOURCE_KEY:
::EEPROMKeymap.updateKey(update_position_, new_key_); ::EEPROMKeymap.updateKey(update_position_, new_key_);
Kaleidoscope.storage().commit(); Runtime.storage().commit();
cancel(); cancel();
break; break;
} }
@ -57,10 +59,10 @@ EventHandlerResult EEPROMKeymapProgrammer::onKeyswitchEvent(Key &mapped_key, Key
if (state_ == WAIT_FOR_KEY) { if (state_ == WAIT_FOR_KEY) {
if (keyToggledOn(key_state)) { if (keyToggledOn(key_state)) {
update_position_ = Layer.top() * Kaleidoscope.device().numKeys() + key_addr.toInt(); update_position_ = Layer.top() * Runtime.device().numKeys() + key_addr.toInt();
} }
if (keyToggledOff(key_state)) { if (keyToggledOff(key_state)) {
if ((uint16_t)(Layer.top() * Kaleidoscope.device().numKeys() + key_addr.toInt()) == update_position_) if ((uint16_t)(Layer.top() * Runtime.device().numKeys() + key_addr.toInt()) == update_position_)
nextState(); nextState();
} }
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-EEPROM-Keymap.h> #include <Kaleidoscope-EEPROM-Keymap.h>
namespace kaleidoscope { namespace kaleidoscope {

@ -18,6 +18,7 @@
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-EEPROM-Keymap.h> #include <Kaleidoscope-EEPROM-Keymap.h>
#include <Kaleidoscope-FocusSerial.h> #include <Kaleidoscope-FocusSerial.h>
#include "kaleidoscope/layers.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -44,17 +45,17 @@ void EEPROMKeymap::setup(uint8_t max) {
void EEPROMKeymap::max_layers(uint8_t max) { void EEPROMKeymap::max_layers(uint8_t max) {
max_layers_ = max; max_layers_ = max;
keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * Kaleidoscope.device().numKeys() * 2); keymap_base_ = ::EEPROMSettings.requestSlice(max_layers_ * Runtime.device().numKeys() * 2);
} }
Key EEPROMKeymap::getKey(uint8_t layer, KeyAddr key_addr) { Key EEPROMKeymap::getKey(uint8_t layer, KeyAddr key_addr) {
if (layer >= max_layers_) if (layer >= max_layers_)
return Key_NoKey; return Key_NoKey;
uint16_t pos = ((layer * Kaleidoscope.device().numKeys()) + key_addr.toInt()) * 2; uint16_t pos = ((layer * Runtime.device().numKeys()) + key_addr.toInt()) * 2;
return Key(Kaleidoscope.storage().read(keymap_base_ + pos + 1), // key_code return Key(Runtime.storage().read(keymap_base_ + pos + 1), // key_code
Kaleidoscope.storage().read(keymap_base_ + pos)); // flags Runtime.storage().read(keymap_base_ + pos)); // flags
} }
Key EEPROMKeymap::getKeyExtended(uint8_t layer, KeyAddr key_addr) { Key EEPROMKeymap::getKeyExtended(uint8_t layer, KeyAddr key_addr) {
@ -73,8 +74,8 @@ uint16_t EEPROMKeymap::keymap_base(void) {
} }
void EEPROMKeymap::updateKey(uint16_t base_pos, Key key) { void EEPROMKeymap::updateKey(uint16_t base_pos, Key key) {
Kaleidoscope.storage().update(keymap_base_ + base_pos * 2, key.getFlags()); Runtime.storage().update(keymap_base_ + base_pos * 2, key.getFlags());
Kaleidoscope.storage().update(keymap_base_ + base_pos * 2 + 1, key.getKeyCode()); Runtime.storage().update(keymap_base_ + base_pos * 2 + 1, key.getKeyCode());
} }
void EEPROMKeymap::dumpKeymap(uint8_t layers, Key(*getkey)(uint8_t, KeyAddr)) { void EEPROMKeymap::dumpKeymap(uint8_t layers, Key(*getkey)(uint8_t, KeyAddr)) {
@ -146,14 +147,14 @@ EventHandlerResult EEPROMKeymap::onFocusEvent(const char *command) {
} else { } else {
uint16_t i = 0; uint16_t i = 0;
while (!::Focus.isEOL() && (i < (uint16_t)Kaleidoscope.device().numKeys() * max_layers_)) { while (!::Focus.isEOL() && (i < (uint16_t)Runtime.device().numKeys() * max_layers_)) {
Key k; Key k;
::Focus.read(k); ::Focus.read(k);
updateKey(i, k); updateKey(i, k);
i++; i++;
} }
Kaleidoscope.storage().commit(); Runtime.storage().commit();
} }
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#define _DEPRECATED_MESSAGE_EEPROM_KEYMAP_SETUP_MODE \ #define _DEPRECATED_MESSAGE_EEPROM_KEYMAP_SETUP_MODE \

@ -18,6 +18,7 @@
#include <Kaleidoscope-EEPROM-Settings.h> #include <Kaleidoscope-EEPROM-Settings.h>
#include <Kaleidoscope-FocusSerial.h> #include <Kaleidoscope-FocusSerial.h>
#include "kaleidoscope/plugin/EEPROM-Settings/crc.h" #include "kaleidoscope/plugin/EEPROM-Settings/crc.h"
#include "kaleidoscope/layers.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -28,7 +29,7 @@ bool EEPROMSettings::sealed_;
uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings); uint16_t EEPROMSettings::next_start_ = sizeof(EEPROMSettings::settings);
EventHandlerResult EEPROMSettings::onSetup() { EventHandlerResult EEPROMSettings::onSetup() {
Kaleidoscope.storage().get(0, settings_); Runtime.storage().get(0, settings_);
/* If the version is undefined, set up sensible defaults. */ /* If the version is undefined, set up sensible defaults. */
if (settings_.version == VERSION_UNDEFINED) { if (settings_.version == VERSION_UNDEFINED) {
@ -49,8 +50,8 @@ EventHandlerResult EEPROMSettings::onSetup() {
* not able to catch all writes yet. For the sake of consistency, if we * not able to catch all writes yet. For the sake of consistency, if we
* encounter a firmware with no version defined, we'll set sensible * encounter a firmware with no version defined, we'll set sensible
* defaults. */ * defaults. */
Kaleidoscope.storage().put(0, settings_); Runtime.storage().put(0, settings_);
Kaleidoscope.storage().commit(); Runtime.storage().commit();
} }
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -147,8 +148,8 @@ uint16_t EEPROMSettings::used(void) {
} }
void EEPROMSettings::update(void) { void EEPROMSettings::update(void) {
Kaleidoscope.storage().put(0, settings_); Runtime.storage().put(0, settings_);
Kaleidoscope.storage().commit(); Runtime.storage().commit();
is_valid_ = true; is_valid_ = true;
} }
@ -222,22 +223,22 @@ EventHandlerResult FocusEEPROMCommand::onFocusEvent(const char *command) {
switch (sub_command) { switch (sub_command) {
case CONTENTS: { case CONTENTS: {
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
for (uint16_t i = 0; i < Kaleidoscope.storage().length(); i++) { for (uint16_t i = 0; i < Runtime.storage().length(); i++) {
uint8_t d = Kaleidoscope.storage().read(i); uint8_t d = Runtime.storage().read(i);
::Focus.send(d); ::Focus.send(d);
} }
} else { } else {
for (uint16_t i = 0; i < Kaleidoscope.storage().length() && !::Focus.isEOL(); i++) { for (uint16_t i = 0; i < Runtime.storage().length() && !::Focus.isEOL(); i++) {
uint8_t d; uint8_t d;
::Focus.read(d); ::Focus.read(d);
Kaleidoscope.storage().update(i, d); Runtime.storage().update(i, d);
} }
} }
break; break;
} }
case FREE: case FREE:
::Focus.send(Kaleidoscope.storage().length() - ::EEPROMSettings.used()); ::Focus.send(Runtime.storage().length() - ::EEPROMSettings.used());
break; break;
} }

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#define _DEPRECATED_MESSAGE_EEPROMSETTINGS_VERSION_SET \ #define _DEPRECATED_MESSAGE_EEPROMSETTINGS_VERSION_SET \
"The EEPROMSettings.version(uint8_t version) method has been deprecated,\n" \ "The EEPROMSettings.version(uint8_t version) method has been deprecated,\n" \

@ -15,9 +15,10 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-OneShot.h> #include <Kaleidoscope-OneShot.h>
#include <Kaleidoscope-Escape-OneShot.h> #include <Kaleidoscope-Escape-OneShot.h>
#include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -32,7 +33,7 @@ EventHandlerResult EscapeOneShot::onKeyswitchEvent(Key &mapped_key, KeyAddr key_
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
Kaleidoscope.device().maskKey(key_addr); Runtime.device().maskKey(key_addr);
::OneShot.cancel(true); ::OneShot.cancel(true);
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -21,6 +21,7 @@
#include <Kaleidoscope-FocusSerial.h> #include <Kaleidoscope-FocusSerial.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#include <Kaleidoscope-LED-Palette-Theme.h> #include <Kaleidoscope-LED-Palette-Theme.h>
#include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -46,7 +47,7 @@ void FingerPainter::toggle(void) {
} }
EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) { EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
if (!Kaleidoscope.has_leds || !edit_mode_) if (!Runtime.has_leds || !edit_mode_)
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (!keyToggledOn(key_state)) { if (!keyToggledOn(key_state)) {
@ -58,7 +59,7 @@ EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_
// TODO: The following works only for keyboards with LEDs for each key. // TODO: The following works only for keyboards with LEDs for each key.
uint8_t color_index = ::LEDPaletteTheme.lookupColorIndexAtPosition(color_base_, Kaleidoscope.device().getLedIndex(key_addr)); uint8_t color_index = ::LEDPaletteTheme.lookupColorIndexAtPosition(color_base_, Runtime.device().getLedIndex(key_addr));
// Find the next color in the palette that is different. // Find the next color in the palette that is different.
// But do not loop forever! // But do not loop forever!
@ -75,7 +76,7 @@ EventHandlerResult FingerPainter::onKeyswitchEvent(Key &mapped_key, KeyAddr key_
new_color = ::LEDPaletteTheme.lookupPaletteColor(color_index); new_color = ::LEDPaletteTheme.lookupPaletteColor(color_index);
} }
::LEDPaletteTheme.updateColorIndexAtPosition(color_base_, Kaleidoscope.device().getLedIndex(key_addr), color_index); ::LEDPaletteTheme.updateColorIndexAtPosition(color_base_, Runtime.device().getLedIndex(key_addr), color_index);
return EventHandlerResult::EVENT_CONSUMED; return EventHandlerResult::EVENT_CONSUMED;
} }
@ -100,10 +101,10 @@ EventHandlerResult FingerPainter::onFocusEvent(const char *command) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (sub_command == CLEAR) { if (sub_command == CLEAR) {
for (uint16_t i = 0; i < Kaleidoscope.device().numKeys() / 2; i++) { for (uint16_t i = 0; i < Runtime.device().numKeys() / 2; i++) {
Kaleidoscope.storage().update(color_base_ + i, 0); Runtime.storage().update(color_base_ + i, 0);
} }
Kaleidoscope.storage().commit(); Runtime.storage().commit();
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }

@ -23,7 +23,7 @@
#ifdef __AVR__ #ifdef __AVR__
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -27,20 +27,20 @@ namespace plugin {
char FocusSerial::command_[32]; char FocusSerial::command_[32];
void FocusSerial::drain(void) { void FocusSerial::drain(void) {
if (Kaleidoscope.serialPort().available()) if (Runtime.serialPort().available())
while (Kaleidoscope.serialPort().peek() != '\n') while (Runtime.serialPort().peek() != '\n')
Kaleidoscope.serialPort().read(); Runtime.serialPort().read();
} }
EventHandlerResult FocusSerial::beforeReportingState() { EventHandlerResult FocusSerial::beforeReportingState() {
if (Kaleidoscope.serialPort().available() == 0) if (Runtime.serialPort().available() == 0)
return EventHandlerResult::OK; return EventHandlerResult::OK;
uint8_t i = 0; uint8_t i = 0;
do { do {
command_[i++] = Kaleidoscope.serialPort().read(); command_[i++] = Runtime.serialPort().read();
if (Kaleidoscope.serialPort().peek() == '\n') if (Runtime.serialPort().peek() == '\n')
break; break;
} while (command_[i - 1] != ' ' && i < 32); } while (command_[i - 1] != ' ' && i < 32);
if (command_[i - 1] == ' ') if (command_[i - 1] == ' ')
@ -48,14 +48,14 @@ EventHandlerResult FocusSerial::beforeReportingState() {
else else
command_[i] = '\0'; command_[i] = '\0';
Kaleidoscope.onFocusEvent(command_); Runtime.onFocusEvent(command_);
Kaleidoscope.serialPort().println(F("\r\n.")); Runtime.serialPort().println(F("\r\n."));
drain(); drain();
if (Kaleidoscope.serialPort().peek() == '\n') if (Runtime.serialPort().peek() == '\n')
Kaleidoscope.serialPort().read(); Runtime.serialPort().read();
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -65,7 +65,7 @@ bool FocusSerial::handleHelp(const char *command,
if (strcmp_P(command, PSTR("help")) != 0) if (strcmp_P(command, PSTR("help")) != 0)
return false; return false;
Kaleidoscope.serialPort().println((const __FlashStringHelper *)help_message); Runtime.serialPort().println((const __FlashStringHelper *)help_message);
return true; return true;
} }
@ -75,7 +75,7 @@ EventHandlerResult FocusSerial::onFocusEvent(const char *command) {
} }
void FocusSerial::printBool(bool b) { void FocusSerial::printBool(bool b) {
Kaleidoscope.serialPort().print((b) ? F("true") : F("false")); Runtime.serialPort().print((b) ? F("true") : F("false"));
} }
} }

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -37,12 +37,12 @@ class FocusSerial : public kaleidoscope::Plugin {
} }
void send(const bool b) { void send(const bool b) {
printBool(b); printBool(b);
Kaleidoscope.serialPort().print(SEPARATOR); Runtime.serialPort().print(SEPARATOR);
} }
template <typename V> template <typename V>
void send(V v) { void send(V v) {
Kaleidoscope.serialPort().print(v); Runtime.serialPort().print(v);
Kaleidoscope.serialPort().print(SEPARATOR); Runtime.serialPort().print(SEPARATOR);
} }
template <typename Var, typename... Vars> template <typename Var, typename... Vars>
void send(Var v, Vars... vars) { void send(Var v, Vars... vars) {
@ -53,31 +53,31 @@ class FocusSerial : public kaleidoscope::Plugin {
void sendRaw() {} void sendRaw() {}
template <typename Var, typename... Vars> template <typename Var, typename... Vars>
void sendRaw(Var v, Vars... vars) { void sendRaw(Var v, Vars... vars) {
Kaleidoscope.serialPort().print(v); Runtime.serialPort().print(v);
sendRaw(vars...); sendRaw(vars...);
} }
const char peek() { const char peek() {
return Kaleidoscope.serialPort().peek(); return Runtime.serialPort().peek();
} }
void read(Key &key) { void read(Key &key) {
key.setRaw(Kaleidoscope.serialPort().parseInt()); key.setRaw(Runtime.serialPort().parseInt());
} }
void read(cRGB &color) { void read(cRGB &color) {
color.r = Kaleidoscope.serialPort().parseInt(); color.r = Runtime.serialPort().parseInt();
color.g = Kaleidoscope.serialPort().parseInt(); color.g = Runtime.serialPort().parseInt();
color.b = Kaleidoscope.serialPort().parseInt(); color.b = Runtime.serialPort().parseInt();
} }
void read(uint8_t &u8) { void read(uint8_t &u8) {
u8 = Kaleidoscope.serialPort().parseInt(); u8 = Runtime.serialPort().parseInt();
} }
void read(uint16_t &u16) { void read(uint16_t &u16) {
u16 = Kaleidoscope.serialPort().parseInt(); u16 = Runtime.serialPort().parseInt();
} }
bool isEOL() { bool isEOL() {
return Kaleidoscope.serialPort().peek() == '\n'; return Runtime.serialPort().peek() == '\n';
} }
static constexpr char COMMENT = '#'; static constexpr char COMMENT = '#';

@ -16,6 +16,7 @@
*/ */
#include <Kaleidoscope-Steno.h> #include <Kaleidoscope-Steno.h>
#include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -39,7 +40,7 @@ EventHandlerResult GeminiPR::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr,
if (keys_held_ == 0) { if (keys_held_ == 0) {
state_[0] |= 0x80; state_[0] |= 0x80;
Kaleidoscope.serialPort().write(state_, sizeof(state_)); Runtime.serialPort().write(state_, sizeof(state_));
memset(state_, 0, sizeof(state_)); memset(state_, 0, sizeof(state_));
} }
} }

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-Ranges.h> #include <Kaleidoscope-Ranges.h>
#define S(n) Key(kaleidoscope::plugin::steno::geminipr::n) #define S(n) Key(kaleidoscope::plugin::steno::geminipr::n)

@ -15,8 +15,9 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-GhostInTheFirmware.h> #include <Kaleidoscope-GhostInTheFirmware.h>
#include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -46,11 +47,11 @@ EventHandlerResult GhostInTheFirmware::beforeReportingState() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
is_pressed_ = true; is_pressed_ = true;
start_time_ = Kaleidoscope.millisAtCycleStart(); start_time_ = Runtime.millisAtCycleStart();
} else { } else {
if (is_pressed_ && Kaleidoscope.hasTimeExpired(start_time_, press_timeout_)) { if (is_pressed_ && Runtime.hasTimeExpired(start_time_, press_timeout_)) {
is_pressed_ = false; is_pressed_ = false;
start_time_ = Kaleidoscope.millisAtCycleStart(); start_time_ = Runtime.millisAtCycleStart();
byte row = pgm_read_byte(&(ghost_keys[current_pos_].row)); byte row = pgm_read_byte(&(ghost_keys[current_pos_].row));
byte col = pgm_read_byte(&(ghost_keys[current_pos_].col)); byte col = pgm_read_byte(&(ghost_keys[current_pos_].col));
@ -61,7 +62,7 @@ EventHandlerResult GhostInTheFirmware::beforeReportingState() {
byte col = pgm_read_byte(&(ghost_keys[current_pos_].col)); byte col = pgm_read_byte(&(ghost_keys[current_pos_].col));
handleKeyswitchEvent(Key_NoKey, KeyAddr(row, col), IS_PRESSED); handleKeyswitchEvent(Key_NoKey, KeyAddr(row, col), IS_PRESSED);
} else if (Kaleidoscope.hasTimeExpired(start_time_, delay_timeout_)) { } else if (Runtime.hasTimeExpired(start_time_, delay_timeout_)) {
current_pos_++; current_pos_++;
press_timeout_ = 0; press_timeout_ = 0;
} }

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -14,9 +14,10 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "Kaleidoscope.h" #include "kaleidoscope/Runtime.h"
#include "Kaleidoscope-HardwareTestMode.h" #include "Kaleidoscope-HardwareTestMode.h"
#include "Kaleidoscope-LEDEffect-Rainbow.h" #include "Kaleidoscope-LEDEffect-Rainbow.h"
#include "kaleidoscope/hid.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -32,9 +33,9 @@ void HardwareTestMode::setActionKey(uint8_t key) {
void HardwareTestMode::waitForKeypress() { void HardwareTestMode::waitForKeypress() {
while (1) { while (1) {
Kaleidoscope.device().readMatrix(); Runtime.device().readMatrix();
if (Kaleidoscope.device().isKeyswitchPressed(actionKey) && if (Runtime.device().isKeyswitchPressed(actionKey) &&
! Kaleidoscope.device().wasKeyswitchPressed(actionKey)) { ! Runtime.device().wasKeyswitchPressed(actionKey)) {
break; break;
} }
} }
@ -76,7 +77,7 @@ void HardwareTestMode::testLeds(void) {
void HardwareTestMode::testMatrix() { void HardwareTestMode::testMatrix() {
// Reset bad keys from previous tests. // Reset bad keys from previous tests.
chatter_data state[Kaleidoscope.device().numKeys()] = {{0, 0, 0}}; chatter_data state[Runtime.device().numKeys()] = {{0, 0, 0}};
constexpr cRGB red = CRGB(201, 0, 0); constexpr cRGB red = CRGB(201, 0, 0);
constexpr cRGB blue = CRGB(0, 0, 201); constexpr cRGB blue = CRGB(0, 0, 201);
@ -84,12 +85,12 @@ void HardwareTestMode::testMatrix() {
constexpr cRGB yellow = CRGB(201, 100, 0); constexpr cRGB yellow = CRGB(201, 100, 0);
while (1) { while (1) {
Kaleidoscope.device().readMatrix(); Runtime.device().readMatrix();
for (auto key_addr : KeyAddr::all()) { for (auto key_addr : KeyAddr::all()) {
uint8_t keynum = key_addr.toInt(); uint8_t keynum = key_addr.toInt();
// If the key is toggled on // If the key is toggled on
if (Kaleidoscope.device().isKeyswitchPressed(key_addr) && ! Kaleidoscope.device().wasKeyswitchPressed(key_addr)) { if (Runtime.device().isKeyswitchPressed(key_addr) && ! Runtime.device().wasKeyswitchPressed(key_addr)) {
// And it's too soon (in terms of cycles between changes) // And it's too soon (in terms of cycles between changes)
state[keynum].tested = 1; state[keynum].tested = 1;
if (state[keynum].cyclesSinceStateChange < CHATTER_CYCLE_LIMIT) { if (state[keynum].cyclesSinceStateChange < CHATTER_CYCLE_LIMIT) {
@ -100,19 +101,19 @@ void HardwareTestMode::testMatrix() {
state[keynum].cyclesSinceStateChange++; state[keynum].cyclesSinceStateChange++;
} }
// If the key is held down // If the key is held down
if (Kaleidoscope.device().isKeyswitchPressed(key_addr) && Kaleidoscope.device().wasKeyswitchPressed(key_addr)) { if (Runtime.device().isKeyswitchPressed(key_addr) && Runtime.device().wasKeyswitchPressed(key_addr)) {
Kaleidoscope.device().setCrgbAt(key_addr, green); Runtime.device().setCrgbAt(key_addr, green);
} }
// If we triggered chatter detection ever on this key // If we triggered chatter detection ever on this key
else if (state[keynum].bad == 1) { else if (state[keynum].bad == 1) {
Kaleidoscope.device().setCrgbAt(key_addr, red); Runtime.device().setCrgbAt(key_addr, red);
} else if (state[keynum].tested == 0) { } else if (state[keynum].tested == 0) {
Kaleidoscope.device().setCrgbAt(key_addr, yellow); Runtime.device().setCrgbAt(key_addr, yellow);
} }
// If the key is not currently pressed and was not just released and is not marked bad // If the key is not currently pressed and was not just released and is not marked bad
else if (! Kaleidoscope.device().isKeyswitchPressed(key_addr)) { else if (! Runtime.device().isKeyswitchPressed(key_addr)) {
Kaleidoscope.device().setCrgbAt(key_addr, blue); Runtime.device().setCrgbAt(key_addr, blue);
} }
} }
::LEDControl.syncLeds(); ::LEDControl.syncLeds();
@ -124,7 +125,7 @@ void HardwareTestMode::runTests() {
// out and send a new report // out and send a new report
kaleidoscope::hid::releaseAllKeys(); kaleidoscope::hid::releaseAllKeys();
kaleidoscope::hid::sendKeyboardReport(); kaleidoscope::hid::sendKeyboardReport();
Kaleidoscope.device().enableHardwareTestMode(); Runtime.device().enableHardwareTestMode();
testLeds(); testLeds();
testMatrix(); testMatrix();
} }

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Arduino.h> #include <Arduino.h>
#include "Kaleidoscope.h" #include "kaleidoscope/Runtime.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -15,9 +15,10 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-Heatmap.h> #include <Kaleidoscope-Heatmap.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -38,7 +39,7 @@ Heatmap::TransientLEDMode::TransientLEDMode(const Heatmap *parent)
// max of heatmap_ (we divide by it so we start at 1) // max of heatmap_ (we divide by it so we start at 1)
highest_(1), highest_(1),
// last heatmap computation time // last heatmap computation time
last_heatmap_comp_time_(Kaleidoscope.millisAtCycleStart()) last_heatmap_comp_time_(Runtime.millisAtCycleStart())
{} {}
cRGB Heatmap::TransientLEDMode::computeColor(float v) { cRGB Heatmap::TransientLEDMode::computeColor(float v) {
@ -133,7 +134,7 @@ void Heatmap::TransientLEDMode::resetMap() {
} }
EventHandlerResult Heatmap::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) { EventHandlerResult Heatmap::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t key_state) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return EventHandlerResult::OK; return EventHandlerResult::OK;
// this methode is called frequently by Kaleidoscope // this methode is called frequently by Kaleidoscope
@ -175,7 +176,7 @@ EventHandlerResult Heatmap::TransientLEDMode::onKeyswitchEvent(Key &mapped_key,
} }
EventHandlerResult Heatmap::beforeEachCycle() { EventHandlerResult Heatmap::beforeEachCycle() {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (::LEDControl.get_mode_index() != led_mode_id_) if (::LEDControl.get_mode_index() != led_mode_id_)
@ -201,19 +202,19 @@ EventHandlerResult Heatmap::TransientLEDMode::beforeEachCycle() {
} }
void Heatmap::TransientLEDMode::update(void) { void Heatmap::TransientLEDMode::update(void) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
// this methode is called frequently by the LEDControl::loopHook // this methode is called frequently by the LEDControl::loopHook
// do nothing if the update interval hasn't elapsed since the previous update // do nothing if the update interval hasn't elapsed since the previous update
if (!Kaleidoscope.hasTimeExpired(last_heatmap_comp_time_, update_delay)) if (!Runtime.hasTimeExpired(last_heatmap_comp_time_, update_delay))
return; return;
// do the heatmap computing // do the heatmap computing
// (update_delay milliseconds elapsed since last_heatmap_comp_time) // (update_delay milliseconds elapsed since last_heatmap_comp_time)
// schedule the next heatmap computing // schedule the next heatmap computing
last_heatmap_comp_time_ = Kaleidoscope.millisAtCycleStart(); last_heatmap_comp_time_ = Runtime.millisAtCycleStart();
// for each key // for each key
for (auto key_addr : KeyAddr::all()) { for (auto key_addr : KeyAddr::all()) {

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
namespace kaleidoscope { namespace kaleidoscope {
@ -57,7 +57,7 @@ class Heatmap : public Plugin,
private: private:
uint16_t heatmap_[Kaleidoscope.device().numKeys()]; uint16_t heatmap_[Runtime.device().numKeys()];
uint16_t highest_; uint16_t highest_;
uint16_t last_heatmap_comp_time_; uint16_t last_heatmap_comp_time_;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -33,15 +33,15 @@ EventHandlerResult HostOS::onSetup(void) {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
os_ = (hostos::Type)Kaleidoscope.storage().read(eeprom_slice_); os_ = (hostos::Type)Runtime.storage().read(eeprom_slice_);
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
void HostOS::os(hostos::Type new_os) { void HostOS::os(hostos::Type new_os) {
os_ = new_os; os_ = new_os;
Kaleidoscope.storage().update(eeprom_slice_, os_); Runtime.storage().update(eeprom_slice_, os_);
Kaleidoscope.storage().commit(); Runtime.storage().commit();
} }
} }

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -15,7 +15,7 @@
* this program. If not, see <http://www.gnu.org/licenses/>. * this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-HostPowerManagement.h> #include <Kaleidoscope-HostPowerManagement.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#define _DEPRECATED_MESSAGE_ENABLEWAKEUP \ #define _DEPRECATED_MESSAGE_ENABLEWAKEUP \
"The HostPowerManagement.enableWakeup() call is not necessary anymore,\n" \ "The HostPowerManagement.enableWakeup() call is not necessary anymore,\n" \

@ -37,7 +37,7 @@ void IdleLEDs::setIdleTimeoutSeconds(uint32_t new_limit) {
EventHandlerResult IdleLEDs::beforeEachCycle() { EventHandlerResult IdleLEDs::beforeEachCycle() {
if (!::LEDControl.paused && if (!::LEDControl.paused &&
Kaleidoscope.hasTimeExpired(start_time_, idle_time_limit)) { Runtime.hasTimeExpired(start_time_, idle_time_limit)) {
::LEDControl.set_all_leds_to(CRGB(0, 0, 0)); ::LEDControl.set_all_leds_to(CRGB(0, 0, 0));
::LEDControl.syncLeds(); ::LEDControl.syncLeds();
@ -54,7 +54,7 @@ EventHandlerResult IdleLEDs::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr,
::LEDControl.refreshAll(); ::LEDControl.refreshAll();
} }
start_time_ = Kaleidoscope.millisAtCycleStart(); start_time_ = Runtime.millisAtCycleStart();
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
@ -67,7 +67,7 @@ EventHandlerResult PersistentIdleLEDs::onSetup() {
// If idleTime is max, assume that EEPROM is uninitialized, and store the // If idleTime is max, assume that EEPROM is uninitialized, and store the
// defaults. // defaults.
uint16_t idle_time; uint16_t idle_time;
Kaleidoscope.storage().get(settings_base_, idle_time); Runtime.storage().get(settings_base_, idle_time);
if (idle_time == 0xffff) { if (idle_time == 0xffff) {
idle_time = idle_time_limit; idle_time = idle_time_limit;
} }
@ -80,8 +80,8 @@ void PersistentIdleLEDs::setIdleTimeoutSeconds(uint32_t new_limit) {
IdleLEDs::setIdleTimeoutSeconds(new_limit); IdleLEDs::setIdleTimeoutSeconds(new_limit);
uint16_t stored_limit = (uint16_t)new_limit; uint16_t stored_limit = (uint16_t)new_limit;
Kaleidoscope.storage().put(settings_base_, stored_limit); Runtime.storage().put(settings_base_, stored_limit);
Kaleidoscope.storage().commit(); Runtime.storage().commit();
} }
EventHandlerResult PersistentIdleLEDs::onFocusEvent(const char *command) { EventHandlerResult PersistentIdleLEDs::onFocusEvent(const char *command) {

@ -18,7 +18,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

@ -16,6 +16,7 @@
*/ */
#include <Kaleidoscope-LED-ActiveLayerColor.h> #include <Kaleidoscope-LED-ActiveLayerColor.h>
#include "kaleidoscope/layers.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -45,7 +46,7 @@ cRGB LEDActiveLayerColorEffect::TransientLEDMode::getActiveColor() {
} }
void LEDActiveLayerColorEffect::TransientLEDMode::onActivate(void) { void LEDActiveLayerColorEffect::TransientLEDMode::onActivate(void) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
active_color_ = getActiveColor(); active_color_ = getActiveColor();

@ -18,6 +18,7 @@
#include <Kaleidoscope-LED-ActiveModColor.h> #include <Kaleidoscope-LED-ActiveModColor.h>
#include <Kaleidoscope-OneShot.h> #include <Kaleidoscope-OneShot.h>
#include <kaleidoscope/hid.h> #include <kaleidoscope/hid.h>
#include "kaleidoscope/layers.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -33,7 +34,7 @@ cRGB ActiveModColorEffect::highlight_color = (cRGB) {
cRGB ActiveModColorEffect::sticky_color = CRGB(160, 0, 0); cRGB ActiveModColorEffect::sticky_color = CRGB(160, 0, 0);
EventHandlerResult ActiveModColorEffect::onLayerChange() { EventHandlerResult ActiveModColorEffect::onLayerChange() {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return EventHandlerResult::OK; return EventHandlerResult::OK;
mod_key_count_ = 0; mod_key_count_ = 0;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#define MAX_MODS_PER_LAYER 16 #define MAX_MODS_PER_LAYER 16

@ -64,7 +64,7 @@ static const uint16_t alphabet[] PROGMEM = {
cRGB AlphaSquare::color = {0x80, 0x80, 0x80}; cRGB AlphaSquare::color = {0x80, 0x80, 0x80};
void AlphaSquare::display(Key key, KeyAddr key_addr, cRGB key_color) { void AlphaSquare::display(Key key, KeyAddr key_addr, cRGB key_color) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
if (key < Key_A || key > Key_0) if (key < Key_A || key > Key_0)
@ -81,7 +81,7 @@ void AlphaSquare::display(Key key, KeyAddr key_addr) {
} }
void AlphaSquare::display(uint16_t symbol, KeyAddr key_addr, cRGB key_color) { void AlphaSquare::display(uint16_t symbol, KeyAddr key_addr, cRGB key_color) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
for (uint8_t r = 0; r < 4; r++) { for (uint8_t r = 0; r < 4; r++) {
@ -106,7 +106,7 @@ void AlphaSquare::display(uint16_t symbol, KeyAddr key_addr) {
bool AlphaSquare::isSymbolPart(Key key, bool AlphaSquare::isSymbolPart(Key key,
KeyAddr displayLedAddr, KeyAddr displayLedAddr,
KeyAddr key_addr) { KeyAddr key_addr) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return false; return false;
if (key < Key_A || key > Key_0) if (key < Key_A || key > Key_0)
@ -121,7 +121,7 @@ bool AlphaSquare::isSymbolPart(Key key,
bool AlphaSquare::isSymbolPart(uint16_t symbol, bool AlphaSquare::isSymbolPart(uint16_t symbol,
KeyAddr displayLedAddr, KeyAddr displayLedAddr,
KeyAddr key_addr) { KeyAddr key_addr) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return false; return false;
for (uint8_t r = 0; r < 4; r++) { for (uint8_t r = 0; r < 4; r++) {

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#define SYM4x4( \ #define SYM4x4( \

@ -16,6 +16,7 @@
*/ */
#include <Kaleidoscope-LED-AlphaSquare.h> #include <Kaleidoscope-LED-AlphaSquare.h>
#include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -28,16 +29,16 @@ AlphaSquareEffect::TransientLEDMode::TransientLEDMode(AlphaSquareEffect */*paren
{} {}
void AlphaSquareEffect::TransientLEDMode::update(void) { void AlphaSquareEffect::TransientLEDMode::update(void) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
if (last_key_left_ != Key_NoKey && if (last_key_left_ != Key_NoKey &&
Kaleidoscope.hasTimeExpired(start_time_left_, length)) { Runtime.hasTimeExpired(start_time_left_, length)) {
::AlphaSquare.clear(last_key_left_); ::AlphaSquare.clear(last_key_left_);
last_key_left_ = Key_NoKey; last_key_left_ = Key_NoKey;
} }
if (last_key_right_ != Key_NoKey && if (last_key_right_ != Key_NoKey &&
Kaleidoscope.hasTimeExpired(start_time_right_, length)) { Runtime.hasTimeExpired(start_time_right_, length)) {
::AlphaSquare.clear(last_key_right_, 10); ::AlphaSquare.clear(last_key_right_, 10);
last_key_right_ = Key_NoKey; last_key_right_ = Key_NoKey;
} }
@ -48,12 +49,12 @@ void AlphaSquareEffect::TransientLEDMode::refreshAt(KeyAddr key_addr) {
uint8_t display_col = 2; uint8_t display_col = 2;
Key key = last_key_left_; Key key = last_key_left_;
if (key_addr.col() < Kaleidoscope.device().matrix_columns / 2) { if (key_addr.col() < Runtime.device().matrix_columns / 2) {
timed_out = Kaleidoscope.hasTimeExpired(start_time_left_, length); timed_out = Runtime.hasTimeExpired(start_time_left_, length);
} else { } else {
key = last_key_right_; key = last_key_right_;
display_col = 10; display_col = 10;
timed_out = Kaleidoscope.hasTimeExpired(start_time_right_, length); timed_out = Runtime.hasTimeExpired(start_time_right_, length);
} }
if (!::AlphaSquare.isSymbolPart(key, KeyAddr(0, display_col), key_addr) || timed_out) if (!::AlphaSquare.isSymbolPart(key, KeyAddr(0, display_col), key_addr) || timed_out)
@ -61,7 +62,7 @@ void AlphaSquareEffect::TransientLEDMode::refreshAt(KeyAddr key_addr) {
} }
EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr, uint8_t keyState) { EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr, uint8_t keyState) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (::LEDControl.get_mode_index() != led_mode_id_) if (::LEDControl.get_mode_index() != led_mode_id_)
@ -81,13 +82,13 @@ EventHandlerResult AlphaSquareEffect::onKeyswitchEvent(Key &mappedKey, KeyAddr k
Key prev_key = this_led_mode->last_key_left_; Key prev_key = this_led_mode->last_key_left_;
if (key_addr.col() < Kaleidoscope.device().matrix_columns / 2) { if (key_addr.col() < Runtime.device().matrix_columns / 2) {
this_led_mode->last_key_left_ = mappedKey; this_led_mode->last_key_left_ = mappedKey;
this_led_mode->start_time_left_ = Kaleidoscope.millisAtCycleStart(); this_led_mode->start_time_left_ = Runtime.millisAtCycleStart();
} else { } else {
prev_key = this_led_mode->last_key_right_; prev_key = this_led_mode->last_key_right_;
this_led_mode->last_key_right_ = mappedKey; this_led_mode->last_key_right_ = mappedKey;
this_led_mode->start_time_right_ = Kaleidoscope.millisAtCycleStart(); this_led_mode->start_time_right_ = Runtime.millisAtCycleStart();
display_col = 10; display_col = 10;
} }

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
namespace kaleidoscope { namespace kaleidoscope {

@ -28,27 +28,27 @@ uint16_t LEDPaletteTheme::reserveThemes(uint8_t max_themes) {
if (!palette_base_) if (!palette_base_)
palette_base_ = ::EEPROMSettings.requestSlice(16 * sizeof(cRGB)); palette_base_ = ::EEPROMSettings.requestSlice(16 * sizeof(cRGB));
return ::EEPROMSettings.requestSlice(max_themes * Kaleidoscope.device().led_count / 2); return ::EEPROMSettings.requestSlice(max_themes * Runtime.device().led_count / 2);
} }
void LEDPaletteTheme::updateHandler(uint16_t theme_base, uint8_t theme) { void LEDPaletteTheme::updateHandler(uint16_t theme_base, uint8_t theme) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
uint16_t map_base = theme_base + (theme * Kaleidoscope.device().led_count / 2); uint16_t map_base = theme_base + (theme * Runtime.device().led_count / 2);
for (uint8_t pos = 0; pos < Kaleidoscope.device().led_count; pos++) { for (uint8_t pos = 0; pos < Runtime.device().led_count; pos++) {
cRGB color = lookupColorAtPosition(map_base, pos); cRGB color = lookupColorAtPosition(map_base, pos);
::LEDControl.setCrgbAt(pos, color); ::LEDControl.setCrgbAt(pos, color);
} }
} }
void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_addr) { void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_addr) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
uint16_t map_base = theme_base + (theme * Kaleidoscope.device().led_count / 2); uint16_t map_base = theme_base + (theme * Runtime.device().led_count / 2);
uint8_t pos = Kaleidoscope.device().getLedIndex(key_addr); uint8_t pos = Runtime.device().getLedIndex(key_addr);
cRGB color = lookupColorAtPosition(map_base, pos); cRGB color = lookupColorAtPosition(map_base, pos);
::LEDControl.setCrgbAt(key_addr, color); ::LEDControl.setCrgbAt(key_addr, color);
@ -58,7 +58,7 @@ void LEDPaletteTheme::refreshAt(uint16_t theme_base, uint8_t theme, KeyAddr key_
const uint8_t LEDPaletteTheme::lookupColorIndexAtPosition(uint16_t map_base, uint16_t position) { const uint8_t LEDPaletteTheme::lookupColorIndexAtPosition(uint16_t map_base, uint16_t position) {
uint8_t color_index; uint8_t color_index;
color_index = Kaleidoscope.storage().read(map_base + position / 2); color_index = Runtime.storage().read(map_base + position / 2);
if (position % 2) if (position % 2)
color_index &= ~0xf0; color_index &= ~0xf0;
else else
@ -76,7 +76,7 @@ const cRGB LEDPaletteTheme::lookupColorAtPosition(uint16_t map_base, uint16_t po
const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) { const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) {
cRGB color; cRGB color;
Kaleidoscope.storage().get(palette_base_ + color_index * sizeof(cRGB), color); Runtime.storage().get(palette_base_ + color_index * sizeof(cRGB), color);
color.r ^= 0xff; color.r ^= 0xff;
color.g ^= 0xff; color.g ^= 0xff;
color.b ^= 0xff; color.b ^= 0xff;
@ -87,7 +87,7 @@ const cRGB LEDPaletteTheme::lookupPaletteColor(uint8_t color_index) {
void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t position, uint8_t color_index) { void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t position, uint8_t color_index) {
uint8_t indexes; uint8_t indexes;
indexes = Kaleidoscope.storage().read(map_base + position / 2); indexes = Runtime.storage().read(map_base + position / 2);
if (position % 2) { if (position % 2) {
uint8_t other = indexes >> 4; uint8_t other = indexes >> 4;
indexes = (other << 4) + color_index; indexes = (other << 4) + color_index;
@ -95,12 +95,12 @@ void LEDPaletteTheme::updateColorIndexAtPosition(uint16_t map_base, uint16_t pos
uint8_t other = indexes & ~0xf0; uint8_t other = indexes & ~0xf0;
indexes = (color_index << 4) + other; indexes = (color_index << 4) + other;
} }
Kaleidoscope.storage().update(map_base + position / 2, indexes); Runtime.storage().update(map_base + position / 2, indexes);
Kaleidoscope.storage().commit(); Runtime.storage().commit();
} }
EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) { EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return EventHandlerResult::OK; return EventHandlerResult::OK;
const char *cmd = PSTR("palette"); const char *cmd = PSTR("palette");
@ -130,10 +130,10 @@ EventHandlerResult LEDPaletteTheme::onFocusEvent(const char *command) {
color.g ^= 0xff; color.g ^= 0xff;
color.b ^= 0xff; color.b ^= 0xff;
Kaleidoscope.storage().put(palette_base_ + i * sizeof(color), color); Runtime.storage().put(palette_base_ + i * sizeof(color), color);
i++; i++;
} }
Kaleidoscope.storage().commit(); Runtime.storage().commit();
::LEDControl.refreshAll(); ::LEDControl.refreshAll();
@ -144,7 +144,7 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command,
const char *expected_command, const char *expected_command,
uint16_t theme_base, uint16_t theme_base,
uint8_t max_themes) { uint8_t max_themes) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (::Focus.handleHelp(command, expected_command)) if (::Focus.handleHelp(command, expected_command))
@ -153,11 +153,11 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command,
if (strcmp_P(command, expected_command) != 0) if (strcmp_P(command, expected_command) != 0)
return EventHandlerResult::OK; return EventHandlerResult::OK;
uint16_t max_index = (max_themes * Kaleidoscope.device().led_count) / 2; uint16_t max_index = (max_themes * Runtime.device().led_count) / 2;
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
for (uint16_t pos = 0; pos < max_index; pos++) { for (uint16_t pos = 0; pos < max_index; pos++) {
uint8_t indexes = Kaleidoscope.storage().read(theme_base + pos); uint8_t indexes = Runtime.storage().read(theme_base + pos);
::Focus.send((uint8_t)(indexes >> 4), indexes & ~0xf0); ::Focus.send((uint8_t)(indexes >> 4), indexes & ~0xf0);
} }
@ -173,10 +173,10 @@ EventHandlerResult LEDPaletteTheme::themeFocusEvent(const char *command,
uint8_t indexes = (idx1 << 4) + idx2; uint8_t indexes = (idx1 << 4) + idx2;
Kaleidoscope.storage().update(theme_base + pos, indexes); Runtime.storage().update(theme_base + pos, indexes);
pos++; pos++;
} }
Kaleidoscope.storage().commit(); Runtime.storage().commit();
::LEDControl.refreshAll(); ::LEDControl.refreshAll();

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
namespace kaleidoscope { namespace kaleidoscope {

@ -17,6 +17,7 @@
#include <Kaleidoscope-LED-Stalker.h> #include <Kaleidoscope-LED-Stalker.h>
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -34,7 +35,7 @@ StalkerEffect::TransientLEDMode::TransientLEDMode(const StalkerEffect *parent)
{} {}
EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t keyState) { EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, uint8_t keyState) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (!key_addr.isValid()) if (!key_addr.isValid())
@ -51,13 +52,13 @@ EventHandlerResult StalkerEffect::onKeyswitchEvent(Key &mapped_key, KeyAddr key_
} }
void StalkerEffect::TransientLEDMode::update(void) { void StalkerEffect::TransientLEDMode::update(void) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
if (!parent_->variant) if (!parent_->variant)
return; return;
if (!Kaleidoscope.hasTimeExpired(step_start_time_, parent_->step_length)) if (!Runtime.hasTimeExpired(step_start_time_, parent_->step_length))
return; return;
for (auto key_addr : KeyAddr::all()) { for (auto key_addr : KeyAddr::all()) {
@ -72,7 +73,7 @@ void StalkerEffect::TransientLEDMode::update(void) {
::LEDControl.setCrgbAt(key_addr, parent_->inactive_color); ::LEDControl.setCrgbAt(key_addr, parent_->inactive_color);
} }
step_start_time_ = Kaleidoscope.millisAtCycleStart(); step_start_time_ = Runtime.millisAtCycleStart();
} }
namespace stalker { namespace stalker {

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#define STALKER(v, ...) ({static kaleidoscope::plugin::stalker::v _effect __VA_ARGS__; &_effect;}) #define STALKER(v, ...) ({static kaleidoscope::plugin::stalker::v _effect __VA_ARGS__; &_effect;})
@ -61,7 +61,7 @@ class StalkerEffect : public Plugin,
const StalkerEffect *parent_; const StalkerEffect *parent_;
uint16_t step_start_time_; uint16_t step_start_time_;
uint8_t map_[Kaleidoscope.device().numKeys()]; uint8_t map_[Runtime.device().numKeys()];
friend class StalkerEffect; friend class StalkerEffect;
}; };

@ -19,6 +19,7 @@
#ifdef ARDUINO_AVR_MODEL01 #ifdef ARDUINO_AVR_MODEL01
#include <Kaleidoscope-LED-Wavepool.h> #include <Kaleidoscope-LED-Wavepool.h>
#include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -31,7 +32,7 @@ uint16_t WavepoolEffect::idle_timeout = 5000; // 5 seconds
int16_t WavepoolEffect::ripple_hue = WavepoolEffect::rainbow_hue; // automatic hue int16_t WavepoolEffect::ripple_hue = WavepoolEffect::rainbow_hue; // automatic hue
// map native keyboard coordinates (16x4) into geometric space (14x5) // map native keyboard coordinates (16x4) into geometric space (14x5)
PROGMEM const uint8_t WavepoolEffect::TransientLEDMode::rc2pos[Kaleidoscope.device().numKeys()] = { PROGMEM const uint8_t WavepoolEffect::TransientLEDMode::rc2pos[Runtime.device().numKeys()] = {
0, 1, 2, 3, 4, 5, 6, 59, 66, 7, 8, 9, 10, 11, 12, 13, 0, 1, 2, 3, 4, 5, 6, 59, 66, 7, 8, 9, 10, 11, 12, 13,
14, 15, 16, 17, 18, 19, 34, 60, 65, 35, 22, 23, 24, 25, 26, 27, 14, 15, 16, 17, 18, 19, 34, 60, 65, 35, 22, 23, 24, 25, 26, 27,
28, 29, 30, 31, 32, 33, 48, 61, 64, 49, 36, 37, 38, 39, 40, 41, 28, 29, 30, 31, 32, 33, 48, 61, 64, 49, 36, 37, 38, 39, 40, 41,
@ -79,14 +80,14 @@ void WavepoolEffect::TransientLEDMode::raindrop(uint8_t x, uint8_t y, int8_t *pa
uint8_t WavepoolEffect::TransientLEDMode::wp_rand() { uint8_t WavepoolEffect::TransientLEDMode::wp_rand() {
static intptr_t offset = 0x400; static intptr_t offset = 0x400;
offset = ((offset + 1) & 0x4fff) | 0x400; offset = ((offset + 1) & 0x4fff) | 0x400;
return (Kaleidoscope.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(void) {
// 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;
uint8_t now = Kaleidoscope.millisAtCycleStart() / MS_PER_FRAME; uint8_t now = Runtime.millisAtCycleStart() / MS_PER_FRAME;
if (now != prev_time) { if (now != prev_time) {
prev_time = now; prev_time = now;
} else { } else {

@ -20,7 +20,7 @@
#ifdef ARDUINO_AVR_MODEL01 #ifdef ARDUINO_AVR_MODEL01
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-LEDControl.h> #include <Kaleidoscope-LEDControl.h>
#define WP_WID 14 #define WP_WID 14
@ -64,7 +64,7 @@ class WavepoolEffect : public Plugin,
uint8_t frames_since_event_; uint8_t frames_since_event_;
int8_t surface_[2][WP_WID * WP_HGT]; int8_t surface_[2][WP_WID * WP_HGT];
uint8_t page_; uint8_t page_;
static PROGMEM const uint8_t rc2pos[Kaleidoscope.device().numKeys()]; static PROGMEM const uint8_t rc2pos[Runtime.device().numKeys()];
void raindrop(uint8_t x, uint8_t y, int8_t *page); void raindrop(uint8_t x, uint8_t y, int8_t *page);
uint8_t wp_rand(); uint8_t wp_rand();

@ -17,6 +17,7 @@
#include "Kaleidoscope-LEDControl.h" #include "Kaleidoscope-LEDControl.h"
#include "Kaleidoscope-FocusSerial.h" #include "Kaleidoscope-FocusSerial.h"
#include "kaleidoscope_internal/LEDModeManager.h" #include "kaleidoscope_internal/LEDModeManager.h"
#include "kaleidoscope/keyswitch_state.h"
using namespace kaleidoscope::internal; using namespace kaleidoscope::internal;
@ -87,7 +88,7 @@ void LEDControl::activate(LEDModeInterface *plugin) {
} }
void LEDControl::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) { void LEDControl::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
cRGB color; cRGB color;
@ -98,31 +99,31 @@ void LEDControl::set_all_leds_to(uint8_t r, uint8_t g, uint8_t b) {
} }
void LEDControl::set_all_leds_to(cRGB color) { void LEDControl::set_all_leds_to(cRGB color) {
for (auto led_index : Kaleidoscope.device().LEDs().all()) { for (auto led_index : Runtime.device().LEDs().all()) {
setCrgbAt(led_index.offset(), color); setCrgbAt(led_index.offset(), color);
} }
} }
void LEDControl::setCrgbAt(uint8_t led_index, cRGB crgb) { void LEDControl::setCrgbAt(uint8_t led_index, cRGB crgb) {
Kaleidoscope.device().setCrgbAt(led_index, crgb); Runtime.device().setCrgbAt(led_index, crgb);
} }
void LEDControl::setCrgbAt(KeyAddr key_addr, cRGB color) { void LEDControl::setCrgbAt(KeyAddr key_addr, cRGB color) {
Kaleidoscope.device().setCrgbAt(key_addr, color); Runtime.device().setCrgbAt(key_addr, color);
} }
cRGB LEDControl::getCrgbAt(uint8_t led_index) { cRGB LEDControl::getCrgbAt(uint8_t led_index) {
return Kaleidoscope.device().getCrgbAt(led_index); return Runtime.device().getCrgbAt(led_index);
} }
cRGB LEDControl::getCrgbAt(KeyAddr key_addr) { cRGB LEDControl::getCrgbAt(KeyAddr key_addr) {
return Kaleidoscope.device().getCrgbAt(Kaleidoscope.device().getLedIndex(key_addr)); return Runtime.device().getCrgbAt(Runtime.device().getLedIndex(key_addr));
} }
void LEDControl::syncLeds(void) { void LEDControl::syncLeds(void) {
if (paused) if (paused)
return; return;
Kaleidoscope.device().syncLeds(); Runtime.device().syncLeds();
} }
kaleidoscope::EventHandlerResult LEDControl::onSetup() { kaleidoscope::EventHandlerResult LEDControl::onSetup() {
@ -156,7 +157,7 @@ kaleidoscope::EventHandlerResult LEDControl::beforeReportingState(void) {
if (paused) if (paused)
return kaleidoscope::EventHandlerResult::OK; return kaleidoscope::EventHandlerResult::OK;
if (Kaleidoscope.hasTimeExpired(syncTimer, syncDelay)) { if (Runtime.hasTimeExpired(syncTimer, syncDelay)) {
syncLeds(); syncLeds();
syncTimer += syncDelay; syncTimer += syncDelay;
update(); update();
@ -173,7 +174,7 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
THEME, THEME,
} subCommand; } subCommand;
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (::Focus.handleHelp(command, PSTR("led.at\n" if (::Focus.handleHelp(command, PSTR("led.at\n"
@ -241,7 +242,7 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
} }
case THEME: { case THEME: {
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
for (auto led_index : Kaleidoscope.device().LEDs().all()) { for (auto led_index : Runtime.device().LEDs().all()) {
cRGB c = ::LEDControl.getCrgbAt(led_index.offset()); cRGB c = ::LEDControl.getCrgbAt(led_index.offset());
::Focus.send(c); ::Focus.send(c);
@ -249,7 +250,7 @@ EventHandlerResult FocusLEDCommand::onFocusEvent(const char *command) {
break; break;
} }
for (auto led_index : Kaleidoscope.device().LEDs().all()) { for (auto led_index : Runtime.device().LEDs().all()) {
if (::Focus.isEOL()) { if (::Focus.isEOL()) {
break; break;
} }

@ -16,7 +16,8 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/plugin/LEDMode.h"
#define LED_TOGGLE B00000001 // Synthetic, internal #define LED_TOGGLE B00000001 // Synthetic, internal
@ -41,13 +42,13 @@ class LEDControl : public kaleidoscope::Plugin {
static void prev_mode(void); static void prev_mode(void);
static void setup(void); static void setup(void);
static void update(void) { static void update(void) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
cur_led_mode_->update(); cur_led_mode_->update();
} }
static void refreshAt(KeyAddr key_addr) { static void refreshAt(KeyAddr key_addr) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
cur_led_mode_->refreshAt(key_addr); cur_led_mode_->refreshAt(key_addr);
@ -69,7 +70,7 @@ class LEDControl : public kaleidoscope::Plugin {
} }
static void refreshAll() { static void refreshAll() {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
if (paused) if (paused)

@ -18,6 +18,9 @@
cRGB cRGB
breath_compute(uint8_t hue, uint8_t saturation, uint8_t phase_offset) { breath_compute(uint8_t hue, uint8_t saturation, uint8_t phase_offset) {
using kaleidoscope::Runtime;
// This code is adapted from FastLED lib8tion.h as of dd5d96c6b289cb6b4b891748a4aeef3ddceaf0e6 // This code is adapted from FastLED lib8tion.h as of dd5d96c6b289cb6b4b891748a4aeef3ddceaf0e6
// Eventually, we should consider just using FastLED // Eventually, we should consider just using FastLED
@ -35,7 +38,7 @@ breath_compute(uint8_t hue, uint8_t saturation, uint8_t phase_offset) {
// We do a bit shift here instead of division to ensure that there's no discontinuity // We do a bit shift here instead of division to ensure that there's no discontinuity
// in the output brightness when the integer overflows. // in the output brightness when the integer overflows.
uint8_t i = ((uint16_t)Kaleidoscope.millisAtCycleStart() + (phase_offset << 4)) >> 4; uint8_t i = ((uint16_t)Runtime.millisAtCycleStart() + (phase_offset << 4)) >> 4;
if (i & 0x80) { if (i & 0x80) {
i = 255 - i; i = 255 - i;

@ -16,7 +16,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
cRGB breath_compute(uint8_t hue = 170, uint8_t saturation = 255, uint8_t phase_offset = 0); cRGB breath_compute(uint8_t hue = 170, uint8_t saturation = 255, uint8_t phase_offset = 0);
cRGB hsvToRgb(uint16_t h, uint16_t s, uint16_t v); cRGB hsvToRgb(uint16_t h, uint16_t s, uint16_t v);

@ -16,6 +16,7 @@
*/ */
#include "Kaleidoscope-LEDEffect-BootAnimation.h" #include "Kaleidoscope-LEDEffect-BootAnimation.h"
#include "kaleidoscope/layers.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -44,7 +45,7 @@ EventHandlerResult BootAnimationEffect::onSetup() {
} }
EventHandlerResult BootAnimationEffect::afterEachCycle() { EventHandlerResult BootAnimationEffect::afterEachCycle() {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return EventHandlerResult::OK; return EventHandlerResult::OK;
//If already done or we're not in a ready state, bail //If already done or we're not in a ready state, bail
@ -65,7 +66,7 @@ EventHandlerResult BootAnimationEffect::afterEachCycle() {
} }
} }
if (Kaleidoscope.hasTimeExpired(start_time_, timeout)) { if (Runtime.hasTimeExpired(start_time_, timeout)) {
current_index_++; current_index_++;
if (current_index_ == sizeof(greeting_)) if (current_index_ == sizeof(greeting_))
done_ = true; done_ = true;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include "Kaleidoscope.h" #include "kaleidoscope/Runtime.h"
#include "Kaleidoscope-LEDControl.h" #include "Kaleidoscope-LEDControl.h"
namespace kaleidoscope { namespace kaleidoscope {

@ -16,6 +16,7 @@
*/ */
#include "Kaleidoscope-LEDEffect-BootGreeting.h" #include "Kaleidoscope-LEDEffect-BootGreeting.h"
#include "kaleidoscope/layers.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -59,7 +60,7 @@ EventHandlerResult BootGreetingEffect::onSetup() {
} }
EventHandlerResult BootGreetingEffect::afterEachCycle() { EventHandlerResult BootGreetingEffect::afterEachCycle() {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return EventHandlerResult::OK; return EventHandlerResult::OK;
//If already done or we're not in a ready state, bail //If already done or we're not in a ready state, bail
@ -68,7 +69,7 @@ EventHandlerResult BootGreetingEffect::afterEachCycle() {
} }
//Only run for 'timeout' milliseconds //Only run for 'timeout' milliseconds
if (Kaleidoscope.hasTimeExpired(start_time, timeout)) { if (Runtime.hasTimeExpired(start_time, timeout)) {
done_ = true; done_ = true;
::LEDControl.refreshAt(key_addr_); ::LEDControl.refreshAt(key_addr_);
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -19,10 +19,10 @@
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
void LEDBreatheEffect::TransientLEDMode::update(void) { void LEDBreatheEffect::TransientLEDMode::update(void) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
if (!Kaleidoscope.hasTimeExpired(last_update_, update_interval_)) if (!Runtime.hasTimeExpired(last_update_, update_interval_))
return; return;
last_update_ += update_interval_; last_update_ += update_interval_;

@ -20,10 +20,10 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
void LEDChaseEffect::TransientLEDMode::update(void) { void LEDChaseEffect::TransientLEDMode::update(void) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
if (!Kaleidoscope.hasTimeExpired(last_update_, parent_->update_delay_)) { if (!Runtime.hasTimeExpired(last_update_, parent_->update_delay_)) {
return; return;
} }
last_update_ += parent_->update_delay_; last_update_ += parent_->update_delay_;
@ -38,7 +38,7 @@ void LEDChaseEffect::TransientLEDMode::update(void) {
// Since it's an unsigned integer, even when it would have a value below zero, // Since it's an unsigned integer, even when it would have a value below zero,
// it underflows and so one test is good for both ends of the range. // it underflows and so one test is good for both ends of the range.
::LEDControl.setCrgbAt(pos_, CRGB(0, 0, 0)); ::LEDControl.setCrgbAt(pos_, CRGB(0, 0, 0));
if (Kaleidoscope.device().LEDs().isValid(pos2)) if (Runtime.device().LEDs().isValid(pos2))
::LEDControl.setCrgbAt(pos2, CRGB(0, 0, 0)); ::LEDControl.setCrgbAt(pos2, CRGB(0, 0, 0));
// Next, we adjust the red light's position. If the direction hasn't changed (the red // Next, we adjust the red light's position. If the direction hasn't changed (the red
@ -48,18 +48,18 @@ void LEDChaseEffect::TransientLEDMode::update(void) {
// will be out of bounds. The simplest way to do this is to assign it a value that is // will be out of bounds. The simplest way to do this is to assign it a value that is
// known to be invalid (LED_COUNT). // known to be invalid (LED_COUNT).
pos_ += direction_; pos_ += direction_;
if (Kaleidoscope.device().LEDs().isValid(pos_)) { if (Runtime.device().LEDs().isValid(pos_)) {
pos2 += direction_; pos2 += direction_;
} else { } else {
direction_ = -direction_; direction_ = -direction_;
pos_ += direction_; pos_ += direction_;
pos2 = Kaleidoscope.device().led_count; pos2 = Runtime.device().led_count;
} }
// Last, we turn on the LEDs at their new positions. As before, the blue light (pos2) is // Last, we turn on the LEDs at their new positions. As before, the blue light (pos2) is
// only set if it's in the valid LED range. // only set if it's in the valid LED range.
::LEDControl.setCrgbAt(pos_, CRGB(255, 0, 0)); ::LEDControl.setCrgbAt(pos_, CRGB(255, 0, 0));
if (Kaleidoscope.device().LEDs().isValid(pos2)) if (Runtime.device().LEDs().isValid(pos2))
::LEDControl.setCrgbAt(pos2, CRGB(0, 0, 255)); ::LEDControl.setCrgbAt(pos2, CRGB(0, 0, 255));
} }

@ -48,7 +48,7 @@ class LEDChaseEffect : public Plugin,
// members of their parent class. Most LED modes can do without. // members of their parent class. Most LED modes can do without.
// //
TransientLEDMode(const LEDChaseEffect *parent) TransientLEDMode(const LEDChaseEffect *parent)
: parent_(parent), last_update_(Kaleidoscope.millisAtCycleStart()) {} : parent_(parent), last_update_(Runtime.millisAtCycleStart()) {}
protected: protected:

@ -20,10 +20,10 @@ namespace kaleidoscope {
namespace plugin { namespace plugin {
void LEDRainbowEffect::TransientLEDMode::update(void) { void LEDRainbowEffect::TransientLEDMode::update(void) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
if (!Kaleidoscope.hasTimeExpired(rainbow_last_update, if (!Runtime.hasTimeExpired(rainbow_last_update,
parent_->rainbow_update_delay)) { parent_->rainbow_update_delay)) {
return; return;
} else { } else {
@ -51,17 +51,17 @@ void LEDRainbowEffect::update_delay(byte delay) {
// --------- // ---------
void LEDRainbowWaveEffect::TransientLEDMode::update(void) { void LEDRainbowWaveEffect::TransientLEDMode::update(void) {
if (!Kaleidoscope.has_leds) if (!Runtime.has_leds)
return; return;
if (!Kaleidoscope.hasTimeExpired(rainbow_last_update, if (!Runtime.hasTimeExpired(rainbow_last_update,
parent_->rainbow_update_delay)) { parent_->rainbow_update_delay)) {
return; return;
} else { } else {
rainbow_last_update += parent_->rainbow_update_delay; rainbow_last_update += parent_->rainbow_update_delay;
} }
for (auto led_index : Kaleidoscope.device().LEDs().all()) { for (auto led_index : Runtime.device().LEDs().all()) {
uint16_t led_hue = rainbow_hue + 16 * (led_index.offset() / 4); uint16_t led_hue = rainbow_hue + 16 * (led_index.offset() / 4);
// We want led_hue to be capped at 255, but we do not want to clip it to // We want led_hue to be capped at 255, but we do not want to clip it to
// that, because that does not result in a nice animation. Instead, when it // that, because that does not result in a nice animation. Instead, when it

@ -110,7 +110,7 @@ class LEDMode : public kaleidoscope::Plugin,
/** Plugin initialization. /** Plugin initialization.
* *
* Called via `Kaleidoscope.use()`, registers the LED mode, and does the * Called via `Runtime.use()`, registers the LED mode, and does the
* necessary initialization steps. Calls @ref setup at the end. * necessary initialization steps. Calls @ref setup at the end.
*/ */
kaleidoscope::EventHandlerResult onSetup() { kaleidoscope::EventHandlerResult onSetup() {

@ -16,6 +16,9 @@
*/ */
#include <Kaleidoscope-Leader.h> #include <Kaleidoscope-Leader.h>
#include "kaleidoscope/keyswitch_state.h"
#include "kaleidoscope/keyswitch_state.h"
#include "kaleidoscope/key_events.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -94,7 +97,7 @@ EventHandlerResult Leader::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, u
if (keyToggledOff(keyState)) { if (keyToggledOff(keyState)) {
// not active, but a leader key = start the sequence on key release! // not active, but a leader key = start the sequence on key release!
start_time_ = Kaleidoscope.millisAtCycleStart(); start_time_ = Runtime.millisAtCycleStart();
sequence_pos_ = 0; sequence_pos_ = 0;
sequence_[sequence_pos_] = mapped_key; sequence_[sequence_pos_] = mapped_key;
} }
@ -113,7 +116,7 @@ EventHandlerResult Leader::onKeyswitchEvent(Key &mapped_key, KeyAddr key_addr, u
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
start_time_ = Kaleidoscope.millisAtCycleStart(); start_time_ = Runtime.millisAtCycleStart();
sequence_[sequence_pos_] = mapped_key; sequence_[sequence_pos_] = mapped_key;
action_index = lookup(); action_index = lookup();
@ -143,7 +146,7 @@ EventHandlerResult Leader::afterEachCycle() {
if (!isActive()) if (!isActive())
return EventHandlerResult::OK; return EventHandlerResult::OK;
if (Kaleidoscope.hasTimeExpired(start_time_, time_out)) if (Runtime.hasTimeExpired(start_time_, time_out))
reset(); reset();
return EventHandlerResult::OK; return EventHandlerResult::OK;

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include <Kaleidoscope-Ranges.h> #include <Kaleidoscope-Ranges.h>
#define LEADER_MAX_SEQUENCE_LENGTH 4 #define LEADER_MAX_SEQUENCE_LENGTH 4

@ -16,6 +16,8 @@
#include "Kaleidoscope-Macros.h" #include "Kaleidoscope-Macros.h"
#include "kaleidoscope/hid.h" #include "kaleidoscope/hid.h"
#include "kaleidoscope/keyswitch_state.h"
#include "kaleidoscope/key_events.h"
__attribute__((weak)) __attribute__((weak))
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) {

@ -16,10 +16,12 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/plugin/Macros/MacroKeyDefs.h" #include "kaleidoscope/plugin/Macros/MacroKeyDefs.h"
#include "kaleidoscope/plugin/Macros/MacroSteps.h" #include "kaleidoscope/plugin/Macros/MacroSteps.h"
#include "kaleidoscope/keyswitch_state.h"
#include "kaleidoscope/key_events.h"
const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState); const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState);
@ -61,7 +63,7 @@ class Macros_ : public kaleidoscope::Plugin {
/* What follows below, is a bit of template magic that allows us to use /* What follows below, is a bit of template magic that allows us to use
Macros.type() with any number of arguments, without having to use a Macros.type() with any number of arguments, without having to use a
sentinel. See the comments on Kaleidoscope.use() for more details - this is sentinel. See the comments on Runtime.use() for more details - this is
the same trick. the same trick.
*/ */
inline const macro_t *type() { inline const macro_t *type() {

@ -34,19 +34,19 @@ EventHandlerResult MagicCombo::beforeReportingState() {
if (comboKey == 0) if (comboKey == 0)
break; break;
match &= Kaleidoscope.device().isKeyswitchPressed(comboKey); match &= Runtime.device().isKeyswitchPressed(comboKey);
if (!match) if (!match)
break; break;
} }
if (j != Kaleidoscope.device().pressedKeyswitchCount()) if (j != Runtime.device().pressedKeyswitchCount())
match = false; match = false;
if (match && Kaleidoscope.hasTimeExpired(start_time_, min_interval)) { if (match && Runtime.hasTimeExpired(start_time_, min_interval)) {
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);
start_time_ = Kaleidoscope.millisAtCycleStart(); start_time_ = Runtime.millisAtCycleStart();
} }
} }

@ -17,7 +17,7 @@
#pragma once #pragma once
#include <Kaleidoscope.h> #include "kaleidoscope/Runtime.h"
#define MAX_COMBO_LENGTH 5 #define MAX_COMBO_LENGTH 5

@ -23,7 +23,7 @@
#ifdef ARDUINO_AVR_MODEL01 #ifdef ARDUINO_AVR_MODEL01
#include <Arduino.h> #include <Arduino.h>
#include "Kaleidoscope.h" #include "kaleidoscope/Runtime.h"
#include "kaleidoscope_internal/deprecations.h" #include "kaleidoscope_internal/deprecations.h"
#define _DEPRECATED_MESSAGE_MODEL01_TESTMODE \ #define _DEPRECATED_MESSAGE_MODEL01_TESTMODE \

@ -16,8 +16,10 @@
#include <Arduino.h> #include <Arduino.h>
#include "Kaleidoscope.h" #include "kaleidoscope/Runtime.h"
#include "Kaleidoscope-MouseKeys.h" #include "Kaleidoscope-MouseKeys.h"
#include "kaleidoscope/hid.h"
#include "kaleidoscope/keyswitch_state.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {
@ -46,10 +48,10 @@ void MouseKeys_::setSpeedLimit(uint8_t speed_limit) {
} }
void MouseKeys_::scrollWheel(uint8_t keyCode) { void MouseKeys_::scrollWheel(uint8_t keyCode) {
if (!Kaleidoscope.hasTimeExpired(wheel_start_time_, wheelDelay)) if (!Runtime.hasTimeExpired(wheel_start_time_, wheelDelay))
return; return;
wheel_start_time_ = Kaleidoscope.millisAtCycleStart(); wheel_start_time_ = Runtime.millisAtCycleStart();
if (keyCode & KEY_MOUSE_UP) if (keyCode & KEY_MOUSE_UP)
kaleidoscope::hid::moveMouse(0, 0, wheelSpeed); kaleidoscope::hid::moveMouse(0, 0, wheelSpeed);
@ -75,18 +77,18 @@ EventHandlerResult MouseKeys_::beforeReportingState() {
return EventHandlerResult::OK; return EventHandlerResult::OK;
} }
if (!Kaleidoscope.hasTimeExpired(move_start_time_, speedDelay)) if (!Runtime.hasTimeExpired(move_start_time_, speedDelay))
return EventHandlerResult::OK; return EventHandlerResult::OK;
move_start_time_ = Kaleidoscope.millisAtCycleStart(); move_start_time_ = Runtime.millisAtCycleStart();
int8_t moveX = 0, moveY = 0; int8_t moveX = 0, moveY = 0;
if (Kaleidoscope.hasTimeExpired(accel_start_time_, accelDelay)) { if (Runtime.hasTimeExpired(accel_start_time_, accelDelay)) {
if (MouseWrapper.accelStep < 255 - accelSpeed) { if (MouseWrapper.accelStep < 255 - accelSpeed) {
MouseWrapper.accelStep += accelSpeed; MouseWrapper.accelStep += accelSpeed;
} }
accel_start_time_ = Kaleidoscope.millisAtCycleStart(); accel_start_time_ = Runtime.millisAtCycleStart();
} }
if (mouseMoveIntent & KEY_MOUSE_UP) if (mouseMoveIntent & KEY_MOUSE_UP)
@ -124,9 +126,9 @@ EventHandlerResult MouseKeys_::onKeyswitchEvent(Key &mappedKey, KeyAddr key_addr
} }
} else if (!(mappedKey.getKeyCode() & KEY_MOUSE_WARP)) { } else if (!(mappedKey.getKeyCode() & KEY_MOUSE_WARP)) {
if (keyToggledOn(keyState)) { if (keyToggledOn(keyState)) {
move_start_time_ = Kaleidoscope.millisAtCycleStart(); move_start_time_ = Runtime.millisAtCycleStart();
accel_start_time_ = Kaleidoscope.millisAtCycleStart(); accel_start_time_ = Runtime.millisAtCycleStart();
wheel_start_time_ = Kaleidoscope.millisAtCycleStart() - wheelDelay; wheel_start_time_ = Runtime.millisAtCycleStart() - wheelDelay;
} }
if (keyIsPressed(keyState)) { if (keyIsPressed(keyState)) {
if (mappedKey.getKeyCode() & KEY_MOUSE_WHEEL) { if (mappedKey.getKeyCode() & KEY_MOUSE_WHEEL) {

@ -16,7 +16,7 @@
#pragma once #pragma once
#include "Kaleidoscope.h" #include "kaleidoscope/Runtime.h"
#include "kaleidoscope/plugin/MouseKeys/MouseKeyDefs.h" #include "kaleidoscope/plugin/MouseKeys/MouseKeyDefs.h"
#include "kaleidoscope/plugin/MouseKeys/MouseWarpModes.h" #include "kaleidoscope/plugin/MouseKeys/MouseWarpModes.h"
#include "kaleidoscope/plugin/MouseKeys/MouseWrapper.h" #include "kaleidoscope/plugin/MouseKeys/MouseWrapper.h"

@ -15,6 +15,7 @@
*/ */
#include "Kaleidoscope-NumPad.h" #include "Kaleidoscope-NumPad.h"
#include "kaleidoscope/layers.h"
namespace kaleidoscope { namespace kaleidoscope {
namespace plugin { namespace plugin {

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

Loading…
Cancel
Save