Mirroring PR #537
This commit is contained in:
@@ -54,3 +54,5 @@ class HalGPIO {
|
|||||||
static constexpr uint8_t BTN_DOWN = 5;
|
static constexpr uint8_t BTN_DOWN = 5;
|
||||||
static constexpr uint8_t BTN_POWER = 6;
|
static constexpr uint8_t BTN_POWER = 6;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern HalGPIO gpio; // Singleton
|
||||||
|
|||||||
@@ -34,13 +34,36 @@ void drawBatteryIcon(const GfxRenderer& renderer, int x, int y, int battWidth, i
|
|||||||
renderer.drawPixel(x + battWidth - 1, y + rectHeight - 4);
|
renderer.drawPixel(x + battWidth - 1, y + rectHeight - 4);
|
||||||
renderer.drawLine(x + battWidth - 0, y + 4, x + battWidth - 0, y + rectHeight - 5);
|
renderer.drawLine(x + battWidth - 0, y + 4, x + battWidth - 0, y + rectHeight - 5);
|
||||||
|
|
||||||
|
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
|
||||||
int filledWidth = percentage * (battWidth - 5) / 100 + 1;
|
constexpr int maxFillWidth = battWidth - 5;
|
||||||
if (filledWidth > battWidth - 5) {
|
int filledWidth = percentage * maxFillWidth / 100 + 1;
|
||||||
filledWidth = battWidth - 5; // Ensure we don't overflow
|
if (filledWidth > maxFillWidth) {
|
||||||
|
filledWidth = maxFillWidth;
|
||||||
|
}
|
||||||
|
|
||||||
|
// When charging, ensure minimum fill so lightning bolt is fully visible
|
||||||
|
constexpr int minFillForBolt = 8;
|
||||||
|
if (charging && filledWidth < minFillForBolt) {
|
||||||
|
filledWidth = minFillForBolt;
|
||||||
}
|
}
|
||||||
|
|
||||||
renderer.fillRect(x + 2, y + 2, filledWidth, rectHeight - 4);
|
renderer.fillRect(x + 2, y + 2, filledWidth, rectHeight - 4);
|
||||||
|
|
||||||
|
// Draw lightning bolt when charging (white/inverted on black fill for visibility)
|
||||||
|
if (charging) {
|
||||||
|
const int boltX = x + 4;
|
||||||
|
const int boltY = y + 2;
|
||||||
|
renderer.drawLine(boltX + 4, boltY + 0, boltX + 5, boltY + 0, false);
|
||||||
|
renderer.drawLine(boltX + 3, boltY + 1, boltX + 4, boltY + 1, false);
|
||||||
|
renderer.drawLine(boltX + 2, boltY + 2, boltX + 5, boltY + 2, false);
|
||||||
|
renderer.drawLine(boltX + 3, boltY + 3, boltX + 4, boltY + 3, false);
|
||||||
|
renderer.drawLine(boltX + 2, boltY + 4, boltX + 3, boltY + 4, false);
|
||||||
|
renderer.drawLine(boltX + 1, boltY + 5, boltX + 4, boltY + 5, false);
|
||||||
|
renderer.drawLine(boltX + 2, boltY + 6, boltX + 3, boltY + 6, false);
|
||||||
|
renderer.drawLine(boltX + 1, boltY + 7, boltX + 2, boltY + 7, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user