Fixes for displaying values as a bar on the LCD.

pull/32/head
Holger Wirtz 5 years ago
parent ddd1ce00d4
commit be7e58962f
  1. 21
      UI.hpp

@ -3375,15 +3375,20 @@ void lcd_display_float(float var, uint8_t size_number, uint8_t size_fraction, bo
void lcd_display_bar_int(const char* title, uint32_t value, uint32_t min_value, uint32_t max_value, uint8_t size, bool zeros, bool brackets, bool sign, bool init) void lcd_display_bar_int(const char* title, uint32_t value, uint32_t min_value, uint32_t max_value, uint8_t size, bool zeros, bool brackets, bool sign, bool init)
{ {
float _v = float(value * LCD_cols) / (max_value - min_value); float _v = float(value * LCD_cols) / (max_value - min_value);
float _vi; float _vi = 0.0;
uint8_t vf = uint8_t(modff(_v, &_vi) * 10.0 + 0.5); uint8_t vf = uint8_t(modff(_v, &_vi) * 10.0 + 0.5);
uint8_t vi = uint8_t(_vi); uint8_t vi = uint8_t(_vi + 0.5);
Serial.println(value, DEC);
Serial.println(_v, 5);
Serial.println(vf, DEC);
Serial.println(vi, DEC);
if (init == true) if (init == true)
{ {
// show initial title, value and bar // show initial title, value and bar
lcd.clear(); lcd.clear();
lcd.show(0, 0, LCD_cols, title); lcd.show(0, 0, LCD_cols - 1, title);
lcd.setCursor(LCD_cols - (size + 1) + 1, 0); lcd.setCursor(LCD_cols - (size + 1) + 1, 0);
lcd_display_int(value, size, zeros, brackets, sign); lcd_display_int(value, size, zeros, brackets, sign);
lcd.setCursor(0, 1); lcd.setCursor(0, 1);
@ -3413,7 +3418,7 @@ void lcd_display_bar_int(const char* title, uint32_t value, uint32_t min_value,
else else
{ {
// show only changed value and changed part of the bar // show only changed value and changed part of the bar
uint8_t ca = max((float((LCD_cols) / float(max_value - min_value)) + 0.5), 1); uint8_t ca = float(LCD_cols - 1) / float(max_value - min_value) + 1;
lcd.setCursor(LCD_cols - (size + 1) + 1, 0); lcd.setCursor(LCD_cols - (size + 1) + 1, 0);
lcd_display_int(value, size, zeros, brackets, sign); lcd_display_int(value, size, zeros, brackets, sign);
@ -3433,14 +3438,12 @@ void lcd_display_bar_int(const char* title, uint32_t value, uint32_t min_value,
} }
else else
{ {
uint8_t b, e; uint8_t b = max(0, vi - ca);
uint8_t e = min(LCD_cols - 1, vi + ca);
b = max(0, vi - ca);
e = min(LCD_cols - 1, vi + ca);
lcd.setCursor(b, 1);
for (uint8_t n = b; n <= e; n++) for (uint8_t n = b; n <= e; n++)
{ {
lcd.setCursor(n, 1);
if (n < vi) if (n < vi)
lcd.write((uint8_t)4); // full block lcd.write((uint8_t)4); // full block
else if (n == vi && uint8_t(vf / 2) != 0) else if (n == vi && uint8_t(vf / 2) != 0)

Loading…
Cancel
Save