2024-04-18 11:34:39 -04:00
|
|
|
/*
|
|
|
|
* 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",
|
|
|
|
};
|
|
|
|
|
|
|
|
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",
|
|
|
|
};
|
|
|
|
|
|
|
|
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",
|
2024-06-22 06:26:14 -04:00
|
|
|
"button-backlight2",
|
2024-04-18 11:34:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2024-06-22 10:14:02 -04:00
|
|
|
static const std::string kRgbLedDevices[][4] = {
|
|
|
|
{"red", "green", "blue", "/sys/class/leds/rgb/rgb_blink"},
|
2024-04-18 11:34:39 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
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]);
|
|
|
|
|
2024-06-22 10:14:02 -04:00
|
|
|
RgbLedDevice rgbLedDevice(red, green, blue, device[3]);
|
2024-04-18 11:34:39 -04:00
|
|
|
if (rgbLedDevice.exists()) {
|
|
|
|
LOG(INFO) << "Found notification RGB LED device: " << red.getName() << ", "
|
|
|
|
<< green.getName() << ", " << blue.getName();
|
2024-06-22 10:14:02 -04:00
|
|
|
devices.emplace_back(red, green, blue, device[3]);
|
2024-04-18 11:34:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return devices;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const std::string kNotificationLedDevices[] = {
|
2024-06-22 06:36:49 -04:00
|
|
|
"left",
|
2024-04-18 11:34:39 -04:00
|
|
|
"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()),
|
|
|
|
mNotificationRgbLedDevices(getNotificationRgbLedDevices()),
|
|
|
|
mNotificationLedDevices(getNotificationLedDevices()) {
|
|
|
|
if (!hasBacklightDevices()) {
|
|
|
|
LOG(INFO) << "No backlight devices found";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!hasButtonDevices()) {
|
|
|
|
LOG(INFO) << "No button 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::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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-17 19:45:59 -04:00
|
|
|
void Devices::setNotificationColor(rgb color, LightMode mode, uint32_t flashOnMs,
|
|
|
|
uint32_t flashOffMs) {
|
2024-04-18 11:34:39 -04:00
|
|
|
for (auto& device : mNotificationRgbLedDevices) {
|
2024-06-17 19:45:59 -04:00
|
|
|
device.setBrightness(color, mode, flashOnMs, flashOffMs);
|
2024-04-18 11:34:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& device : mNotificationLedDevices) {
|
2024-06-17 19:45:59 -04:00
|
|
|
device.setBrightness(color.toBrightness(), mode, flashOnMs, flashOffMs);
|
2024-04-18 11:34:39 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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, "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
|