hardware_xiaomi/aidl/light/LED.cpp
Sebastiano Barezzi 242aaad5c0 aidl: light: Set color and brightness data size to 8bit
* We're wasting memory

Change-Id: Ie66f504f32b487642c25b104240eaa8fb2df870c
2022-09-13 22:12:02 +05:30

40 lines
922 B
C++

/*
* Copyright (C) 2021-2022 The LineageOS Project
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "LED.h"
#include "Utils.h"
namespace aidl {
namespace android {
namespace hardware {
namespace light {
static const uint32_t kDefaultMaxLedBrightness = 255;
LED::LED(std::string type) : mBasePath("/sys/class/leds/" + type + "/") {
if (!readFromFile(mBasePath + "max_brightness", &mMaxBrightness))
mMaxBrightness = kDefaultMaxLedBrightness;
mBreath = fileWriteable(mBasePath + "breath");
}
bool LED::exists() {
return fileWriteable(mBasePath + "brightness");
}
bool LED::setBreath(uint8_t value) {
return writeToFile(mBasePath + (mBreath ? "breath" : "blink"), value);
}
bool LED::setBrightness(uint8_t value) {
return writeToFile(mBasePath + "brightness", value * mMaxBrightness / 0xFF);
}
} // namespace light
} // namespace hardware
} // namespace android
} // namespace aidl