From 25c975eae7422a7908cb0ef2d5cc01f83c1d4ac6 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Mon, 14 Jun 2021 19:49:16 -0500 Subject: [PATCH] Add testcase for issue 1061 This is a demonstration that another plugin can use the new public OneShot methods to turn a non-OneShot key into a OneShot. Signed-off-by: Michael Richters --- tests/issues/1061/1061.ino | 70 ++++++++++++++++++++++++ tests/issues/1061/sketch.json | 6 ++ tests/issues/1061/test.ktest | 100 ++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 tests/issues/1061/1061.ino create mode 100644 tests/issues/1061/sketch.json create mode 100644 tests/issues/1061/test.ktest diff --git a/tests/issues/1061/1061.ino b/tests/issues/1061/1061.ino new file mode 100644 index 00000000..f9d8b275 --- /dev/null +++ b/tests/issues/1061/1061.ino @@ -0,0 +1,70 @@ +/* -*- mode: c++ -*- + * Copyright (C) 2021 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 . + */ + +#include +#include + +// *INDENT-OFF* +KEYMAPS( + [0] = KEYMAP_STACKED + ( + Key_Insert, ___, ___, ___, ___, ___, ___, + Key_A, Key_B, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, + ___, + + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, + ___ + ), +) +// *INDENT-ON* + +namespace kaleidoscope { +namespace plugin { + +class OneShotInsert : public Plugin { + public: + EventHandlerResult onKeyEvent(KeyEvent &event) { + if (keyToggledOn(event.state) && (event.state & INJECTED) == 0 && + event.key == Key_Insert && live_keys[event.addr] != event.key) + ::OneShot.setPending(event.addr); + return EventHandlerResult::OK; + } +}; + +} // namespace plugin +} // namespace kaleidoscope + +kaleidoscope::plugin::OneShotInsert OneShotInsert; + +KALEIDOSCOPE_INIT_PLUGINS(OneShot, OneShotInsert); + +void setup() { + Kaleidoscope.setup(); + OneShot.setTimeout(50); + OneShot.setHoldTimeout(20); + OneShot.setDoubleTapTimeout(20); +} + +void loop() { + Kaleidoscope.loop(); +} diff --git a/tests/issues/1061/sketch.json b/tests/issues/1061/sketch.json new file mode 100644 index 00000000..8cc86922 --- /dev/null +++ b/tests/issues/1061/sketch.json @@ -0,0 +1,6 @@ +{ + "cpu": { + "fqbn": "keyboardio:virtual:model01", + "port": "" + } +} diff --git a/tests/issues/1061/test.ktest b/tests/issues/1061/test.ktest new file mode 100644 index 00000000..1d72c372 --- /dev/null +++ b/tests/issues/1061/test.ktest @@ -0,0 +1,100 @@ +VERSION 1 + +KEYSWITCH INSERT 0 0 +KEYSWITCH A 1 0 +KEYSWITCH B 1 1 + +# ============================================================================== +NAME OneShot insert timeout + +RUN 4 ms +PRESS INSERT +RUN 1 cycle +EXPECT keyboard-report Key_Insert + +RUN 4 ms +RELEASE INSERT +RUN 1 cycle + +RUN 45 ms +EXPECT keyboard-report empty + +RUN 4 ms +PRESS A +RUN 1 cycle +EXPECT keyboard-report Key_A + +RUN 4 ms +RELEASE A +RUN 1 cycle +EXPECT keyboard-report empty + +RUN 5 ms + +# ============================================================================== +NAME OneShot insert interrupt + +RUN 4 ms +PRESS INSERT +RUN 1 cycle +EXPECT keyboard-report Key_Insert + +RUN 4 ms +RELEASE INSERT +RUN 1 cycle + +RUN 4 ms +PRESS A +RUN 1 cycle +EXPECT keyboard-report Key_Insert Key_A +EXPECT keyboard-report Key_A + +RUN 4 ms +RELEASE A +RUN 1 cycle +EXPECT keyboard-report empty + +RUN 5 ms + +# ============================================================================== +NAME OneShot insert sticky + +RUN 4 ms +PRESS INSERT +RUN 1 cycle +EXPECT keyboard-report Key_Insert + +RUN 4 ms +RELEASE INSERT +RUN 1 cycle + +RUN 4 ms +PRESS INSERT +RUN 1 cycle + +RUN 4 ms +RELEASE INSERT +RUN 1 cycle + +RUN 4 ms +PRESS A +RUN 1 cycle +EXPECT keyboard-report Key_Insert Key_A + +RUN 4 ms +RELEASE A +RUN 1 cycle +EXPECT keyboard-report Key_Insert + +RUN 100 ms + +RUN 4 ms +PRESS INSERT +RUN 1 cycle + +RUN 4 ms +RELEASE INSERT +RUN 1 cycle +EXPECT keyboard-report empty + +RUN 5 ms