-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathLED-CapsLockLight.cpp
69 lines (56 loc) · 1.91 KB
/
LED-CapsLockLight.cpp
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
/* -*- mode: c++ -*-
* kaleidoscope::plugin::LEDCapsLockLight -- Highlight CapsLock when active
* Copyright (C) 2020 Dygma Lab S.L.
*
* 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 "LED-CapsLockLight.h"
namespace kaleidoscope {
namespace plugin {
KeyAddr LEDCapsLockLight::caps_address_ = UnknownKeyswitchLocation;
uint8_t LEDCapsLockLight::highlight_hue_ = 0;
bool LEDCapsLockLight::caps_was_on_;
EventHandlerResult LEDCapsLockLight::onSetup() {
return findCapsLock();
}
EventHandlerResult LEDCapsLockLight::onLayerChange() {
return findCapsLock();
}
EventHandlerResult LEDCapsLockLight::beforeReportingState() {
if (!caps_address_.isValid())
return EventHandlerResult::OK;
bool caps_is_on = !!(Runtime.hid().keyboard().getKeyboardLEDs() & LED_CAPS_LOCK);
if (!caps_is_on && caps_was_on_) {
::LEDControl.refreshAt(caps_address_);
}
if (caps_is_on) {
cRGB color = breath_compute(highlight_hue_);
::LEDControl.setCrgbAt(caps_address_, color);
}
caps_was_on_ = caps_is_on;
return EventHandlerResult::OK;
}
EventHandlerResult LEDCapsLockLight::findCapsLock() {
caps_address_ = UnknownKeyswitchLocation;
for (auto key_addr: KeyAddr::all()) {
Key k = Layer.lookup(key_addr);
if (k == Key_CapsLock) {
caps_address_ = key_addr;
break;
}
}
return EventHandlerResult::OK;
}
}
}
kaleidoscope::plugin::LEDCapsLockLight LEDCapsLockLight;