forked from ecraven/g13
-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathg13_keys.cpp
More file actions
66 lines (54 loc) · 1.66 KB
/
Copy pathg13_keys.cpp
File metadata and controls
66 lines (54 loc) · 1.66 KB
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
/* This file contains code for managing keys an profiles
*
*/
// TODO: check out why g13.h needs to be included before libevdev
// clang-format off
#include "g13.hpp"
#include "g13_device.hpp"
#include "g13_keys.hpp"
#include "helper.hpp"
// clang-format on
namespace G13 {
// clang-format off
const char* G13_Key_Tables::G13_KEY_STRINGS[] = {
/* byte 3 */
"G1", "G2", "G3", "G4", "G5", "G6", "G7", "G8",
/* byte 4 */
"G9", "G10", "G11", "G12", "G13", "G14", "G15", "G16",
/* byte 5 */
"G17", "G18", "G19", "G20", "G21", "G22", "UNDEF1", "LIGHT_STATE",
/* byte 6 */
"BD", "L1", "L2", "L3", "L4", "M1", "M2", "M3",
/* byte 7 */
"MR", "LEFT", "DOWN", "TOP", "UNDEF3", "LIGHT", "LIGHT2", "MISC_TOGGLE",
nullptr
};
const char *G13_Key_Tables::G13_NONPARSED_KEYS[] = {
"UNDEF1", "LIGHT_STATE", "UNDEF3", "LIGHT",
"LIGHT2", "UNDEF3", "MISC_TOGGLE",
nullptr
};
const char* G13_Key_Tables::G13_BTN_SEQ[] = {
"LEFT", "RIGHT", "MIDDLE", "SIDE", "EXTRA",
nullptr
};
// clang-format on
void G13_Key::dump(std::ostream &o) const {
o << G13_Manager::Instance()->FindG13KeyName(index()) << "(" << index()
<< ") : ";
if (action()) {
action()->dump(o);
} else {
o << "(no action)";
}
}
// *************************************************************************
void G13_Key::ParseKey(const unsigned char *byte, G13_Device *g13) {
bool key_is_down = byte[_index.offset] & _index.mask;
auto key_state_changed = g13->update(_index.index, key_is_down);
if (key_state_changed && _action) {
_action->act(*g13, key_is_down);
}
}
// *************************************************************************
} // namespace G13