|
|
@@ -1,6 +1,7 @@
|
|
|
#include "cc_cv_charging.h"
|
|
|
#include "src/config.h"
|
|
|
#include "src/battery_data/battery.h"
|
|
|
+#include <cstdint>
|
|
|
#include <stdio.h>
|
|
|
#include "ti/driverlib/dl_gpio.h"
|
|
|
#include "ti_msp_dl_config.h"
|
|
|
@@ -28,23 +29,25 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
|
|
|
int16_t batt_charge_discharge= battery->charge_discharge;
|
|
|
uint8_t previous_cycle= battery->previous_cycle_number;
|
|
|
uint8_t *cycle_count = &battery->cycle_number;
|
|
|
+ uint8_t *previous_cycle= &battery->previous_cycle_number;
|
|
|
battery->battery_charging_state= charging_state;
|
|
|
- BatteryChargingState previous_state= charging_state;
|
|
|
|
|
|
- //For logging state transitions
|
|
|
- if(charging_state != previous_state){
|
|
|
- printf("State transition: %d -> %d\n", previous_state, charging_state);
|
|
|
- previous_state= charging_state;
|
|
|
-
|
|
|
- }
|
|
|
|
|
|
- //Checking the condition where all the battery measurements are NULL: STATE
|
|
|
- if((batt_voltage== 0) || (batt_current == 0)){
|
|
|
- battery->battery_charging_state= STATE_IDLE;
|
|
|
- cv_charging_started= false;
|
|
|
+ //Added condition to support the edge case when the voltage drops unexpectedly to 0 during the cycle making the relays to clear
|
|
|
+ if(batt_voltage== 0){
|
|
|
+ battery_data[slot_id].counter+=1;
|
|
|
+ if(battery_data[slot_id].counter > 3){
|
|
|
+ printf("Persistent zero voltage. Setting to IDLE.\n");
|
|
|
+ battery->battery_charging_state = STATE_IDLE;
|
|
|
+ cv_charging_started = false;
|
|
|
+ }else{
|
|
|
+ //reset:
|
|
|
+ battery_data[slot_id].counter= 0;
|
|
|
+ }
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
if(battery_data[slot_id].battery_state == STATE_EMPTY || battery_data[slot_id].batteryLimitReceived==0){
|
|
|
battery->battery_charging_state= STATE_IDLE;
|
|
|
cv_charging_started= false;
|