Merge pull request #966 from gedankenexperimenter/b/macros.key-range
Standardize Macros key definitionspull/969/head
commit
5a9aa3b3a9
@ -0,0 +1,69 @@
|
||||
/* -*- 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <Kaleidoscope.h>
|
||||
#include <Kaleidoscope-Macros.h>
|
||||
|
||||
// *INDENT-OFF*
|
||||
KEYMAPS(
|
||||
[0] = KEYMAP_STACKED
|
||||
(
|
||||
M(0), M(1), M(255), ___, ___, ___, ___,
|
||||
Key_X, ___, ___, ___, ___, ___, ___,
|
||||
___, ___, ___, ___, ___, ___,
|
||||
___, ___, ___, ___, ___, ___, ___,
|
||||
|
||||
___, ___, ___, ___,
|
||||
___,
|
||||
|
||||
___, ___, ___, ___, ___, ___, ___,
|
||||
___, ___, ___, ___, ___, ___, ___,
|
||||
___, ___, ___, ___, ___, ___,
|
||||
___, ___, ___, ___, ___, ___, ___,
|
||||
|
||||
___, ___, ___, ___,
|
||||
___
|
||||
),
|
||||
)
|
||||
// *INDENT-ON*
|
||||
|
||||
const macro_t *macroAction(uint8_t index, uint8_t key_state) {
|
||||
if (keyToggledOn(key_state)) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
Kaleidoscope.hid().keyboard().pressKey(Key_A);
|
||||
break;
|
||||
case 1:
|
||||
Kaleidoscope.hid().keyboard().pressKey(Key_B);
|
||||
break;
|
||||
case 255:
|
||||
Kaleidoscope.hid().keyboard().pressKey(Key_C);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return MACRO_NONE;
|
||||
}
|
||||
|
||||
// Use Redial
|
||||
KALEIDOSCOPE_INIT_PLUGINS(Macros);
|
||||
|
||||
void setup() {
|
||||
Kaleidoscope.setup();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Kaleidoscope.loop();
|
||||
}
|
@ -0,0 +1,136 @@
|
||||
/* -*- 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "testing/setup-googletest.h"
|
||||
|
||||
SETUP_GOOGLETEST();
|
||||
|
||||
namespace kaleidoscope {
|
||||
namespace testing {
|
||||
namespace {
|
||||
|
||||
constexpr KeyAddr addr_macro_A{0, 0};
|
||||
constexpr KeyAddr addr_macro_B{0, 1};
|
||||
constexpr KeyAddr addr_macro_C{0, 2};
|
||||
constexpr KeyAddr addr_macro_X{0, 3};
|
||||
constexpr KeyAddr addr_X{1, 0};
|
||||
|
||||
class MacrosBasic : public VirtualDeviceTest {
|
||||
protected:
|
||||
std::set<uint8_t> expected_keycodes_ = {};
|
||||
std::unique_ptr<State> state_ = nullptr;
|
||||
};
|
||||
|
||||
TEST_F(MacrosBasic, MacroIndex_0) {
|
||||
|
||||
sim_.Press(addr_macro_A);
|
||||
state_ = RunCycle();
|
||||
expected_keycodes_.insert(Key_A.getKeyCode());
|
||||
|
||||
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 1)
|
||||
<< "There should be one HID report";
|
||||
EXPECT_THAT(state_->HIDReports()->Keyboard(0).ActiveKeycodes(),
|
||||
::testing::ElementsAreArray(expected_keycodes_))
|
||||
<< "The report should include only `A`";
|
||||
|
||||
sim_.Release(addr_macro_A);
|
||||
state_ = RunCycle();
|
||||
expected_keycodes_.erase(Key_A.getKeyCode());
|
||||
|
||||
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 1)
|
||||
<< "There should be one report after letter key release";
|
||||
EXPECT_THAT(state_->HIDReports()->Keyboard(0).ActiveKeycodes(),
|
||||
::testing::ElementsAreArray(expected_keycodes_))
|
||||
<< "The report should be empty";
|
||||
}
|
||||
|
||||
TEST_F(MacrosBasic, MacroIndex_1) {
|
||||
|
||||
sim_.Press(addr_macro_B);
|
||||
state_ = RunCycle();
|
||||
expected_keycodes_.insert(Key_B.getKeyCode());
|
||||
|
||||
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 1)
|
||||
<< "There should be one HID report";
|
||||
EXPECT_THAT(state_->HIDReports()->Keyboard(0).ActiveKeycodes(),
|
||||
::testing::ElementsAreArray(expected_keycodes_))
|
||||
<< "The report should include only `B`";
|
||||
|
||||
sim_.Release(addr_macro_B);
|
||||
state_ = RunCycle();
|
||||
expected_keycodes_.erase(Key_B.getKeyCode());
|
||||
|
||||
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 1)
|
||||
<< "There should be one report after letter key release";
|
||||
EXPECT_THAT(state_->HIDReports()->Keyboard(0).ActiveKeycodes(),
|
||||
::testing::ElementsAreArray(expected_keycodes_))
|
||||
<< "The report should be empty";
|
||||
}
|
||||
|
||||
TEST_F(MacrosBasic, MacroIndex_255) {
|
||||
|
||||
sim_.Press(addr_macro_C);
|
||||
state_ = RunCycle();
|
||||
expected_keycodes_.insert(Key_C.getKeyCode());
|
||||
|
||||
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 1)
|
||||
<< "There should be one HID report";
|
||||
EXPECT_THAT(state_->HIDReports()->Keyboard(0).ActiveKeycodes(),
|
||||
::testing::ElementsAreArray(expected_keycodes_))
|
||||
<< "The report should include only `C`";
|
||||
|
||||
state_ = RunCycle();
|
||||
expected_keycodes_.erase(Key_C.getKeyCode());
|
||||
|
||||
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 1)
|
||||
<< "There should be one report in the next cycle";
|
||||
EXPECT_THAT(state_->HIDReports()->Keyboard(0).ActiveKeycodes(),
|
||||
::testing::ElementsAreArray(expected_keycodes_))
|
||||
<< "The report should be empty";
|
||||
|
||||
sim_.Release(addr_macro_C);
|
||||
state_ = RunCycle();
|
||||
|
||||
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 0)
|
||||
<< "There should be no report after release";
|
||||
}
|
||||
|
||||
TEST_F(MacrosBasic, NonMacrosKey) {
|
||||
|
||||
sim_.Press(addr_X);
|
||||
state_ = RunCycle();
|
||||
expected_keycodes_.insert(Key_X.getKeyCode());
|
||||
|
||||
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 1)
|
||||
<< "There should be one HID report";
|
||||
EXPECT_THAT(state_->HIDReports()->Keyboard(0).ActiveKeycodes(),
|
||||
::testing::ElementsAreArray(expected_keycodes_))
|
||||
<< "The report should include only `X`";
|
||||
|
||||
sim_.Release(addr_X);
|
||||
state_ = RunCycle();
|
||||
expected_keycodes_.erase(Key_X.getKeyCode());
|
||||
|
||||
ASSERT_EQ(state_->HIDReports()->Keyboard().size(), 1)
|
||||
<< "There should be one report after letter key release";
|
||||
EXPECT_THAT(state_->HIDReports()->Keyboard(0).ActiveKeycodes(),
|
||||
::testing::ElementsAreArray(expected_keycodes_))
|
||||
<< "The report should be empty";
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace testing
|
||||
} // namespace kaleidoscope
|
Loading…
Reference in new issue