Add immediate response for usb cable plug in / removal
This commit is contained in:
+8
-1
@@ -7,7 +7,14 @@ void HalGPIO::begin() {
|
|||||||
pinMode(UART0_RXD, INPUT);
|
pinMode(UART0_RXD, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HalGPIO::update() { inputMgr.update(); }
|
void HalGPIO::update() {
|
||||||
|
inputMgr.update();
|
||||||
|
const bool connected = isUsbConnected();
|
||||||
|
usbStateChanged = (connected != lastUsbConnected);
|
||||||
|
lastUsbConnected = connected;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HalGPIO::wasUsbStateChanged() const { return usbStateChanged; }
|
||||||
|
|
||||||
bool HalGPIO::isPressed(uint8_t buttonIndex) const { return inputMgr.isPressed(buttonIndex); }
|
bool HalGPIO::isPressed(uint8_t buttonIndex) const { return inputMgr.isPressed(buttonIndex); }
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ class HalGPIO {
|
|||||||
InputManager inputMgr;
|
InputManager inputMgr;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool lastUsbConnected = false;
|
||||||
|
bool usbStateChanged = false;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HalGPIO() = default;
|
HalGPIO() = default;
|
||||||
|
|
||||||
@@ -41,6 +44,9 @@ class HalGPIO {
|
|||||||
// Check if USB is connected
|
// Check if USB is connected
|
||||||
bool isUsbConnected() const;
|
bool isUsbConnected() const;
|
||||||
|
|
||||||
|
// Returns true once per edge (plug or unplug) since the last update()
|
||||||
|
bool wasUsbStateChanged() const;
|
||||||
|
|
||||||
enum class WakeupReason { PowerButton, AfterFlash, AfterUSBPower, Other };
|
enum class WakeupReason { PowerButton, AfterFlash, AfterUSBPower, Other };
|
||||||
|
|
||||||
WakeupReason getWakeupReason() const;
|
WakeupReason getWakeupReason() const;
|
||||||
|
|||||||
@@ -347,6 +347,11 @@ void loop() {
|
|||||||
powerManager.setPowerSaving(false); // Restore normal CPU frequency on user activity
|
powerManager.setPowerSaving(false); // Restore normal CPU frequency on user activity
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refresh the battery icon immediately when USB is plugged or unplugged
|
||||||
|
if (gpio.wasUsbStateChanged()) {
|
||||||
|
activityManager.requestUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
static bool screenshotButtonsReleased = true;
|
static bool screenshotButtonsReleased = true;
|
||||||
if (gpio.isPressed(HalGPIO::BTN_POWER) && gpio.isPressed(HalGPIO::BTN_DOWN)) {
|
if (gpio.isPressed(HalGPIO::BTN_POWER) && gpio.isPressed(HalGPIO::BTN_DOWN)) {
|
||||||
if (screenshotButtonsReleased) {
|
if (screenshotButtonsReleased) {
|
||||||
|
|||||||
Reference in New Issue
Block a user