-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkeys.ino
More file actions
50 lines (43 loc) · 891 Bytes
/
Copy pathkeys.ino
File metadata and controls
50 lines (43 loc) · 891 Bytes
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
#include "marco.h"
using namespace marco;
Key::Key(uint8_t idx)
{
index = idx;
pressDuration = 0;
}
void Key::setColor(uint32_t c)
{
color = c;
}
void Key::press()
{
if (!pressed)
{
pressed = true;
lastPressMillis = millis();
Instruction keydown(EVENT, index, KEYDOWN);
keydown.send();
}
else
{
pressDuration = millis() - lastPressMillis;
uint8_t pressDuration100Ms = durationToByte();
if (pressDuration100Ms != lastTransmittedDuration)
{
lastTransmittedDuration = pressDuration100Ms;
Instruction keyhold(EVENT, index, KEYHOLD, pressDuration100Ms);
keyhold.send();
}
}
}
void Key::unpress()
{
pressed = false;
pressDuration = 0;
Instruction keyup(EVENT, index, KEYUP, durationToByte());
keyup.send();
}
uint8_t Key::durationToByte()
{
return uint8_t((pressDuration / (unsigned long)100) % (0xF + 1));
}