From 40cc6a290e381797df3f3f0b6de17cf86183d340 Mon Sep 17 00:00:00 2001 From: Michael Richters Date: Sun, 22 Nov 2020 11:28:51 -0600 Subject: [PATCH] Add basic MagicCombo testcase Signed-off-by: Michael Richters --- tests/plugins/MagicCombo/basic/common.h | 27 ++++++++++ tests/plugins/MagicCombo/basic/sketch.ino | 66 +++++++++++++++++++++++ tests/plugins/MagicCombo/basic/test.ktest | 30 +++++++++++ 3 files changed, 123 insertions(+) create mode 100644 tests/plugins/MagicCombo/basic/common.h create mode 100644 tests/plugins/MagicCombo/basic/sketch.ino create mode 100644 tests/plugins/MagicCombo/basic/test.ktest diff --git a/tests/plugins/MagicCombo/basic/common.h b/tests/plugins/MagicCombo/basic/common.h new file mode 100644 index 00000000..dcfcc35b --- /dev/null +++ b/tests/plugins/MagicCombo/basic/common.h @@ -0,0 +1,27 @@ +// -*- mode: c++ -*- + +/* Kaleidoscope - Firmware for computer input devices + * Copyright (C) 2020 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 . + */ + +#pragma once + +#include + +namespace kaleidoscope { +namespace testing { + +} // namespace testing +} // namespace kaleidoscope diff --git a/tests/plugins/MagicCombo/basic/sketch.ino b/tests/plugins/MagicCombo/basic/sketch.ino new file mode 100644 index 00000000..f5bdc3ed --- /dev/null +++ b/tests/plugins/MagicCombo/basic/sketch.ino @@ -0,0 +1,66 @@ +/* -*- mode: c++ -*- + * Copyright (C) 2020 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 + +#include "./common.h" + +#undef min +#undef max +#include + +// *INDENT-OFF* +KEYMAPS( + [0] = KEYMAP_STACKED + ( + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, + ___, + + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, ___, ___, ___, + ___, ___, ___, ___, + ___ + ), +) +// *INDENT-ON* + +void tapKeyA(uint8_t magic_combo_index) { + std::cerr << "tapKeyA" << std::endl; + handleKeyswitchEvent(Key_A, KeyAddr{1, 0}, IS_PRESSED | INJECTED); + Kaleidoscope.hid().keyboard().sendReport(); + handleKeyswitchEvent(Key_NoKey, KeyAddr{1, 0}, WAS_PRESSED | INJECTED); + Kaleidoscope.hid().keyboard().sendReport(); +} + +USE_MAGIC_COMBOS({.action = tapKeyA, .keys = {R0C0, R0C1, R0C2}}); + +KALEIDOSCOPE_INIT_PLUGINS(MagicCombo); + +void setup() { + Kaleidoscope.setup(); + MagicCombo.min_interval = 20; +} + +void loop() { + Kaleidoscope.loop(); +} diff --git a/tests/plugins/MagicCombo/basic/test.ktest b/tests/plugins/MagicCombo/basic/test.ktest new file mode 100644 index 00000000..4bde2201 --- /dev/null +++ b/tests/plugins/MagicCombo/basic/test.ktest @@ -0,0 +1,30 @@ +VERSION 1 + +KEYSWITCH MC0 0 0 +KEYSWITCH MC1 0 1 +KEYSWITCH MC2 0 2 + +# ============================================================================== +NAME MagicCombo key A + +RUN 5 ms +PRESS MC2 +PRESS MC1 +RUN 5 ms +PRESS MC0 +RUN 10 ms +# With MagicCombo.min_interval set to 20(ms), we need to wait that long before +# it will trigger, plus one. +RUN 1 ms +EXPECT keyboard-report Key_A # The report should contain only `A` +EXPECT keyboard-report empty # Report should be empty +RUN 5 ms +RELEASE MC0 +RUN 1 cycle +RELEASE MC2 +RUN 1 cycle +RELEASE MC1 +RUN 1 cycle + +# Run a bit longer to make sure no extra reports were generated. +RUN 5 ms