/*

   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);
}
