Separate load and USB out, improve state handling

Identified issues:
- The load output and USB charging port shared the same state machine,
  which did not allow to set different switch-off thresholds.
- Load error codes were global, so it was not possible to have multiple
  load instances.

This commit introduces load-specific error_flags, makes the LoadOutput
class inherit from PowerPort (to improve code readability), separates
the load driver better from higher level implementation and adds a
second LoadOutput object for the USB charging port.
This commit is contained in:
Martin Jäger
2020-02-21 18:27:36 +01:00
parent 3c0bc41164
commit fa9d15e796
18 changed files with 341 additions and 474 deletions
+4 -4
View File
@@ -107,7 +107,7 @@ void ExtOled::process_1s()
oled.drawBitmap(34, 3, bmp_arrow_right, 5, 7, 1);
}
if (load.pgood) {
if (load.state == LOAD_STATE_ON) {
oled.drawBitmap(84, 3, bmp_arrow_right, 5, 7, 1);
}
else {
@@ -170,16 +170,16 @@ void ExtOled::process_1s()
// load data
oled.setTextCursor(90, 18);
len = snprintf(buf, sizeof(buf), "%5.1fW",
(abs(load_terminal.power) < 0.1) ? 0 : load_terminal.power); // remove negative zeros
(abs(load.power) < 0.1) ? 0 : load.power); // remove negative zeros
oled.writeString(buf, len);
oled.setTextCursor(90, 26);
len = snprintf(buf, sizeof(buf), "%5.1fA\n",
(abs(load_terminal.current) < 0.1) ? 0 : load_terminal.current);
(abs(load.current) < 0.1) ? 0 : load.current);
oled.writeString(buf, len);
oled.setTextCursor(0, 36);
len = snprintf(buf, sizeof(buf), "Day +%5.0fWh -%5.0fWh",
in_terminal.neg_energy_Wh, fabs(load_terminal.pos_energy_Wh));
in_terminal.neg_energy_Wh, fabs(load.pos_energy_Wh));
oled.writeString(buf, len);
len = snprintf(buf, sizeof(buf), "Tot +%4.1fkWh -%4.1fkWh",
dev_stat.solar_in_total_Wh / 1000.0, fabs(dev_stat.load_out_total_Wh) / 1000.0);