@@ -13,12 +13,20 @@ namespace m5avatar {
1313
1414class BatteryIcon final : public Drawable {
1515 private:
16- void drawBatteryIcon (M5Canvas *spi, uint32_t x, uint32_t y, uint16_t fgcolor, uint16_t bgcolor, float offset, int32_t batteryLevel) {
16+ void drawBatteryIcon (M5Canvas *spi, uint32_t x, uint32_t y, uint16_t fgcolor, uint16_t bgcolor, float offset, BatteryIconStatus batteryIconStatus, int32_t batteryLevel) {
1717 spi->drawRect (x, y + 5 , 5 , 5 , fgcolor);
1818 spi->drawRect (x + 5 , y, 30 , 15 , fgcolor);
1919 int battery_width = 30 * (float )(batteryLevel / 100 .0f );
2020 spi->fillRect (x + 5 + 30 - battery_width, y, battery_width, 15 , fgcolor);
21- }
21+ if (batteryIconStatus == BatteryIconStatus::isCharging) {
22+ spi->fillTriangle (x + 20 , y, x + 15 , y + 8 , x + 20 , y + 8 , bgcolor);
23+ spi->fillTriangle (x + 18 , y + 7 , x + 18 , y + 15 , x + 23 , y + 7 , bgcolor);
24+ spi->drawLine (x + 20 , y, x + 15 , y + 8 , fgcolor);
25+ spi->drawLine (x + 20 , y, x + 20 , y + 7 , fgcolor);
26+ spi->drawLine (x + 18 , y + 15 , x + 23 , y + 7 , fgcolor);
27+ spi->drawLine (x + 18 , y + 8 , x + 18 , y + 15 , fgcolor);
28+ }
29+ }
2230
2331 public:
2432 // constructor
@@ -27,12 +35,12 @@ class BatteryIcon final : public Drawable {
2735 BatteryIcon (const BatteryIcon &other) = default ;
2836 BatteryIcon &operator =(const BatteryIcon &other) = default ;
2937 void draw (M5Canvas *spi, BoundingRect rect, DrawContext *ctx) override {
30- if (ctx->getBatteryIcon () ) {
38+ if (ctx->getBatteryIconStatus () != BatteryIconStatus::invisible ) {
3139 uint16_t primaryColor = ctx->getColorDepth () == 1 ? 1 : ctx->getColorPalette ()->get (COLOR_PRIMARY );
3240 uint16_t bgColor = ctx->getColorDepth () == 1 ? ERACER_COLOR : ctx->getColorPalette ()->get (COLOR_BACKGROUND );
3341 float offset = ctx->getBreath ();
3442 int32_t batteryLevel = ctx->getBatteryLevel ();
35- drawBatteryIcon (spi, 285 , 5 , primaryColor, bgColor, -offset, batteryLevel);
43+ drawBatteryIcon (spi, 285 , 5 , primaryColor, bgColor, -offset, ctx-> getBatteryIconStatus (), batteryLevel);
3644 }
3745 };
3846
0 commit comments