## Summary * **What is the goal of this PR?** All praise goes to @didacta for his PR #537. Just picked up the reviewer comments to contain the changes as suggested (there was no response for more than 6 weeks, so I wanted to reanimate this feature). Just one addition: should recognize usb cable plug ins / retractions and update the icon immediately * **What changes are included?** ## Additional Context see #537 --- ### AI Usage While CrossPoint doesn't have restrictions on AI tools in contributing, please be transparent about their usage as it helps set the right context for reviewers. Did you use AI tools to help write this code? _**< NO >**_
This commit is contained in:
@@ -7,7 +7,14 @@ void HalGPIO::begin() {
|
||||
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); }
|
||||
|
||||
|
||||
@@ -23,6 +23,9 @@ class HalGPIO {
|
||||
InputManager inputMgr;
|
||||
#endif
|
||||
|
||||
bool lastUsbConnected = false;
|
||||
bool usbStateChanged = false;
|
||||
|
||||
public:
|
||||
HalGPIO() = default;
|
||||
|
||||
@@ -41,6 +44,9 @@ class HalGPIO {
|
||||
// Check if USB is connected
|
||||
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 };
|
||||
|
||||
WakeupReason getWakeupReason() const;
|
||||
@@ -54,3 +60,5 @@ class HalGPIO {
|
||||
static constexpr uint8_t BTN_DOWN = 5;
|
||||
static constexpr uint8_t BTN_POWER = 6;
|
||||
};
|
||||
|
||||
extern HalGPIO gpio; // Singleton
|
||||
|
||||
Reference in New Issue
Block a user