[apps][ion] Handle LED color concurrency between exam mode and charging

state
This commit is contained in:
Émilie Feral
2019-04-11 10:49:21 +02:00
parent 98ddca8321
commit 5dd0098981
7 changed files with 30 additions and 19 deletions

View File

@@ -145,20 +145,12 @@ void AppsContainer::suspend(bool checkIfPowerKeyReleased) {
window()->redraw(true);
}
void AppsContainer::updateLED() {
if (Ion::USB::isPlugged()) {
Ion::LED::setColor(Ion::Battery::isCharging() ? KDColorOrange : KDColorGreen);
} else {
Ion::LED::setColor(KDColorBlack);
}
}
bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
bool alphaLockWantsRedraw = updateAlphaLock();
bool didProcessEvent = false;
if (event == Ion::Events::USBEnumeration || event == Ion::Events::USBPlug || event == Ion::Events::BatteryCharging) {
updateLED();
Ion::LED::updateColorWithPlugAndCharge();
}
if (event == Ion::Events::USBEnumeration) {
if (Ion::USB::isPlugged()) {
@@ -172,7 +164,7 @@ bool AppsContainer::dispatchEvent(Ion::Events::Event event) {
if (switchTo(usbConnectedAppSnapshot())) {
Ion::USB::DFU();
// Update LED when exciting DFU mode
updateLED();
Ion::LED::updateColorWithPlugAndCharge();
bool switched = switchTo(activeSnapshot);
assert(switched);
(void) switched; // Silence compilation warning about unused variable.

View File

@@ -62,7 +62,6 @@ private:
bool processEvent(Ion::Events::Event event);
void resetShiftAlphaStatus();
bool updateAlphaLock();
void updateLED();
AppsWindow m_window;
EmptyBatteryWindow m_emptyBatteryWindow;

View File

@@ -63,6 +63,7 @@ ExamPopUpController::ContentView::ContentView(Responder * parentResponder) :
Ion::LED::setBlinking(1000, 0.1f);
} else {
Ion::LED::setColor(KDColorBlack);
Ion::LED::updateColorWithPlugAndCharge();
}
container->refreshPreferences();
container->activeApp()->dismissModalViewController();

View File

@@ -20,6 +20,7 @@ src += $(addprefix ion/src/shared/, \
crc32_padded.cpp \
decompress.cpp \
events.cpp \
led.cpp \
platform_info.cpp \
storage.cpp \
)

View File

@@ -10,6 +10,8 @@ KDColor getColor();
void setColor(KDColor c);
void setBlinking(uint16_t periodInMilliseconds, float dutyCycle);
KDColor updateColorWithPlugAndCharge();
}
}

View File

@@ -66,12 +66,6 @@ void sleepConfiguration() {
CORTEX.SCR()->setSLEEPDEEP(false);
}
KDColor updateLED() {
KDColor ledColor = USB::isPlugged() ? (Battery::isCharging() ? KDColorOrange : KDColorGreen) : KDColorBlack;
Ion::LED::setColor(ledColor);
return ledColor;
}
void suspend(bool checkIfPowerKeyReleased) {
bool isLEDActive = Ion::LED::getColor() != KDColorBlack;
bool plugged = USB::isPlugged();
@@ -94,7 +88,7 @@ void suspend(bool checkIfPowerKeyReleased) {
Device::Battery::initGPIO();
Device::USB::initGPIO();
Device::LED::init();
isLEDActive = updateLED() != KDColorBlack;
isLEDActive = LED::updateColorWithPlugAndCharge() != KDColorBlack;
// Configure low-power mode
if (isLEDActive) {
@@ -150,7 +144,7 @@ void suspend(bool checkIfPowerKeyReleased) {
Device::Board::initClocks();
Device::Board::initPeripherals();
// Update LED according to plug and charge state
updateLED();
LED::updateColorWithPlugAndCharge();
}
}

22
ion/src/shared/led.cpp Normal file
View File

@@ -0,0 +1,22 @@
#include <ion/led.h>
#include <ion/battery.h>
#include <ion/usb.h>
namespace Ion {
namespace LED {
KDColor updateColorWithPlugAndCharge() {
KDColor ledColor = getColor();
if (ledColor != KDColorRed) { // If exam mode is on, we do not update the LED with the plugged/charging state
if (USB::isPlugged()) {
ledColor = Battery::isCharging() ? KDColorOrange : KDColorGreen;
} else {
ledColor = KDColorBlack;
}
setColor(ledColor);
}
return ledColor;
}
}
}