aidl: light: Reformat with clang-format
Change-Id: Iee8f2dc3777a95df827f33ad1f4e37f7d0f48eed
This commit is contained in:
parent
5981d19419
commit
2154cee0ec
@ -14,7 +14,7 @@ namespace hardware {
|
||||
namespace light {
|
||||
|
||||
class BacklightBrightness : public BacklightDevice {
|
||||
public:
|
||||
public:
|
||||
BacklightBrightness(std::string name) : mBasePath(mkBacklightBasePath + name + "/") {
|
||||
if (!readFromFile(mBasePath + "max_brightness", &mMaxBrightness)) {
|
||||
mMaxBrightness = kDefaultMaxBrightness;
|
||||
@ -25,10 +25,9 @@ public:
|
||||
writeToFile(mBasePath + "brightness", value * mMaxBrightness / 0xFF);
|
||||
}
|
||||
|
||||
bool exists() {
|
||||
return fileWriteable(mBasePath + "brightness");
|
||||
}
|
||||
private:
|
||||
bool exists() { return fileWriteable(mBasePath + "brightness"); }
|
||||
|
||||
private:
|
||||
std::string mBasePath;
|
||||
uint32_t mMaxBrightness;
|
||||
|
||||
@ -37,31 +36,28 @@ private:
|
||||
};
|
||||
|
||||
class LEDBacklight : public BacklightDevice {
|
||||
public:
|
||||
LEDBacklight(std::string type) : mLED(type) {};
|
||||
public:
|
||||
LEDBacklight(std::string type) : mLED(type){};
|
||||
|
||||
void setBacklight(uint8_t value) {
|
||||
mLED.setBrightness(value);
|
||||
}
|
||||
void setBacklight(uint8_t value) { mLED.setBrightness(value); }
|
||||
|
||||
bool exists() {
|
||||
return mLED.exists();
|
||||
}
|
||||
private:
|
||||
bool exists() { return mLED.exists(); }
|
||||
|
||||
private:
|
||||
LED mLED;
|
||||
};
|
||||
|
||||
static const std::string kBacklightDevices[] = {
|
||||
"backlight",
|
||||
"panel0-backlight",
|
||||
"backlight",
|
||||
"panel0-backlight",
|
||||
};
|
||||
|
||||
static const std::string kLedDevices[] = {
|
||||
"lcd-backlight",
|
||||
"lcd-backlight",
|
||||
};
|
||||
|
||||
BacklightDevice *getBacklightDevice() {
|
||||
for (auto &device : kBacklightDevices) {
|
||||
BacklightDevice* getBacklightDevice() {
|
||||
for (auto& device : kBacklightDevices) {
|
||||
auto backlight = new BacklightBrightness(device);
|
||||
if (backlight->exists()) {
|
||||
return backlight;
|
||||
@ -80,7 +76,7 @@ BacklightDevice *getBacklightDevice() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
@ -12,16 +12,16 @@ namespace hardware {
|
||||
namespace light {
|
||||
|
||||
class BacklightDevice {
|
||||
public:
|
||||
public:
|
||||
virtual ~BacklightDevice() = default;
|
||||
|
||||
virtual void setBacklight(uint8_t value) = 0;
|
||||
virtual bool exists() = 0;
|
||||
};
|
||||
|
||||
BacklightDevice *getBacklightDevice();
|
||||
BacklightDevice* getBacklightDevice();
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
@ -33,7 +33,7 @@ bool LED::setBrightness(uint8_t value) {
|
||||
return writeToFile(mBasePath + "brightness", value * mMaxBrightness / 0xFF);
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
@ -14,19 +14,20 @@ namespace hardware {
|
||||
namespace light {
|
||||
|
||||
class LED {
|
||||
public:
|
||||
public:
|
||||
LED(std::string type);
|
||||
|
||||
bool exists();
|
||||
bool setBreath(uint8_t value);
|
||||
bool setBrightness(uint8_t value);
|
||||
private:
|
||||
|
||||
private:
|
||||
std::string mBasePath;
|
||||
uint32_t mMaxBrightness;
|
||||
bool mBreath;
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
@ -16,8 +16,8 @@ namespace hardware {
|
||||
namespace light {
|
||||
|
||||
static const std::string kAllButtonsPaths[] = {
|
||||
"/sys/class/leds/button-backlight/brightness",
|
||||
"/sys/class/leds/button-backlight1/brightness",
|
||||
"/sys/class/leds/button-backlight/brightness",
|
||||
"/sys/class/leds/button-backlight1/brightness",
|
||||
};
|
||||
|
||||
enum led_type {
|
||||
@ -29,13 +29,14 @@ enum led_type {
|
||||
};
|
||||
|
||||
static LED kLEDs[MAX_LEDS] = {
|
||||
[RED] = LED("red"),
|
||||
[GREEN] = LED("green"),
|
||||
[BLUE] = LED("blue"),
|
||||
[WHITE] = LED("white"),
|
||||
[RED] = LED("red"),
|
||||
[GREEN] = LED("green"),
|
||||
[BLUE] = LED("blue"),
|
||||
[WHITE] = LED("white"),
|
||||
};
|
||||
|
||||
#define AutoHwLight(light) {.id = (int32_t)light, .type = light, .ordinal = 0}
|
||||
#define AutoHwLight(light) \
|
||||
{ .id = (int32_t)light, .type = light, .ordinal = 0 }
|
||||
|
||||
Lights::Lights() {
|
||||
mBacklightDevice = getBacklightDevice();
|
||||
@ -44,14 +45,12 @@ Lights::Lights() {
|
||||
}
|
||||
|
||||
for (auto& buttons : kAllButtonsPaths) {
|
||||
if (!fileWriteable(buttons))
|
||||
continue;
|
||||
if (!fileWriteable(buttons)) continue;
|
||||
|
||||
mButtonsPaths.push_back(buttons);
|
||||
}
|
||||
|
||||
if (!mButtonsPaths.empty())
|
||||
mLights.push_back(AutoHwLight(LightType::BUTTONS));
|
||||
if (!mButtonsPaths.empty()) mLights.push_back(AutoHwLight(LightType::BUTTONS));
|
||||
|
||||
mWhiteLED = kLEDs[WHITE].exists();
|
||||
|
||||
@ -66,12 +65,10 @@ ndk::ScopedAStatus Lights::setLightState(int32_t id, const HwLightState& state)
|
||||
LightType type = static_cast<LightType>(id);
|
||||
switch (type) {
|
||||
case LightType::BACKLIGHT:
|
||||
if (mBacklightDevice)
|
||||
mBacklightDevice->setBacklight(color.toBrightness());
|
||||
if (mBacklightDevice) mBacklightDevice->setBacklight(color.toBrightness());
|
||||
break;
|
||||
case LightType::BUTTONS:
|
||||
for (auto& buttons : mButtonsPaths)
|
||||
writeToFile(buttons, color.isLit());
|
||||
for (auto& buttons : mButtonsPaths) writeToFile(buttons, color.isLit());
|
||||
break;
|
||||
case LightType::BATTERY:
|
||||
case LightType::NOTIFICATIONS:
|
||||
@ -92,9 +89,8 @@ ndk::ScopedAStatus Lights::setLightState(int32_t id, const HwLightState& state)
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
|
||||
ndk::ScopedAStatus Lights::getLights(std::vector<HwLight> *_aidl_return) {
|
||||
for (const auto& light : mLights)
|
||||
_aidl_return->push_back(light);
|
||||
ndk::ScopedAStatus Lights::getLights(std::vector<HwLight>* _aidl_return) {
|
||||
for (const auto& light : mLights) _aidl_return->push_back(light);
|
||||
|
||||
return ndk::ScopedAStatus::ok();
|
||||
}
|
||||
@ -114,8 +110,7 @@ void Lights::setLED(const HwLightState& state) {
|
||||
rc &= kLEDs[GREEN].setBreath(blink && color.green);
|
||||
rc &= kLEDs[BLUE].setBreath(blink && color.blue);
|
||||
}
|
||||
if (rc)
|
||||
break;
|
||||
if (rc) break;
|
||||
FALLTHROUGH_INTENDED;
|
||||
default:
|
||||
if (mWhiteLED) {
|
||||
@ -131,7 +126,7 @@ void Lights::setLED(const HwLightState& state) {
|
||||
return;
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
@ -10,8 +10,8 @@
|
||||
#include <mutex>
|
||||
#include "Backlight.h"
|
||||
|
||||
using ::aidl::android::hardware::light::HwLightState;
|
||||
using ::aidl::android::hardware::light::HwLight;
|
||||
using ::aidl::android::hardware::light::HwLightState;
|
||||
|
||||
namespace aidl {
|
||||
namespace android {
|
||||
@ -19,17 +19,18 @@ namespace hardware {
|
||||
namespace light {
|
||||
|
||||
class Lights : public BnLights {
|
||||
public:
|
||||
public:
|
||||
Lights();
|
||||
|
||||
ndk::ScopedAStatus setLightState(int32_t id, const HwLightState& state) override;
|
||||
ndk::ScopedAStatus getLights(std::vector<HwLight> *_aidl_return) override;
|
||||
private:
|
||||
ndk::ScopedAStatus getLights(std::vector<HwLight>* _aidl_return) override;
|
||||
|
||||
private:
|
||||
void setLED(const HwLightState& state);
|
||||
|
||||
std::vector<HwLight> mLights;
|
||||
|
||||
BacklightDevice *mBacklightDevice;
|
||||
BacklightDevice* mBacklightDevice;
|
||||
std::vector<std::string> mButtonsPaths;
|
||||
bool mWhiteLED;
|
||||
|
||||
@ -38,7 +39,7 @@ private:
|
||||
HwLightState mLastNotificationState;
|
||||
};
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
@ -24,11 +24,11 @@ bool fileWriteable(const std::string& file) {
|
||||
return !access(file.c_str(), W_OK);
|
||||
}
|
||||
|
||||
bool readFromFile(const std::string& file, std::string *content) {
|
||||
bool readFromFile(const std::string& file, std::string* content) {
|
||||
return ReadFileToString(file, content, true);
|
||||
}
|
||||
|
||||
bool readFromFile(const std::string& file, uint32_t *content) {
|
||||
bool readFromFile(const std::string& file, uint32_t* content) {
|
||||
std::string content_str;
|
||||
if (readFromFile(file, &content_str))
|
||||
*content = std::stoi(content_str);
|
||||
@ -70,7 +70,7 @@ uint8_t rgb::toBrightness() {
|
||||
return (77 * red + 150 * green + 29 * blue) >> 8;
|
||||
}
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
@ -14,9 +14,9 @@ namespace hardware {
|
||||
namespace light {
|
||||
|
||||
typedef struct rgb {
|
||||
rgb(uint8_t r, uint8_t g, uint8_t b) : red(r), green(g), blue(b) {};
|
||||
rgb(uint8_t r, uint8_t g, uint8_t b) : red(r), green(g), blue(b){};
|
||||
rgb(uint32_t color);
|
||||
rgb() : red(0), green(0), blue(0) {};
|
||||
rgb() : red(0), green(0), blue(0){};
|
||||
|
||||
uint8_t red;
|
||||
uint8_t green;
|
||||
@ -27,11 +27,11 @@ typedef struct rgb {
|
||||
} rgb_t;
|
||||
|
||||
bool fileWriteable(const std::string& file);
|
||||
bool readFromFile(const std::string& file, std::string *content);
|
||||
bool readFromFile(const std::string& file, uint32_t *content);
|
||||
bool readFromFile(const std::string& file, std::string* content);
|
||||
bool readFromFile(const std::string& file, uint32_t* content);
|
||||
bool writeToFile(const std::string& file, uint32_t content);
|
||||
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
} // namespace light
|
||||
} // namespace hardware
|
||||
} // namespace android
|
||||
} // namespace aidl
|
||||
|
@ -6,9 +6,9 @@
|
||||
|
||||
#include "Lights.h"
|
||||
|
||||
#include <android-base/logging.h>
|
||||
#include <android/binder_manager.h>
|
||||
#include <android/binder_process.h>
|
||||
#include <android-base/logging.h>
|
||||
|
||||
using ::aidl::android::hardware::light::Lights;
|
||||
|
||||
@ -21,5 +21,5 @@ int main() {
|
||||
CHECK(status == STATUS_OK);
|
||||
|
||||
ABinderProcess_joinThreadPool();
|
||||
return EXIT_FAILURE; // should not reach
|
||||
return EXIT_FAILURE; // should not reach
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user