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