瀏覽代碼

updated the logic for testing when the MCU resets and Pi sends the charging cycle number along with the other battery limits; dry run(untested)

namrota ghosh 7 月之前
父節點
當前提交
b553bd8ede
共有 1 個文件被更改,包括 7 次插入11 次删除
  1. 7 11
      src/cc_cv_charging.c

+ 7 - 11
src/cc_cv_charging.c

@@ -85,18 +85,17 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
     
         // 4. Cut-off check inside CV
     
-        else if ((charging_state == STATE_CV_CHARGING) &&
-                (batt_current <= batt_cutoff_current + BATTERY_THRESHOLD)) {
-            if (cycle_count < MAX_CYCLES) {
+        else if ((charging_state == STATE_CV_CHARGING) && (batt_current <= batt_cutoff_current + BATTERY_THRESHOLD)) {
+            //since after the reset the cycle_count sets back to 0, and if the previous_cycle_number obtained from the Pi is greater then:      
+            if(previous_cycle_number > cycle_count){
+                cycle_count= previous_cycle_number;
+                charging_state =  STATE_DISCHARGING;
+            }else if (cycle_count < MAX_CYCLES) {
                 charging_state = STATE_DISCHARGING;
                 cycle_count++;
-            } else if(previous_cycle_number < cycle_count){
-                cycle_count= previous_cycle_number;
             }else {
                 charging_state = STATE_FINAL_DISCHARGE;
             }
-            
-            
         }
   
         // 5. State Discharging condition
@@ -123,10 +122,7 @@ void CC_CV_UpdateChargingState(uint8_t slot_id) {
     }
 }
     
-    
-    
-
-  /*
+/*
 Function for Battery Charging and Discharging:
 ** Pre Charge: Once the battery is in discharged state, pre-charging
 begins. Starts charging safely with a typically low current C/10