Browse Source

added battery indicator wip

Toby Chui 1 year ago
parent
commit
725299fd95
3 changed files with 46 additions and 2 deletions
  1. 2 2
      InkyDash/InkyDash.ino
  2. 43 0
      InkyDash/battery.ino
  3. 1 0
      InkyDash/draw.ino

+ 2 - 2
InkyDash/InkyDash.ino

@@ -1,12 +1,11 @@
 /*
     InkyDash
 
-    An ESP8266 powered version of InkyCal project
+    An ESP8266 powered version of InkyCal like project
     for low power desktop dashboard
 
     Author: tobychui
 
-
 */
 
 /* Pin Mappings */
@@ -122,6 +121,7 @@ float currentHumd = 50.0;
 float currentRain = 0.0;
 float maxTemp = 0.0;
 float minTemp = 0.0;
+int batRemain = 20; //In percentage
 
 /* Schedulers */
 void datetimeUpdateCallback();

+ 43 - 0
InkyDash/battery.ino

@@ -0,0 +1,43 @@
+/*
+
+   Battery.ino
+
+   Renders the battery information
+   on screen
+
+*/
+
+//Update the battery reading from ADC pin
+void updateBatteryReading(){
+  batRemain = 80;
+}
+
+//Draw the battery icon at the bottom right hand corner
+void drawBatteryIcon() {
+  updateBatteryReading();
+  
+  //Draw the battery icon
+  uint16_t barColor = GxEPD_BLACK;
+  if (batRemain <= 20){
+    barColor = GxEPD_RED;
+  }
+  int iconBaseX = display.width() - 50;
+  int iconBaseY = display.height() - 26;
+  display.drawRoundRect(iconBaseX, iconBaseY, 40, 20, 3, GxEPD_BLACK);
+  display.fillRoundRect(iconBaseX + 40, iconBaseY + 5, 4, 10, 3, GxEPD_BLACK);
+  //Internal bar
+  int maxBarWidth = 36;
+  int barWidth = int(float(batRemain)/100.0 * maxBarWidth);
+  display.fillRoundRect(iconBaseX + 2, iconBaseY + 2, barWidth, 16, 3, barColor);
+
+  //Draw percentage
+  int16_t tbx, tby; uint16_t tbw, tbh;
+  display.setFont(&FreeSans9pt7b);
+  display.setTextSize(0.5);
+  String batInfo = String(batRemain) + "%";
+  display.getTextBounds(batInfo, 0, 0, &tbx, &tby, &tbw, &tbh);
+  display.setCursor(iconBaseX - tbw - 6, iconBaseY + tbh + 2);
+  display.setTextColor(GxEPD_BLACK);
+  display.print(batInfo);
+  display.setTextSize(1);
+}

+ 1 - 0
InkyDash/draw.ino

@@ -17,6 +17,7 @@ void drawHomeFrame() {
   drawDayProgressBar(200, 10, GxEPD_BLACK);
   drawCalender(250);
   drawLastUpdateTimestamp();
+  drawBatteryIcon();
 }
 
 //Draw a timestamp at the corner to show the last update time