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