Is there a proper way to adjust battery monitor range for the OLED display to show first bar for example at voltages <2.5 and last bar at 4.0> ?
There is no “proper” way to do it. Some people have been adjusting the battery upper/lower limits here:
float battery() const {
return last_voltage_;
}
void SetLoad(bool on) {
loaded_ = on;
}
bool low() const { return low_count_ > 1000; }
float battery_percent() {
// Energy is roughly proportional to voltage squared.
float v = battery();
float min_v = 3.0;
float max_v = 4.2;
return 100.0 * (v * v - min_v * min_v) / (max_v * max_v - min_v * min_v);
// return 100.0 * (v - min_v) / (max_v - min_v);
}
void SetPinHigh(bool go_high) {
if (go_high) {
pinMode(batteryLevelPin, OUTPUT);
digitalWrite(batteryLevelPin, HIGH);
} else {
#if VERSION_MAJOR >= 2
Changing those lines changes the upper/lower limits for all the battery functions in proffieos.
If you want to specifically change how the OLED battery meter works, you can change it’s math here:
int start, end;
if (bar.skip < bar.columns) {
start = -bar.skip;
end = WIDTH + bar.columns - 1;
} else {
start = 0;
end = WIDTH;
}
int max_bars = (end - start) / bar.skip;
int pos = start;
int bars = floorf(
battery_monitor.battery_percent() * (0.5 + max_bars) / 100);
for (int i = 0; i < bars; i++) {
Draw(bar, pos, 0);
pos += bar.skip;
}
}
void DrawText(const char* str,
int x, int y,
const Glyph* font) {
while (*str) {
1 Like
Ok, and how this math works? What do I need to change?
It works very well thank you.
Seriously though; what exactly do you want it to do?
1 Like
I already changed float max and min voltages to 2.6 and 4.0, but the first bar is gone already at 2.7-2.8 volts, but I want 2 bars go to 1 last bar at 2.6 volts and stay visible if voltage goes below that.
Maybe just change the floor() to a ceil()?
1 Like
I don’t know, I don’t even understand what they both mean or do
1 Like
ceil() modification worked, thanks