-
Notifications
You must be signed in to change notification settings - Fork 9
/
builtin_keycode.cc
112 lines (88 loc) · 3.05 KB
/
builtin_keycode.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include <vector>
#include "hardware/watchdog.h"
#include "keyscan.h"
#include "layout.h"
#include "pico/bootrom.h"
#include "runner.h"
class MouseButtonHandler : public CustomKeycodeHandler {
public:
// Using ProcessKeyState callback because we want to keep on sending the mouse
// keycode until the key is released.
void ProcessKeyState(Keycode kc, bool is_pressed, size_t key_idx) override {
(void)key_idx;
key_scan_->SetMouseButtonState(kc.keycode, is_pressed);
}
std::string GetName() const override { return "Mouse key handler"; }
};
REGISTER_CUSTOM_KEYCODE_HANDLER(MSE_L, true, MouseButtonHandler);
REGISTER_CUSTOM_KEYCODE_HANDLER(MSE_R, true, MouseButtonHandler);
REGISTER_CUSTOM_KEYCODE_HANDLER(MSE_M, true, MouseButtonHandler);
REGISTER_CUSTOM_KEYCODE_HANDLER(MSE_BACK, true, MouseButtonHandler);
REGISTER_CUSTOM_KEYCODE_HANDLER(MSE_FORWARD, true, MouseButtonHandler);
class LayerButtonHandler : public CustomKeycodeHandler {
public:
LayerButtonHandler() {}
void ProcessKeyEvent(Keycode kc, bool is_pressed, size_t key_idx) override {
(void)key_idx;
const bool toggle = kc.custom_info & 0x40;
const uint8_t layer = kc.custom_info & 0x3f;
if (toggle) {
if (is_pressed) {
key_scan_->ToggleLayerStatus(layer);
}
} else {
key_scan_->SetLayerStatus(layer, is_pressed);
}
}
std::string GetName() const override { return "Layer switch key handler"; }
};
REGISTER_CUSTOM_KEYCODE_HANDLER(LAYER_SWITCH, true, LayerButtonHandler);
class EnterConfigHandler : public CustomKeycodeHandler {
public:
void ProcessKeyEvent(Keycode kc, bool is_pressed, size_t key_idx) override {
(void)key_idx;
if (is_pressed) {
runner::SetConfigMode(true);
}
}
std::string GetName() const override { return "Enter config mode"; }
};
REGISTER_CUSTOM_KEYCODE_HANDLER(ENTER_CONFIG, true, EnterConfigHandler);
class ConfigSelHandler : public CustomKeycodeHandler {
public:
ConfigSelHandler() : currently_pressed_(false) {}
void ProcessKeyEvent(Keycode kc, bool is_pressed, size_t key_idx) override {
(void)key_idx;
if (is_pressed) {
key_scan_->ConfigSelect();
}
}
std::string GetName() const override { return "Config sel handler"; }
private:
bool currently_pressed_;
};
REGISTER_CUSTOM_KEYCODE_HANDLER(CONFIG_SEL, true, ConfigSelHandler);
class BootselHandler : public CustomKeycodeHandler {
public:
BootselHandler() {}
void ProcessKeyState(Keycode kc, bool is_pressed, size_t key_idx) override {
(void)key_idx;
if (is_pressed) {
reset_usb_boot(0, 0);
}
}
std::string GetName() const override { return "Enter bootsel handler"; }
};
REGISTER_CUSTOM_KEYCODE_HANDLER(BOOTSEL, true, BootselHandler);
class RebootHandler : public CustomKeycodeHandler {
public:
RebootHandler() {}
void ProcessKeyState(Keycode kc, bool is_pressed, size_t key_idx) override {
(void)key_idx;
if (is_pressed) {
watchdog_reboot(0, 0, 0);
}
}
std::string GetName() const override { return "Reboot"; }
};
REGISTER_CUSTOM_KEYCODE_HANDLER(REBOOT, true, RebootHandler);