Added Battery Monitoring
This commit is contained in:
parent
49260c0db5
commit
6bc0e394ac
@ -22,6 +22,8 @@
|
|||||||
<h3>
|
<h3>
|
||||||
%TITLE%
|
%TITLE%
|
||||||
</h3>
|
</h3>
|
||||||
|
<p>Battery Voltage: %BATTERY_VOLTAGE% V</p>
|
||||||
|
<p>Battery Level: %BATTERY_LEVEL% %</p>
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -9,6 +9,11 @@
|
|||||||
#define WIFI_PASS "CaptureTheFlag"
|
#define WIFI_PASS "CaptureTheFlag"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef BAT_LOW_PERCENT
|
||||||
|
#define BAT_LOW_PERCENT 10
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef FACTION_1_NAME
|
#ifndef FACTION_1_NAME
|
||||||
#define FACTION_1_NAME "Team A"
|
#define FACTION_1_NAME "Team A"
|
||||||
#endif
|
#endif
|
||||||
|
39
src/main.cpp
39
src/main.cpp
@ -70,6 +70,12 @@ uint8_t Faction_1_dot = 0;
|
|||||||
uint8_t Faction_2_dot = 0;
|
uint8_t Faction_2_dot = 0;
|
||||||
uint8_t Faction_3_dot = 0;
|
uint8_t Faction_3_dot = 0;
|
||||||
|
|
||||||
|
float loadvoltage = 0;
|
||||||
|
int battery_level = 0;
|
||||||
|
|
||||||
|
const uint8_t sevenSeg_bat[] = {0x00, 0b01111100, 0b01110111, 0b01111000};
|
||||||
|
const uint8_t sevenSeg_low[] = {0b00111000, 0b01011100, 0x00, 0x00};
|
||||||
|
|
||||||
String processor(const String &var)
|
String processor(const String &var)
|
||||||
{
|
{
|
||||||
char buffer[16] = {0};
|
char buffer[16] = {0};
|
||||||
@ -104,6 +110,16 @@ String processor(const String &var)
|
|||||||
if (var == "TITLE")
|
if (var == "TITLE")
|
||||||
return WIFI_SSID;
|
return WIFI_SSID;
|
||||||
|
|
||||||
|
if (var == "BATTERY_LEVEL")
|
||||||
|
{
|
||||||
|
sprintf(buffer, "%d", battery_level);
|
||||||
|
return String(buffer);
|
||||||
|
}
|
||||||
|
if (var == "BATTERY_VOLTAGE")
|
||||||
|
{
|
||||||
|
sprintf(buffer, "%f", loadvoltage);
|
||||||
|
return String(buffer);
|
||||||
|
}
|
||||||
return String(buffer);
|
return String(buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -209,6 +225,21 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
void SevenSeg_Output()
|
void SevenSeg_Output()
|
||||||
|
{
|
||||||
|
if (battery_level < BAT_LOW_PERCENT)
|
||||||
|
{
|
||||||
|
disp_FAC_1.setBrightness(0);
|
||||||
|
disp_FAC_2.setBrightness(0);
|
||||||
|
disp_FAC_3.setBrightness(0);
|
||||||
|
|
||||||
|
disp_FAC_3.setSegments(sevenSeg_bat);
|
||||||
|
disp_FAC_2.setSegments(sevenSeg_low);
|
||||||
|
if (millis() % 5000 > 2500)
|
||||||
|
disp_FAC_1.showNumberDec(battery_level);
|
||||||
|
else
|
||||||
|
disp_FAC_1.showNumberDecEx(loadvoltage * 100, 0x40);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
disp_FAC_1.setBrightness(activeFaction == FACTION_1 ? 7 : 0);
|
disp_FAC_1.setBrightness(activeFaction == FACTION_1 ? 7 : 0);
|
||||||
disp_FAC_2.setBrightness(activeFaction == FACTION_2 ? 7 : 0);
|
disp_FAC_2.setBrightness(activeFaction == FACTION_2 ? 7 : 0);
|
||||||
@ -284,10 +315,12 @@ void inputGetterTicker_callback()
|
|||||||
|
|
||||||
void powerMonitorTicker_callback()
|
void powerMonitorTicker_callback()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// loadvoltage and percentage is global, because of battery Monitoring
|
||||||
|
|
||||||
float shuntvoltage = 0;
|
float shuntvoltage = 0;
|
||||||
float busvoltage = 0;
|
|
||||||
float current_mA = 0;
|
float current_mA = 0;
|
||||||
float loadvoltage = 0;
|
float busvoltage = 0;
|
||||||
float power_mW = 0;
|
float power_mW = 0;
|
||||||
|
|
||||||
shuntvoltage = ina219.getShuntVoltage_mV();
|
shuntvoltage = ina219.getShuntVoltage_mV();
|
||||||
@ -295,7 +328,9 @@ void powerMonitorTicker_callback()
|
|||||||
current_mA = ina219.getCurrent_mA();
|
current_mA = ina219.getCurrent_mA();
|
||||||
power_mW = ina219.getPower_mW();
|
power_mW = ina219.getPower_mW();
|
||||||
loadvoltage = busvoltage + (shuntvoltage / 1000);
|
loadvoltage = busvoltage + (shuntvoltage / 1000);
|
||||||
|
battery_level = map(loadvoltage * 100, 655, 840, 0, 100);
|
||||||
|
|
||||||
|
Serial.printf("Battery Level: %d %%\n", battery_level);
|
||||||
Serial.printf("Bus Voltage: %f V\n", busvoltage);
|
Serial.printf("Bus Voltage: %f V\n", busvoltage);
|
||||||
Serial.printf("Shunt Voltage: %f mV\n", shuntvoltage);
|
Serial.printf("Shunt Voltage: %f mV\n", shuntvoltage);
|
||||||
Serial.printf("Load Voltage: %f V\n", loadvoltage);
|
Serial.printf("Load Voltage: %f V\n", loadvoltage);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user