2021-09-26 15:08:29 -04:00
|
|
|
/*
|
2024-04-18 11:34:39 -04:00
|
|
|
* Copyright (C) 2021-2024 The LineageOS Project
|
2021-09-26 15:08:29 -04:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2024-04-18 11:34:39 -04:00
|
|
|
#include <cstdint>
|
|
|
|
#include <fstream>
|
2021-09-26 15:08:29 -04:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace aidl {
|
|
|
|
namespace android {
|
|
|
|
namespace hardware {
|
|
|
|
namespace light {
|
|
|
|
|
2023-11-12 19:39:17 -05:00
|
|
|
struct rgb {
|
2024-04-18 11:34:39 -04:00
|
|
|
rgb();
|
|
|
|
rgb(uint8_t r, uint8_t g, uint8_t b);
|
2022-09-12 15:00:23 -04:00
|
|
|
rgb(uint32_t color);
|
|
|
|
|
2022-09-12 12:18:05 -04:00
|
|
|
uint8_t red;
|
|
|
|
uint8_t green;
|
|
|
|
uint8_t blue;
|
2022-09-12 15:00:23 -04:00
|
|
|
|
|
|
|
bool isLit();
|
|
|
|
uint8_t toBrightness();
|
2023-11-12 19:39:17 -05:00
|
|
|
};
|
2021-09-26 15:08:29 -04:00
|
|
|
|
2024-04-18 11:34:39 -04:00
|
|
|
uint32_t scaleBrightness(uint8_t brightness, uint32_t maxBrightness);
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool readFromFile(const std::string& file, T& content) {
|
|
|
|
std::ifstream fileStream(file);
|
|
|
|
|
|
|
|
if (!fileStream) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileStream >> content;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool writeToFile(const std::string& file, const T content) {
|
|
|
|
std::ofstream fileStream(file);
|
|
|
|
|
|
|
|
if (!fileStream) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fileStream << content;
|
|
|
|
return true;
|
|
|
|
}
|
2021-09-26 15:08:29 -04:00
|
|
|
|
2023-11-12 19:38:12 -05:00
|
|
|
} // namespace light
|
|
|
|
} // namespace hardware
|
|
|
|
} // namespace android
|
|
|
|
} // namespace aidl
|