aidl: light: Implement attention light type

Change-Id: Ia7fff2a4374ad4d05718909000dc2fd99b9264f0
This commit is contained in:
Sebastiano Barezzi 2023-11-13 01:48:16 +01:00
parent 69f546cc9b
commit 9cbf7b03e3
No known key found for this signature in database
GPG Key ID: 763BD3AE91A7A13F
2 changed files with 22 additions and 6 deletions

View File

@ -56,11 +56,11 @@ Lights::Lights() {
mLights.push_back(AutoHwLight(LightType::BATTERY));
mLights.push_back(AutoHwLight(LightType::NOTIFICATIONS));
mLights.push_back(AutoHwLight(LightType::ATTENTION));
}
ndk::ScopedAStatus Lights::setLightState(int32_t id, const HwLightState& state) {
rgb color(state.color);
rgb batteryStateColor;
LightType type = static_cast<LightType>(id);
switch (type) {
@ -72,14 +72,20 @@ ndk::ScopedAStatus Lights::setLightState(int32_t id, const HwLightState& state)
break;
case LightType::BATTERY:
case LightType::NOTIFICATIONS:
case LightType::ATTENTION:
mLEDMutex.lock();
if (type == LightType::BATTERY)
mLastBatteryState = state;
else
else if (type == LightType::NOTIFICATIONS)
mLastNotificationState = state;
batteryStateColor = rgb(mLastBatteryState.color);
setLED(batteryStateColor.isLit() ? mLastBatteryState : mLastNotificationState);
else if (type == LightType::ATTENTION)
mLastAttentionState = state;
setLED();
mLEDMutex.unlock();
break;
default:
return ndk::ScopedAStatus::fromExceptionCode(EX_UNSUPPORTED_OPERATION);
@ -95,8 +101,16 @@ ndk::ScopedAStatus Lights::getLights(std::vector<HwLight>* _aidl_return) {
return ndk::ScopedAStatus::ok();
}
void Lights::setLED(const HwLightState& state) {
void Lights::setLED() {
bool rc = true;
bool isBatteryLit = rgb(mLastBatteryState.color).isLit();
bool isAttentionLit = rgb(mLastAttentionState.color).isLit();
const HwLightState state = isBatteryLit ? mLastBatteryState
: isAttentionLit ? mLastAttentionState
: mLastNotificationState;
rgb color(state.color);
uint8_t blink = (state.flashOnMs != 0 && state.flashOffMs != 0);

View File

@ -26,7 +26,7 @@ class Lights : public BnLights {
ndk::ScopedAStatus getLights(std::vector<HwLight>* _aidl_return) override;
private:
void setLED(const HwLightState& state);
void setLED();
std::vector<HwLight> mLights;
@ -35,8 +35,10 @@ class Lights : public BnLights {
bool mWhiteLED;
std::mutex mLEDMutex;
HwLightState mLastBatteryState;
HwLightState mLastNotificationState;
HwLightState mLastAttentionState;
};
} // namespace light