-
Notifications
You must be signed in to change notification settings - Fork 105
/
Copy pathDevices.cpp
265 lines (215 loc) · 6.83 KB
/
Devices.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
/*
* Copyright (C) 2024 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "Devices.h"
#define LOG_TAG "Devices"
#include <android-base/logging.h>
namespace aidl {
namespace android {
namespace hardware {
namespace light {
static const std::string kBacklightDevices[] = {
"backlight",
"panel0-backlight",
"panel0-backlight-ex",
"sprd_backlight",
};
static std::vector<BacklightDevice> getBacklightDevices() {
std::vector<BacklightDevice> devices;
for (const auto& device : kBacklightDevices) {
BacklightDevice backlight(device);
if (backlight.exists()) {
LOG(INFO) << "Found backlight device: " << backlight.getName();
devices.push_back(backlight);
}
}
return devices;
}
static const std::string kLedBacklightDevices[] = {
"lcd-backlight",
"lcd-backlight-ex",
"lcd_backlight0",
};
static std::vector<LedDevice> getBacklightLedDevices() {
std::vector<LedDevice> devices;
for (const auto& device : kLedBacklightDevices) {
LedDevice backlight(device);
if (backlight.exists()) {
LOG(INFO) << "Found backlight LED device: " << backlight.getName();
devices.push_back(backlight);
}
}
return devices;
}
static const std::string kButtonLedDevices[] = {
"button-backlight",
"button-backlight1",
"button-backlight2",
};
static std::vector<LedDevice> getButtonLedDevices() {
std::vector<LedDevice> devices;
for (const auto& device : kButtonLedDevices) {
LedDevice button(device);
if (button.exists()) {
LOG(INFO) << "Found button LED device: " << button.getName();
devices.emplace_back(button);
}
}
return devices;
}
static const std::string kKeyboardLedDevices[] = {
"keyboard-backlight",
};
static std::vector<LedDevice> getKeyboardLedDevices() {
std::vector<LedDevice> devices;
for (const auto& device : kKeyboardLedDevices) {
LedDevice keyboard(device);
if (keyboard.exists()) {
LOG(INFO) << "Found keyboard LED device: " << keyboard.getName();
devices.emplace_back(keyboard);
}
}
return devices;
}
static const std::string kRgbLedDevices[][4] = {
{"red", "green", "blue", "/sys/class/leds/rgb/rgb_blink"},
};
static std::vector<RgbLedDevice> getNotificationRgbLedDevices() {
std::vector<RgbLedDevice> devices;
for (const auto& device : kRgbLedDevices) {
LedDevice red(device[0]);
LedDevice green(device[1]);
LedDevice blue(device[2]);
RgbLedDevice rgbLedDevice(red, green, blue, device[3]);
if (rgbLedDevice.exists()) {
LOG(INFO) << "Found notification RGB LED device: " << red.getName() << ", "
<< green.getName() << ", " << blue.getName();
devices.emplace_back(red, green, blue, device[3]);
}
}
return devices;
}
static const std::string kNotificationLedDevices[] = {
"charging",
"left",
"white",
};
static std::vector<LedDevice> getNotificationLedDevices() {
std::vector<LedDevice> devices;
for (const auto& device : kNotificationLedDevices) {
LedDevice notification(device);
if (notification.exists()) {
LOG(INFO) << "Found notification LED device: " << notification.getName();
devices.emplace_back(notification);
}
}
return devices;
}
Devices::Devices()
: mBacklightDevices(getBacklightDevices()),
mBacklightLedDevices(getBacklightLedDevices()),
mButtonLedDevices(getButtonLedDevices()),
mKeyboardLedDevices(getKeyboardLedDevices()),
mNotificationRgbLedDevices(getNotificationRgbLedDevices()),
mNotificationLedDevices(getNotificationLedDevices()) {
if (!hasBacklightDevices()) {
LOG(INFO) << "No backlight devices found";
}
if (!hasButtonDevices()) {
LOG(INFO) << "No button devices found";
}
if (!hasKeyboardDevices()) {
LOG(INFO) << "No keyboard devices found";
}
if (!hasNotificationDevices()) {
LOG(INFO) << "No notification devices found";
}
}
bool Devices::hasBacklightDevices() const {
return !mBacklightDevices.empty() || !mBacklightLedDevices.empty();
}
bool Devices::hasButtonDevices() const {
return !mButtonLedDevices.empty();
}
bool Devices::hasKeyboardDevices() const {
return !mKeyboardLedDevices.empty();
}
bool Devices::hasNotificationDevices() const {
return !mNotificationRgbLedDevices.empty() || !mNotificationLedDevices.empty();
}
void Devices::setBacklightColor(rgb color) {
for (auto& device : mBacklightDevices) {
device.setBrightness(color.toBrightness());
}
for (auto& device : mBacklightLedDevices) {
device.setBrightness(color.toBrightness());
}
}
void Devices::setButtonsColor(rgb color) {
for (auto& device : mButtonLedDevices) {
device.setBrightness(color.toBrightness());
}
}
void Devices::setKeyboardColor(rgb color) {
for (auto& device : mKeyboardLedDevices) {
device.setBrightness(color.toBrightness());
}
}
void Devices::setNotificationColor(rgb color, LightMode mode, uint32_t flashOnMs,
uint32_t flashOffMs) {
for (auto& device : mNotificationRgbLedDevices) {
device.setBrightness(color, mode, flashOnMs, flashOffMs);
}
for (auto& device : mNotificationLedDevices) {
device.setBrightness(color.toBrightness(), mode, flashOnMs, flashOffMs);
}
}
void Devices::dump(int fd) const {
dprintf(fd, "Backlight devices:\n");
for (const auto& device : mBacklightDevices) {
dprintf(fd, "- ");
device.dump(fd);
dprintf(fd, "\n");
}
dprintf(fd, "\n");
dprintf(fd, "Backlight LED devices:\n");
for (const auto& device : mBacklightLedDevices) {
dprintf(fd, "- ");
device.dump(fd);
dprintf(fd, "\n");
}
dprintf(fd, "\n");
dprintf(fd, "Button LED devices:\n");
for (const auto& device : mButtonLedDevices) {
dprintf(fd, "- ");
device.dump(fd);
dprintf(fd, "\n");
}
dprintf(fd, "\n");
dprintf(fd, "Keyboard LED devices:\n");
for (const auto& device : mKeyboardLedDevices) {
dprintf(fd, "- ");
device.dump(fd);
dprintf(fd, "\n");
}
dprintf(fd, "Notification RGB LED devices:\n");
for (const auto& device : mNotificationRgbLedDevices) {
dprintf(fd, "- ");
device.dump(fd);
dprintf(fd, "\n");
}
dprintf(fd, "\n");
dprintf(fd, "Notification LED devices:\n");
for (const auto& device : mNotificationLedDevices) {
dprintf(fd, "- ");
device.dump(fd);
dprintf(fd, "\n");
}
return;
}
} // namespace light
} // namespace hardware
} // namespace android
} // namespace aidl