Switched to use power of 2 error numbers (#72)

In addition to the normal error flags we now have
ERR_ANY_ERROR which may be used to clear all errors
at once or to use in has_error to see if there is any error flag set.
This commit is contained in:
hogthrob
2019-11-04 09:19:06 +01:00
committed by Martin Jäger
parent fd474e5350
commit bec02cb25b
4 changed files with 65 additions and 44 deletions
+13 -13
View File
@@ -265,7 +265,7 @@ void LoadOutput::state_machine()
state = LOAD_STATE_ON;
}
else {
if (dev_stat.error_flags & (1 << ERR_BAT_UNDERVOLTAGE)) {
if (dev_stat.has_error(ERR_BAT_UNDERVOLTAGE)) {
state = LOAD_STATE_OFF_LOW_SOC;
}
else {
@@ -283,7 +283,7 @@ void LoadOutput::state_machine()
else if (port->pos_current_limit == 0) { // float == is allowed for 0.0
switch_set(false);
// find out reason why load current is not allowed
if (dev_stat.error_flags & (1 << ERR_BAT_UNDERVOLTAGE)) {
if (dev_stat.has_error(ERR_BAT_UNDERVOLTAGE)) {
lvd_timestamp = time(NULL);
state = LOAD_STATE_OFF_LOW_SOC;
}
@@ -296,7 +296,7 @@ void LoadOutput::state_machine()
case LOAD_STATE_OFF_LOW_SOC:
// wait at least configured time
if (time(NULL) - lvd_timestamp > lvd_recovery_delay &&
!(dev_stat.error_flags & (1 << ERR_BAT_UNDERVOLTAGE)))
!(dev_stat.has_error(ERR_BAT_UNDERVOLTAGE)))
{
state = LOAD_STATE_DISABLED; // switch to normal mode again
}
@@ -304,8 +304,8 @@ void LoadOutput::state_machine()
case LOAD_STATE_OFF_OVERCURRENT:
// wait configured time
if (time(NULL) - overcurrent_timestamp > overcurrent_recovery_delay) {
dev_stat.error_flags &= ~(1 << ERR_LOAD_OVERCURRENT);
dev_stat.error_flags &= ~(1 << ERR_LOAD_VOLTAGE_DIP);
dev_stat.clear_error(ERR_LOAD_OVERCURRENT);
dev_stat.clear_error(ERR_LOAD_VOLTAGE_DIP);
state = LOAD_STATE_DISABLED; // switch to normal mode again
}
break;
@@ -313,7 +313,7 @@ void LoadOutput::state_machine()
if (port->voltage < (port->sink_voltage_max - 0.5) &&
port->voltage < (LOW_SIDE_VOLTAGE_MAX - 0.5))
{
dev_stat.error_flags &= ~(1 << ERR_LOAD_OVERVOLTAGE);
dev_stat.clear_error(ERR_LOAD_OVERVOLTAGE);
state = LOAD_STATE_DISABLED; // switch to normal mode again
}
break;
@@ -321,12 +321,12 @@ void LoadOutput::state_machine()
// stay here until the charge controller is reset or load is switched off remotely
if (enable == false) {
short_circuit = false;
dev_stat.error_flags &= ~(1 << ERR_LOAD_SHORT_CIRCUIT);
dev_stat.clear_error(ERR_LOAD_SHORT_CIRCUIT);
state = LOAD_STATE_DISABLED; // switch to normal mode again
}
break;
case LOAD_STATE_OFF_TEMPERATURE:
if (!(dev_stat.error_flags & (1U << ERR_INT_OVERTEMP)) &&
if (!(dev_stat.has_error(ERR_INT_OVERTEMP)) &&
port->pos_current_limit > 0)
{
state = LOAD_STATE_DISABLED;
@@ -343,7 +343,7 @@ void LoadOutput::control()
if (short_circuit) {
if (state != LOAD_STATE_OFF_SHORT_CIRCUIT) {
state = LOAD_STATE_OFF_SHORT_CIRCUIT;
dev_stat.error_flags |= (1 << ERR_LOAD_SHORT_CIRCUIT);
dev_stat.set_error(ERR_LOAD_SHORT_CIRCUIT);
print_error("Load short circuit detected\n");
}
return;
@@ -363,14 +363,14 @@ void LoadOutput::control()
switch_set(false);
leds_flicker(LED_LOAD);
state = LOAD_STATE_OFF_OVERCURRENT;
dev_stat.error_flags |= (1 << ERR_LOAD_OVERCURRENT);
dev_stat.set_error(ERR_LOAD_OVERCURRENT);
print_error("Load overcurrent detected\n");
overcurrent_timestamp = time(NULL);
return;
}
// internal overtemperature
if (dev_stat.error_flags & (1U << ERR_INT_OVERTEMP)) {
if (dev_stat.has_error(ERR_INT_OVERTEMP)) {
switch_set(false);
state = LOAD_STATE_OFF_TEMPERATURE;
print_error("Device overtemperature detected\n");
@@ -382,7 +382,7 @@ void LoadOutput::control()
switch_set(false);
leds_flicker(LED_LOAD);
state = LOAD_STATE_OFF_OVERCURRENT;
dev_stat.error_flags |= (1 << ERR_LOAD_VOLTAGE_DIP);
dev_stat.set_error(ERR_LOAD_VOLTAGE_DIP);
print_error("Load voltage dip detected\n");
overcurrent_timestamp = time(NULL);
return;
@@ -399,7 +399,7 @@ void LoadOutput::control()
print_error("Load overvoltage detected\n");
state = LOAD_STATE_OFF_OVERVOLTAGE;
overcurrent_timestamp = time(NULL);
dev_stat.error_flags |= (1 << ERR_LOAD_OVERVOLTAGE);
dev_stat.set_error(ERR_LOAD_OVERVOLTAGE);
return;
}
}