hardware_xiaomi/aidl/light/BacklightDevice.cpp
Sebastiano Barezzi ee864f39ea
aidl: light: Refactor
Change-Id: Ib4ae8e9821dd0fb36e922e2c5f993aa6c0e28be1
2024-06-18 02:32:19 +02:00

56 lines
1.4 KiB
C++

/*
* Copyright (C) 2022-2024 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "BacklightDevice.h"
#define LOG_TAG "BacklightDevice"
#include <android-base/logging.h>
#include <fstream>
#include "Utils.h"
namespace aidl {
namespace android {
namespace hardware {
namespace light {
static const std::string kBacklightBasePath = "/sys/class/backlight/";
static const uint32_t kDefaultMaxBrightness = 255;
static const std::string kBrightnessNode = "brightness";
static const std::string kMaxBrightnessNode = "max_brightness";
BacklightDevice::BacklightDevice(std::string name)
: mName(name), mBasePath(kBacklightBasePath + name + "/") {
if (!readFromFile(mBasePath + kMaxBrightnessNode, mMaxBrightness)) {
mMaxBrightness = kDefaultMaxBrightness;
}
};
std::string BacklightDevice::getName() const {
return mName;
}
bool BacklightDevice::exists() const {
return std::ifstream(mBasePath + kBrightnessNode).good();
}
bool BacklightDevice::setBrightness(uint8_t value) {
return writeToFile(mBasePath + kBrightnessNode, scaleBrightness(value, mMaxBrightness));
}
void BacklightDevice::dump(int fd) const {
dprintf(fd, "Name: %s", mName.c_str());
dprintf(fd, ", exists: %d", exists());
dprintf(fd, ", base path: %s", mBasePath.c_str());
dprintf(fd, ", max brightness: %u", mMaxBrightness);
}
} // namespace light
} // namespace hardware
} // namespace android
} // namespace aidl