|
1 | 1 | #include "UITask.h" |
2 | 2 | #include <helpers/TxtDataHelpers.h> |
| 3 | +#include <helpers/Battery.h> |
3 | 4 | #include "../MyMesh.h" |
4 | 5 | #include "target.h" |
5 | 6 | #ifdef WIFI_SSID |
@@ -110,18 +111,7 @@ class HomeScreen : public UIScreen { |
110 | 111 |
|
111 | 112 |
|
112 | 113 | void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) { |
113 | | - // Convert millivolts to percentage |
114 | | -#ifndef BATT_MIN_MILLIVOLTS |
115 | | - #define BATT_MIN_MILLIVOLTS 3000 |
116 | | -#endif |
117 | | -#ifndef BATT_MAX_MILLIVOLTS |
118 | | - #define BATT_MAX_MILLIVOLTS 4200 |
119 | | -#endif |
120 | | - const int minMilliVolts = BATT_MIN_MILLIVOLTS; |
121 | | - const int maxMilliVolts = BATT_MAX_MILLIVOLTS; |
122 | | - int batteryPercentage = ((batteryMilliVolts - minMilliVolts) * 100) / (maxMilliVolts - minMilliVolts); |
123 | | - if (batteryPercentage < 0) batteryPercentage = 0; // Clamp to 0% |
124 | | - if (batteryPercentage > 100) batteryPercentage = 100; // Clamp to 100% |
| 114 | + int batteryPercentage = batteryPercentFromMilliVolts(batteryMilliVolts); |
125 | 115 |
|
126 | 116 | // battery icon |
127 | 117 | int iconWidth = 24; |
@@ -358,8 +348,20 @@ class HomeScreen : public UIScreen { |
358 | 348 | strcpy(name, "gps"); sprintf(buf, "%.4f %.4f", lat, lon); |
359 | 349 | break; |
360 | 350 | case LPP_VOLTAGE: |
361 | | - r.readVoltage(v); |
362 | | - strcpy(name, "voltage"); sprintf(buf, "%6.2f", v); |
| 351 | + r.readVoltage(v); // v is in volts |
| 352 | + |
| 353 | + if (channel == TELEM_CHANNEL_SELF) { |
| 354 | + // This is our own battery voltage |
| 355 | + uint16_t batteryMilliVolts = (uint16_t)(v * 1000.0f + 0.5f); // convert V -> mV |
| 356 | + int pct = batteryPercentFromMilliVolts(batteryMilliVolts); |
| 357 | + |
| 358 | + strcpy(name, "battery"); |
| 359 | + sprintf(buf, "%4.2fV %3d%%", v, pct); |
| 360 | + } else { |
| 361 | + // Other voltage sensor |
| 362 | + strcpy(name, "voltage"); |
| 363 | + sprintf(buf, "%6.2f", v); |
| 364 | + } |
363 | 365 | break; |
364 | 366 | case LPP_CURRENT: |
365 | 367 | r.readCurrent(v); |
|
0 commit comments