hardware_xiaomi/aidl/light/LED.cpp
Sebastiano Barezzi 2154cee0ec
aidl: light: Reformat with clang-format
Change-Id: Iee8f2dc3777a95df827f33ad1f4e37f7d0f48eed
2023-11-13 01:39:53 +01:00

40 lines
926 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