diff --git a/selfdrive/thermald/power_monitoring.py b/selfdrive/thermald/power_monitoring.py index 468e767f65..fe6e8ec2d4 100644 --- a/selfdrive/thermald/power_monitoring.py +++ b/selfdrive/thermald/power_monitoring.py @@ -58,12 +58,11 @@ def panda_current_to_actual_current(panda_current): class PowerMonitoring: - def __init__(self, is_uno): + def __init__(self): self.last_measurement_time = None # Used for integration delta self.power_used_uWh = 0 # Integrated power usage in uWh since going into offroad self.next_pulsed_measurement_time = None self.integration_lock = threading.Lock() - self.is_uno = is_uno # Calculation tick def calculate(self, health): @@ -90,6 +89,7 @@ class PowerMonitoring: self.last_measurement_time = now return + is_uno = health.health.hwType == log.HealthData.HwType.uno # Get current power draw somehow current_power = 0 if get_battery_status() == 'Discharging': @@ -132,7 +132,7 @@ class PowerMonitoring: self.next_pulsed_measurement_time = None return - elif self.next_pulsed_measurement_time is None and not self.is_uno: + elif self.next_pulsed_measurement_time is None and not is_uno: # On a charging EON with black panda, or drawing more than 400mA out of a white/grey one # Only way to get the power draw is to turn off charging for a few sec and check what the discharging rate is # We shouldn't do this very often, so make sure it has been some long-ish random time interval diff --git a/selfdrive/thermald/thermald.py b/selfdrive/thermald/thermald.py index be60ae41a1..db03db93e9 100755 --- a/selfdrive/thermald/thermald.py +++ b/selfdrive/thermald/thermald.py @@ -180,16 +180,11 @@ def thermald_thread(): current_connectivity_alert = None time_valid_prev = True should_start_prev = False - - is_uno = (read_tz(29, clip=False) < -1000) - if is_uno or not ANDROID: - handle_fan = handle_fan_uno - else: - setup_eon_fan() - handle_fan = handle_fan_eon + handle_fan = None + is_uno = False params = Params() - pm = PowerMonitoring(is_uno) + pm = PowerMonitoring() while 1: health = messaging.recv_sock(health_sock, wait=True) @@ -201,6 +196,18 @@ def thermald_thread(): usb_power = health.health.usbPowerMode != log.HealthData.UsbPowerMode.client ignition = health.health.ignitionLine or health.health.ignitionCan + # Setup fan handler on first connect to panda + if handle_fan is None and health.health.hwType != log.HealthData.HwType.unknown: + is_uno = health.health.hwType == log.HealthData.HwType.uno + + if is_uno or not ANDROID: + cloudlog.info("Setting up UNO fan handler") + handle_fan = handle_fan_uno + else: + cloudlog.info("Setting up EON fan handler") + setup_eon_fan() + handle_fan = handle_fan_eon + # Handle disconnect if health_prev is not None: if health.health.hwType == log.HealthData.HwType.unknown and \ @@ -244,8 +251,9 @@ def thermald_thread(): max_comp_temp = max(max_cpu_temp, msg.thermal.mem / 10., msg.thermal.gpu / 10.) bat_temp = msg.thermal.bat / 1000. - fan_speed = handle_fan(max_cpu_temp, bat_temp, fan_speed, ignition) - msg.thermal.fanSpeed = fan_speed + if handle_fan is not None: + fan_speed = handle_fan(max_cpu_temp, bat_temp, fan_speed, ignition) + msg.thermal.fanSpeed = fan_speed # thermal logic with hysterisis if max_cpu_temp > 107. or bat_temp >= 63.: