96 lines
3.3 KiB
C++
96 lines
3.3 KiB
C++
// the setup function runs once when you press reset or power the board
|
|
|
|
#include "upsIO.h"
|
|
#include "upsSvr.h"
|
|
|
|
bool printDebug = true;
|
|
|
|
bool inOk = false;
|
|
int16_t adc = 0;
|
|
float voltage = 0;
|
|
uint32_t infoTick = 0;
|
|
|
|
void setup() {
|
|
// initialize digital pin LED_BUILTIN as an output.
|
|
Serial.begin(115200);
|
|
Serial.println();
|
|
//ESP.wdtDisable();
|
|
|
|
//initUpsIo(true);
|
|
initUpsIo();
|
|
//initUpsIo(false, true);
|
|
|
|
upsServerInit();
|
|
|
|
//CharliplexDemoRoutine();
|
|
}
|
|
|
|
// the loop function runs over and over again forever
|
|
void loop() {
|
|
if (printDebug && (millis()-infoTick>=500)){
|
|
infoTick = millis();
|
|
adc = analogRead(A0);//ioAdc;//analogRead(A0);//ioAdc;//
|
|
//voltage = (16.0*((float)adc / 1024)) * 0.983; //use 1.5 MOhm series resistor
|
|
voltage = (16.0*((float)adc / 1024)) * 1.0; //use 1.5 MOhm series resistor
|
|
Serial.println("VBatt: " + (String(voltage, 2)) + " V");
|
|
|
|
//adc = ioAdcFiltered;
|
|
voltage = batteryVoltageUnfiltered;//(16.0*((float)adc / 1024)) * 1.0; //use 1.5 MOhm series resistor
|
|
Serial.println("VBatt (Sub-Min): " + (String(voltage, 2)) + " V");
|
|
|
|
//adc = adcValueMin;
|
|
voltage = batteryVoltage;//(16.0*((float)adc / 1024)) * 1.0; //use 1.5 MOhm series resistor
|
|
Serial.print("VBatt (Min): " + (String(voltage, 2)) + " V");
|
|
Serial.print(" (" + (String(batteryPercentage)) + "%)");
|
|
Serial.println(", LV: " + (String(batteryLevel)));
|
|
|
|
|
|
Serial.println("Charge Error: " + (String(chargeError)));
|
|
Serial.println("Charge Switch: " + (String(isChargeActive)));
|
|
Serial.println("Input Under Voltage: " + (String(inputUnderVoltage)));
|
|
Serial.println("Input Voltage Exists: " + (String(inputVoltageKeepup)));
|
|
|
|
//inOk = digitalRead(pinInputSense);
|
|
//Serial.println("Vin: " + (String)(inOk?"True":"False"));
|
|
|
|
//buttonState = !digitalRead(pinInputButton); //inverted
|
|
Serial.println("Button: " + (String)(buttonState?"True":"False"));
|
|
Serial.println("Button (short): " + (String)(buttonShortPress?"True":"False"));
|
|
Serial.println("Button (long): " + (String)(buttonLongPress?"True":"False"));
|
|
|
|
Serial.println("Power OUT: " + (String)(powerOutputActive?"True":"False"));
|
|
//digitalWrite(pinLed, HIGH); // turn the LED on (HIGH is the voltage level)
|
|
//digitalWrite(pinPowerOut, HIGH);
|
|
|
|
Serial.println("KEEP POWER: " + (String)(keepPowerState?"True":"False"));
|
|
|
|
Serial.println("Display: " + (String)(displayActive?"True":"False"));
|
|
|
|
Serial.println("RSSI: " + (String)(rssi));
|
|
|
|
Serial.println("Charge Allowed: " + (String)(chargeAllowed?"True":"False"));
|
|
|
|
//for persistent shutdown demo: ==============================================================
|
|
// if (persistentShutdown){
|
|
// Serial.println("Shutdown in: " + (String)(getPersistentShutdownTick()/1000000));
|
|
// }else{
|
|
// if (restartAutoPowerOn()) Serial.println("Automatic ON restarted");
|
|
// setPersistentShutdown(10000000UL);
|
|
// }
|
|
//============================================================================================
|
|
}
|
|
|
|
upsServerRoutine();
|
|
|
|
upsRoutineInterrupt();
|
|
|
|
//delay(2000); // wait for a second
|
|
//digitalWrite(pinLed, LOW); // turn the LED off by making the voltage LOW
|
|
//digitalWrite(pinPowerOut, LOW);
|
|
|
|
|
|
//CharlieplexDemoRoutine();
|
|
//UpsIoRoutine();
|
|
|
|
}
|