from src.variables.service import get_variable, set_variable from src.modules.RTD8.service import read_temp from src.modules.IndustrialAutomation.service_analog import set_0_10_out fans = [ { "inputs": [ #temperature inputs { "type": "RTD", #Card type "stack": 1, #Card stack "channel": 1 #Card channel }, { "type": "RTD", #Card type "stack": 1, #Card stack "channel": 2 #Card channel } ], "temp_min": 40, #minimum temp for fan_min "temp_max": 70, #maximum temp for fan_max "fan_min": 0, #fan minimum 0-10V set "fan_max": 10, #fan maximum 0-10V set "output_stack": 0, #stack card "output_channel": 2 #card channel } ] def get_temp(channel: dict) -> float: match channel["type"]: case "RTD": return read_temp(stack=channel["stack"], channel=channel["channel"]) case _: return 0 def max_temp(channels: list) -> float: temp: float = 0 for channel in channels: temp_ch = get_temp(channel=channel) if temp < temp_ch: temp = temp_ch return temp def fan_control(): for fan in fans: temp = max_temp(fan["inputs"]) if temp > fan["temp_max"]: set_0_10_out(stack=fan["output_stack"], channel=fan["output_channel"], value=10) elif temp < fan["temp_min"]: set_0_10_out(stack=fan["output_stack"], channel=fan["output_channel"], value=0) else: temp_calc = temp - fan["temp_min"] temp_max_calc = fan["temp_max"] - fan["temp_min"] calc_out = round(temp_calc / temp_max_calc, 4) * 10 set_0_10_out(stack=fan["output_stack"], channel=fan["output_channel"], value=calc_out)