forked from kairyu/tkg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathled_map.js
More file actions
153 lines (148 loc) · 3.11 KB
/
Copy pathled_map.js
File metadata and controls
153 lines (148 loc) · 3.11 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
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
var led_map = {
"LEDMAP_ACTIVE_LOW": {
"name": "Active Low",
"description": "",
"code": function(binding, reverse, backlight) {
if (reverse != 0) {
reverse = 0x1000;
}
if (backlight != 0) {
backlight = 0x2000;
}
console.log(binding);
return "0x" + dechex(backlight + reverse + binding, 4);
},
"param": [ "binding", "reverse", "backlight" ],
"default": [ "LEDMAP_BINDING_NO", 0, 0 ]
},
"LEDMAP_ACTIVE_HIGH": {
"name": "Active High",
"description": "",
"code": function(binding, reverse, backlight) {
if (reverse != 0) {
reverse = 0x1000;
}
if (backlight != 0) {
backlight = 0x2000;
}
return "0x" + dechex(0x4000 + backlight + reverse + binding, 4);
},
"param": [ "binding", "reverse", "backlight" ],
"default": [ "LEDMAP_BINDING_NO", 0, 0 ]
},
"LEDMAP_RGB_LED": {
"name": "RGB LED",
"description": "",
"code": function(led_count) {
return "0x80" + dechex(led_count, 2);
},
"param": [ "led_count" ],
"default": [ 16 ]
}
}
var binding_map = {
"LEDMAP_BINDING_NO": {
"group": "None",
"name": "None",
"description": "Binding to nothing",
"code": 0
},
"LEDMAP_BINDING_DEFAULT_LAYER": {
"group": "Layer",
"name": "Default layer",
"description": "Binding to state of default layer",
"code": function(layer) {
layer = Number(layer);
if (layer < 0) {
layer = 0;
}
if (layer > 31) {
layer = 31;
}
return 0x0100 + layer;
},
"param": [ "layer" ],
"default": [ 0 ]
},
"LEDMAP_BINDING_LAYER": {
"group": "Layer",
"name": "Layer",
"description": "Binding to state of layer",
"code": function(layer) {
layer = Number(layer);
if (layer < 0) {
layer = 0;
}
if (layer > 31) {
layer = 31;
}
return 0x0200 + layer;
},
"param": [ "layer" ],
"default": [ 0 ]
},
"LEDMAP_BINDING_INDICATOR": {
"group": "Indicator",
"name": "Indicator",
"description": "Binding to state of indicator",
"code": function(ind) {
ind = Number(ind);
if (ind < 0) {
ind = 0;
}
if (ind > 2) {
ind = 2;
}
return 0x0300 + ind;
},
"param": [ "ind" ],
"default": [ "LEDMAP_NUM_LOCK" ]
}
}
var ind_map = {
"LEDMAP_NUM_LOCK": {
"name": "Num Lock",
"description": "Indicate state of Num Lock",
"code": 0
},
"LEDMAP_CAPS_LOCK": {
"name": "Caps Lock",
"description": "Indicate state of Caps Lock",
"code": 1
},
"LEDMAP_SCROLL_LOCK": {
"name": "Scroll Lock",
"description": "Indicate state of Scroll Lock",
"code": 2
}
}
function dechex(dec, pad) {
var hex = Number(dec).toString(16).toUpperCase();
pad = typeof(pad) === "undefined" || pad == null ? pad = 1 : pad;
while (hex.length < pad) {
hex = "0" + hex;
}
return hex;
}
var reverse_map = {
"LEDMAP_REVERSE": {
"name": "Reverse",
"description": "Reverse binding state",
"code": function(reverse) {
return 0x1000 * reverse;
},
"param": [ "reverse" ],
"default": [ 0 ]
}
}
var backlight_map = {
"LEDMAP_BACKLIGHT": {
"name": "Backlight",
"description": "Force on when backlight is on",
"code": function(backlight) {
return 0x2000 * backlight;
},
"param": [ "backlight" ],
"default": [ 0 ]
}
}