Merge branch 'feat-charger' of https://github.com/jpirnay/crosspoint-reader into mybuild
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;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <HalStorage.h>
|
#include <HalStorage.h>
|
||||||
#include <Logging.h>
|
#include <Logging.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
@@ -37,7 +38,11 @@ void drawBatteryIcon(const GfxRenderer& renderer, int x, int y, int battWidth, i
|
|||||||
const bool charging = gpio.isUsbConnected();
|
const bool charging = gpio.isUsbConnected();
|
||||||
|
|
||||||
// The +1 is to round up, so that we always fill at least one pixel
|
// The +1 is to round up, so that we always fill at least one pixel
|
||||||
constexpr int maxFillWidth = battWidth - 5;
|
const int maxFillWidth = battWidth - 5;
|
||||||
|
const int fillHeight = rectHeight - 4;
|
||||||
|
if (maxFillWidth <= 0 || fillHeight <= 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
int filledWidth = percentage * maxFillWidth / 100 + 1;
|
int filledWidth = percentage * maxFillWidth / 100 + 1;
|
||||||
if (filledWidth > maxFillWidth) {
|
if (filledWidth > maxFillWidth) {
|
||||||
filledWidth = maxFillWidth;
|
filledWidth = maxFillWidth;
|
||||||
@@ -46,10 +51,10 @@ void drawBatteryIcon(const GfxRenderer& renderer, int x, int y, int battWidth, i
|
|||||||
// When charging, ensure minimum fill so lightning bolt is fully visible
|
// When charging, ensure minimum fill so lightning bolt is fully visible
|
||||||
constexpr int minFillForBolt = 8;
|
constexpr int minFillForBolt = 8;
|
||||||
if (charging && filledWidth < minFillForBolt) {
|
if (charging && filledWidth < minFillForBolt) {
|
||||||
filledWidth = minFillForBolt;
|
filledWidth = std::min(minFillForBolt, maxFillWidth);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.fillRect(x + 2, y + 2, filledWidth, rectHeight - 4);
|
renderer.fillRect(x + 2, y + 2, filledWidth, fillHeight);
|
||||||
|
|
||||||
// Draw lightning bolt when charging (white/inverted on black fill for visibility)
|
// Draw lightning bolt when charging (white/inverted on black fill for visibility)
|
||||||
if (charging) {
|
if (charging) {
|
||||||
|
|||||||
@@ -379,6 +379,12 @@ void loop() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Refresh the battery icon when USB is plugged or unplugged.
|
||||||
|
// Placed after sleep guards so we never queue a render that won't be processed.
|
||||||
|
if (gpio.wasUsbStateChanged()) {
|
||||||
|
activityManager.requestUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
const unsigned long activityStartTime = millis();
|
const unsigned long activityStartTime = millis();
|
||||||
activityManager.loop();
|
activityManager.loop();
|
||||||
const unsigned long activityDuration = millis() - activityStartTime;
|
const unsigned long activityDuration = millis() - activityStartTime;
|
||||||
|
|||||||
Reference in New Issue
Block a user