This commit is contained in:
Max Hunt 2019-12-20 22:43:54 +00:00
parent 88b44de1ce
commit 06b7e5d84a

View File

@ -1,7 +1,11 @@
#include <MAX17043.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include "Arduino.h"
#include "LowPower.h"
#include <avr/wdt.h>
@ -123,6 +127,7 @@ void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.clearDisplay();
display.setTextColor(WHITE);
Wire.begin();
Serial.begin(9600);
pinMode(VBAT, INPUT);
pinMode(CSTAT1, INPUT);
@ -136,6 +141,11 @@ void setup() {
battVoltage = GetVoltage();
initScreen();
delay(200);
/*
FuelGauge.begin();
FuelGauge.reset(); //<== Might cause problems
FuelGauge.quickstart();
*/
}
void loop() {
@ -146,7 +156,7 @@ void loop() {
safetyCheck();
if (screenState != 0 && isSafe == true) {updateScreen();}
if (powerState == false && screenState == 0) {
LowPower.powerDown(SLEEP_2S, ADC_OFF, BOD_OFF);
LowPower.powerDown(SLEEP_1S, ADC_OFF, BOD_OFF);
}
}
@ -180,6 +190,10 @@ void getBatteryCharge(){
}
void _getBatteryCharge(){
batteryPct = FuelGauge.percent();
}
void checkPresses(){
if (digitalRead(PWRBTN) == 0) {
@ -328,6 +342,10 @@ double GetVoltage(){
}
}
double _GetVoltage(){
return (FuelGauge.voltage());
}
void safetyCheck(){
double currentVoltage = 0;
currentVoltage = GetVoltage();