From e6c25db24cb34f2a88c578737d34c0797c39c83d Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Tue, 5 Nov 2019 13:39:22 +0100 Subject: [PATCH] Model01-TestMode: Deprecate and turn into a no-op Deprecate Model01-TestMode, in favour of the newer HardwareTestMode plugin. We also turn it into a no-op, so that we don't need to update it for API changes coming in the near future. The Model01 example has been updated to use the newer HardwareTestMode instead. Signed-off-by: Gergely Nagy --- .../Devices/Keyboardio/Model01/Model01.ino | 25 ++- src/kaleidoscope/plugin/Model01-TestMode.cpp | 178 ------------------ src/kaleidoscope/plugin/Model01-TestMode.h | 24 +-- 3 files changed, 28 insertions(+), 199 deletions(-) delete mode 100644 src/kaleidoscope/plugin/Model01-TestMode.cpp diff --git a/examples/Devices/Keyboardio/Model01/Model01.ino b/examples/Devices/Keyboardio/Model01/Model01.ino index 775261c1..28625508 100644 --- a/examples/Devices/Keyboardio/Model01/Model01.ino +++ b/examples/Devices/Keyboardio/Model01/Model01.ino @@ -22,12 +22,13 @@ #include "Kaleidoscope-Macros.h" #include "Kaleidoscope-LEDControl.h" #include "Kaleidoscope-NumPad.h" +#include "Kaleidoscope-HardwareTestMode.h" +#include "Kaleidoscope-MagicCombo.h" #include "Kaleidoscope-LEDEffect-SolidColor.h" #include "Kaleidoscope-LEDEffect-Breathe.h" #include "Kaleidoscope-LEDEffect-Chase.h" #include "Kaleidoscope-LEDEffect-Rainbow.h" -#include "Kaleidoscope-Model01-TestMode.h" #define NUMPAD_KEYMAP 2 @@ -96,12 +97,30 @@ const macro_t *macroAction(uint8_t macroIndex, uint8_t keyState) { return MACRO_NONE; } -KALEIDOSCOPE_INIT_PLUGINS(TestMode, +/** + * This enters the hardware test mode + */ +static void enterHardwareTestMode(uint8_t combo_index) { + HardwareTestMode.runTests(); +} + + +/** Magic combo list, a list of key combo and action pairs the firmware should + * recognise. + */ +USE_MAGIC_COMBOS({ + .action = enterHardwareTestMode, + // Left Fn + Prog + LED + .keys = { R3C6, R0C0, R0C6 } +}); + +KALEIDOSCOPE_INIT_PLUGINS(HardwareTestMode, LEDControl, LEDOff, solidRed, solidOrange, solidYellow, solidGreen, solidBlue, solidIndigo, solidViolet, LEDBreatheEffect, LEDRainbowEffect, LEDChaseEffect, NumPad, Macros, - MouseKeys); + MouseKeys, + MagicCombo); void setup() { Kaleidoscope.setup(); diff --git a/src/kaleidoscope/plugin/Model01-TestMode.cpp b/src/kaleidoscope/plugin/Model01-TestMode.cpp deleted file mode 100644 index 9ab1fc21..00000000 --- a/src/kaleidoscope/plugin/Model01-TestMode.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* Kaleidoscope-Model01-TestMode - A factory test mode for the Model 01. - * Copyright (C) 2017-2018 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 . - */ - -#ifndef KALEIDOSCOPE_VIRTUAL_BUILD - -#if ARDUINO_AVR_MODEL01 - -#include "Kaleidoscope.h" -#include "Kaleidoscope-Model01-TestMode.h" -#include "Kaleidoscope-LEDEffect-Rainbow.h" -#include "kaleidoscope_internal/LEDModeManager.h" - -namespace kaleidoscope { -namespace plugin { - -constexpr uint8_t CHATTER_CYCLE_LIMIT = 30; -constexpr uint8_t TOGGLED_OFF = 2; -constexpr uint8_t TOGGLED_ON = 1; -constexpr uint8_t HELD = 3; -constexpr uint8_t RELEASED = 0; - -EventHandlerResult TestMode::beforeReportingState() { - if (Kaleidoscope.device().isKeyswitchPressed(R0C0) && - Kaleidoscope.device().isKeyswitchPressed(R0C6) && - Kaleidoscope.device().isKeyswitchPressed(R3C6) && - Kaleidoscope.device().pressedKeyswitchCount() == 3) { - run_tests(); - } - return EventHandlerResult::OK; -} - -void TestMode::waitForKeypress() { - for (uint8_t temp = 0; temp < 8; temp++) { - Kaleidoscope.device().readMatrix(); - } - while (1) { - Kaleidoscope.device().readMatrix(); - if (Kaleidoscope.device().isKeyswitchPressed(R3C6) - && Kaleidoscope.device().pressedKeyswitchCount() == 1 - && Kaleidoscope.device().previousLeftHandState.all == 0) { - break; - } - } -} - -void TestMode::set_leds(cRGB color) { - ::LEDControl.set_all_leds_to(color); - ::LEDControl.syncLeds(); - waitForKeypress(); -} - -void TestMode::test_leds(void) { - constexpr cRGB red = CRGB(201, 0, 0); - constexpr cRGB blue = CRGB(0, 0, 201); - constexpr cRGB green = CRGB(0, 201, 0); - constexpr cRGB brightWhite = CRGB(160, 160, 160); - - // make all the LEDs bright red - set_leds(red); - // make all the LEDs bright green - set_leds(green); - // make all the LEDs bright blue - set_leds(blue); - // make all the LEDs bright white (1.6A) - set_leds(brightWhite); - - // This works under the assumption that LEDRainbowEffect - // has been registered with KALEIDOSCOPE_INIT_PLUGINS in - // the sketch. Otherwise LEDRainbowEffect would not be - // known to LEDControl. - // - ::LEDControl.activate(&::LEDRainbowEffect); - - // rainbow for 10 seconds - for (auto i = 0; i < 1000; i++) { - ::LEDControl.update(); - ::LEDControl.syncLeds(); - } - waitForKeypress(); -} - - - -void TestMode::handleKeyEvent(side_data_t *side, keydata_t *oldState, keydata_t *newState, KeyAddr key_addr, uint8_t col_offset) { - - constexpr cRGB red = CRGB(201, 0, 0); - constexpr cRGB blue = CRGB(0, 0, 201); - constexpr cRGB green = CRGB(0, 201, 0); - - auto keynum = key_addr.toInt(); - - const uint8_t keyState = ((bitRead(oldState->all, keynum) << 1) | - (bitRead(newState->all, keynum) << 0)); - if (keyState == TOGGLED_ON) { - if (side->cyclesSinceStateChange[keynum] < CHATTER_CYCLE_LIMIT) { - bitSet(side->badKeys, keynum); - } - side->cyclesSinceStateChange[keynum] = 0; - } else if (side->cyclesSinceStateChange[keynum] <= CHATTER_CYCLE_LIMIT) { - side->cyclesSinceStateChange[keynum]++; - } - - auto key_addr_col_shifted = KeyAddr(key_addr.row(), col_offset - key_addr.col()); - - // If the key is held down - if (keyState == HELD) { - Kaleidoscope.device().setCrgbAt(key_addr_col_shifted, green); - } else if (bitRead(side->badKeys, key_addr_col_shifted.toInt()) == 1) { - // If we triggered chatter detection ever on this key - Kaleidoscope.device().setCrgbAt(key_addr_col_shifted, red); - } else if (keyState == TOGGLED_OFF) { - // If the key was just released - Kaleidoscope.device().setCrgbAt(key_addr_col_shifted, blue); - } -} - - -void TestMode::testMatrix() { - // Reset bad keys from previous tests. - side_data_t left = {{0}, 0}; - side_data_t right = {{0}, 0}; - - - ::LEDControl.set_all_leds_to(200, 0, 0); - // Clear out the key event buffer so we don't get messed up information from - // taps during LED test mode. - while (1) { - Kaleidoscope.device().readMatrix(); - if (Kaleidoscope.device().isKeyswitchPressed(R0C0) && - Kaleidoscope.device().isKeyswitchPressed(R0C6) && - Kaleidoscope.device().isKeyswitchPressed(R3C6) && - Kaleidoscope.device().pressedKeyswitchCount() == 3) { - break; - } - for (auto key_addr : KeyAddr::all()) { - handleKeyEvent(&left, &(Kaleidoscope.device().previousLeftHandState), &(Kaleidoscope.device().leftHandState), key_addr, 7); - handleKeyEvent(&right, &(Kaleidoscope.device().previousRightHandState), &(Kaleidoscope.device().rightHandState), key_addr, 15); - } - ::LEDControl.syncLeds(); - } -} - -void TestMode::toggle_programming_leds_on() { - PORTD |= (1 << 5); - PORTB |= (1 << 0); -} - -void TestMode::run_tests() { - // Kaleidoscope.device().serialPort().println("Running tests"); - toggle_programming_leds_on(); - // Disable debouncing - Kaleidoscope.device().setKeyscanInterval(2); - test_leds(); - testMatrix(); - // Kaleidoscope.device().serialPort().println("Done running tests"); -} - -} -} - -kaleidoscope::plugin::TestMode TestMode; - -#endif - -#endif diff --git a/src/kaleidoscope/plugin/Model01-TestMode.h b/src/kaleidoscope/plugin/Model01-TestMode.h index 38a37c22..127c6bb1 100644 --- a/src/kaleidoscope/plugin/Model01-TestMode.h +++ b/src/kaleidoscope/plugin/Model01-TestMode.h @@ -24,30 +24,18 @@ #include #include "Kaleidoscope.h" +#include "kaleidoscope_internal/deprecations.h" + +#define _DEPRECATED_MESSAGE_MODEL01_TESTMODE \ + "The Model01-specific TestMode plugin has been deprecated in favour of\n" __NL__ \ + "the more generic HardwareTestMode. Please migrate to the new one." namespace kaleidoscope { namespace plugin { class TestMode : public kaleidoscope::Plugin { public: - typedef struct { - uint8_t cyclesSinceStateChange[32]; - uint32_t badKeys; - - } side_data_t; - - TestMode(void) {} - - EventHandlerResult beforeReportingState(); - - private: - static void run_tests(); - static void test_leds(); - static void testMatrix(); - static void toggle_programming_leds_on(); - static void handleKeyEvent(side_data_t *side, keydata_t *oldState, keydata_t *newState, KeyAddr key_addr, uint8_t col_offset); - static void waitForKeypress(); - static void set_leds(cRGB color); + DEPRECATED(MODEL01_TESTMODE) EventHandlerResult beforeReportingState() {}; }; } }