def process_charging_ctrl(msg, last_charging_ctrl, battery_percent): charging_ctrl = msg.dragonConf.dpChargingCtrl if last_charging_ctrl != charging_ctrl: HARDWARE.set_battery_charging(True) if charging_ctrl: if battery_percent >= msg.dragonConf.dpDischargingAt and HARDWARE.get_battery_charging(): HARDWARE.set_battery_charging(False) elif battery_percent <= msg.dragonConf.dpChargingAt and not HARDWARE.get_battery_charging(): HARDWARE.set_battery_charging(True) return charging_ctrl
def charging_ctrl(self, msg, ts, to_discharge, to_charge): if self.ts_last_charging_ctrl is None or ( ts - self.ts_last_charging_ctrl) >= 300.: battery_changing = HARDWARE.get_battery_charging() if self.ts_last_charging_ctrl: if msg.deviceState.batteryPercent >= to_discharge and battery_changing: HARDWARE.set_battery_charging(False) elif msg.deviceState.batteryPercent <= to_charge and not battery_changing: HARDWARE.set_battery_charging(True) self.ts_last_charging_ctrl = ts
def should_shutdown(self, pandaState, offroad_timestamp, started_seen): if pandaState is None or offroad_timestamp is None: return False now = sec_since_boot() panda_charging = (pandaState.pandaState.usbPowerMode != log.PandaState.UsbPowerMode.client) BATT_PERC_OFF = 10 should_shutdown = False # Wait until we have shut down charging before powering down should_shutdown |= (not panda_charging and self.should_disable_charging(pandaState, offroad_timestamp)) should_shutdown |= ((HARDWARE.get_battery_capacity() < BATT_PERC_OFF) and (not HARDWARE.get_battery_charging()) and ((now - offroad_timestamp) > 60)) should_shutdown &= started_seen return should_shutdown
def should_shutdown(self, health, offroad_timestamp, started_seen, LEON): if health is None or offroad_timestamp is None: return False now = sec_since_boot() panda_charging = (health.health.usbPowerMode != log.HealthData.UsbPowerMode.client) BATT_PERC_OFF = 10 if LEON else 3 should_shutdown = False # Wait until we have shut down charging before powering down should_shutdown |= (not panda_charging and self.should_disable_charging(health, offroad_timestamp)) should_shutdown |= ((HARDWARE.get_battery_capacity() < BATT_PERC_OFF) and (not HARDWARE.get_battery_charging()) and ((now - offroad_timestamp) > 60)) should_shutdown &= started_seen return should_shutdown
def should_shutdown(self, peripheralState, ignition, in_car, offroad_timestamp, started_seen): if offroad_timestamp is None: return False now = sec_since_boot() panda_charging = (peripheralState.usbPowerMode != log.PeripheralState.UsbPowerMode.client) BATT_PERC_OFF = 10 should_shutdown = False # Wait until we have shut down charging before powering down should_shutdown |= (not panda_charging and self.should_disable_charging(ignition, in_car, offroad_timestamp)) should_shutdown |= ((HARDWARE.get_battery_capacity() < BATT_PERC_OFF) and (not HARDWARE.get_battery_charging()) and ((now - offroad_timestamp) > 60)) should_shutdown &= started_seen or (now > MIN_ON_TIME_S) return should_shutdown
def setEONChargingStatus(car_voltage_mV, batteryPercent): if EON: if car_voltage_mV is None or batteryPercent is None: HARDWARE.set_battery_charging(True) return #print( "car_voltage_mV:",car_voltage_mV) #print( "batteryPercent:",batteryPercent) #print( "VBATT_PAUSE_CHARGING:",VBATT_PAUSE_CHARGING) #print("VBATT_PAUSE_CHARGING * 1e3:", VBATT_PAUSE_CHARGING * 1e3) if HARDWARE.get_battery_charging(): #print("log purpose : HARDWARE.get_battery_charging() True ") # if batteryPercent > BATT_PERC_MAX or car_voltage_mV < VBATT_PAUSE_CHARGING * 1e3 : if batteryPercent > BATT_PERC_MAX: #or car_voltage_mV < VBATT_PAUSE_CHARGING * 1e3: #print("log purpose : HARDWARE.set_battery_charging(False) False ") HARDWARE.set_battery_charging(False) return else: #print("log purpose : HARDWARE.get_battery_charging() False ") #if batteryPercent < BATT_PERC_MIN and car_voltage_mV > VBATT_PAUSE_CHARGING * 1e3: if batteryPercent < BATT_PERC_MIN: #and car_voltage_mV > VBATT_PAUSE_CHARGING * 1e3: #print("log purpose : HARDWARE.set_battery_charging(True) True ") HARDWARE.set_battery_charging(True) return