mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[apps][ion] Handle LED color concurrency between exam mode and charging
state
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -62,7 +62,6 @@ private:
|
||||
bool processEvent(Ion::Events::Event event);
|
||||
void resetShiftAlphaStatus();
|
||||
bool updateAlphaLock();
|
||||
void updateLED();
|
||||
|
||||
AppsWindow m_window;
|
||||
EmptyBatteryWindow m_emptyBatteryWindow;
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -20,6 +20,7 @@ src += $(addprefix ion/src/shared/, \
|
||||
crc32_padded.cpp \
|
||||
decompress.cpp \
|
||||
events.cpp \
|
||||
led.cpp \
|
||||
platform_info.cpp \
|
||||
storage.cpp \
|
||||
)
|
||||
|
||||
@@ -10,6 +10,8 @@ KDColor getColor();
|
||||
void setColor(KDColor c);
|
||||
void setBlinking(uint16_t periodInMilliseconds, float dutyCycle);
|
||||
|
||||
KDColor updateColorWithPlugAndCharge();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
22
ion/src/shared/led.cpp
Normal 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user