|
|
@@ -27,6 +27,12 @@ static void batteryslots_init() {
|
|
|
|
|
|
for(uint8_t i=0; i< NUM_SLOTS; i++){
|
|
|
|
|
|
+ battery_slots[i].measurement.state = SLOT_STATE_OK;
|
|
|
+ // convinience trick:
|
|
|
+ // with that we can set *battery_slots[i].state = SLOT_STATE_* or SLOT_ERR_*
|
|
|
+ // like e.g. *battery_slots[i].state = SLOT_ERR_OVERTEMPERATURE
|
|
|
+ battery_slots[i].state = &battery_slots[i].measurement.state;
|
|
|
+
|
|
|
battery_slots[i].measurement.voltage = 0;
|
|
|
battery_slots[i].measurement.current = 0;
|
|
|
battery_slots[i].measurement.temperature = 0;
|
|
|
@@ -70,9 +76,8 @@ static void batteryslots_adjust_current(uint8_t slot) {
|
|
|
set_dac(slot, --battery_slots[slot].dac_value);
|
|
|
}
|
|
|
else {
|
|
|
- // error case to be implemented:
|
|
|
// we want to give more current, but we can't ?!
|
|
|
- ;
|
|
|
+ *battery_slots[slot].state = SLOT_WARN_LOWER_DAC_NOT_POSSIBLE;
|
|
|
}
|
|
|
} else if (battery_slots[slot].set_current - BATTERY_CURRENT_THRESHOLD < battery_slots[slot].measurement.current) {
|
|
|
// we are outside of the tolerance band
|
|
|
@@ -82,9 +87,8 @@ static void batteryslots_adjust_current(uint8_t slot) {
|
|
|
set_dac(slot, ++battery_slots[slot].dac_value);
|
|
|
}
|
|
|
else {
|
|
|
- // error case to be implemented:
|
|
|
// we want to give more current, but we can't ?!
|
|
|
- ;
|
|
|
+ *battery_slots[slot].state = SLOT_WARN_HIGHER_DAC_NOT_POSSIBLE;
|
|
|
}
|
|
|
}
|
|
|
// no else statement here: we are ok, since we are in the tolerance measure
|
|
|
@@ -104,14 +108,13 @@ static void batteryslots_adjust_current(uint8_t slot) {
|
|
|
// @todo debugging & validation: ensure that this directive works
|
|
|
printf("timer count: %d\n", DL_Timer_getTimerCount(battery_slots[0].timer));
|
|
|
|
|
|
- if (battery_slots[slot].pwm_value+1 >= DL_Timer_getTimerCount(battery_slots[0].timer)) {
|
|
|
+ if (battery_slots[slot].pwm_value+1 <= DL_Timer_getTimerCount(battery_slots[0].timer)) {
|
|
|
// pwm is inverse to the DAC since dragging more current means more negative
|
|
|
set_pwm(slot, ++battery_slots[slot].pwm_value);
|
|
|
}
|
|
|
else {
|
|
|
- // error case to be implemented:
|
|
|
// we want to give more current, but we can't ?!
|
|
|
- ;
|
|
|
+ *battery_slots[slot].state = SLOT_WARN_HIGHER_PWM_NOT_POSSIBLE;
|
|
|
}
|
|
|
} else if (battery_slots[slot].set_current - BATTERY_CURRENT_THRESHOLD < battery_slots[slot].measurement.current) {
|
|
|
// we are outside of the tolerance band
|
|
|
@@ -121,9 +124,8 @@ static void batteryslots_adjust_current(uint8_t slot) {
|
|
|
set_dac(slot, --battery_slots[slot].pwm_value);
|
|
|
}
|
|
|
else {
|
|
|
- // error case to be implemented:
|
|
|
// we want to give more current, but we can't ?!
|
|
|
- ;
|
|
|
+ *battery_slots[slot].state = SLOT_WARN_LOWER_PWM_NOT_POSSIBLE;
|
|
|
}
|
|
|
}
|
|
|
} else {
|