|
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 |
|
@@ -99,12 +100,7 @@ class HomeScreen : public UIScreen { |
99 | 100 |
|
100 | 101 |
|
101 | 102 | void renderBatteryIndicator(DisplayDriver& display, uint16_t batteryMilliVolts) { |
102 | | - // Convert millivolts to percentage |
103 | | - const int minMilliVolts = 3000; // Minimum voltage (e.g., 3.0V) |
104 | | - const int maxMilliVolts = 4200; // Maximum voltage (e.g., 4.2V) |
105 | | - int batteryPercentage = ((batteryMilliVolts - minMilliVolts) * 100) / (maxMilliVolts - minMilliVolts); |
106 | | - if (batteryPercentage < 0) batteryPercentage = 0; // Clamp to 0% |
107 | | - if (batteryPercentage > 100) batteryPercentage = 100; // Clamp to 100% |
| 103 | + int batteryPercentage = batteryPercentFromMilliVolts(batteryMilliVolts); |
108 | 104 |
|
109 | 105 | // battery icon |
110 | 106 | int iconWidth = 24; |
@@ -326,8 +322,20 @@ class HomeScreen : public UIScreen { |
326 | 322 | strcpy(name, "gps"); sprintf(buf, "%.4f %.4f", lat, lon); |
327 | 323 | break; |
328 | 324 | case LPP_VOLTAGE: |
329 | | - r.readVoltage(v); |
330 | | - strcpy(name, "voltage"); sprintf(buf, "%6.2f", v); |
| 325 | + r.readVoltage(v); // v is in volts |
| 326 | + |
| 327 | + if (channel == TELEM_CHANNEL_SELF) { |
| 328 | + // This is our own battery voltage |
| 329 | + uint16_t batteryMilliVolts = (uint16_t)(v * 1000.0f + 0.5f); // convert V -> mV |
| 330 | + int pct = batteryPercentFromMilliVolts(batteryMilliVolts); |
| 331 | + |
| 332 | + strcpy(name, "battery"); |
| 333 | + sprintf(buf, "%4.2fV %3d%%", v, pct); |
| 334 | + } else { |
| 335 | + // Other voltage sensor |
| 336 | + strcpy(name, "voltage"); |
| 337 | + sprintf(buf, "%6.2f", v); |
| 338 | + } |
331 | 339 | break; |
332 | 340 | case LPP_CURRENT: |
333 | 341 | r.readCurrent(v); |
|
0 commit comments