Skip to main content

Code:

 

    def main():

args = parse_args()



TEMP_SCRIPT = "/home/firefly/Downloads/read_temp.sh"

FAN_CONTROL = "/usr/bin/firefly_fan_control"

BOARD_MODEL = "ITX-3588J"



fan_state = None # 'high' or 'low'



while True:

temp = get_temperature(TEMP_SCRIPT)

if temp is None:

time.sleep(args.interval)

continue



if temp >= args.high_threshold and fan_state != 'high':

print(f""INFO] Temp {temp} ≥ {args.high_threshold} → HIGH fan")

kill_old_fan_controls()

start_fan(args.high, FAN_CONTROL, BOARD_MODEL)

fan_state = 'high'



elif temp <= args.low_threshold and fan_state != 'low':

print(f"nINFO] Temp {temp} ≤ {args.low_threshold} → LOW fan")

kill_old_fan_controls()

start_fan(args.low, FAN_CONTROL, BOARD_MODEL)

fan_state = 'low'



else:

print(f" DEBUG] Temp {temp} — Fan remains {fan_state}")



time.sleep(args.interval)



if __name__ == "__main__":

main()



b2] read_temp.sh



#!/bin/bash



total=0

count=0



for zone in /sys/class/thermal/thermal_zone*/temp; do

temp=$(cat "$zone")

celsius=$((temp / 1000))

echo "$celsius"

total=$((total + celsius))

count=$((count + 1))

done



echo "$total"

echo $((total / count)



fan_state = None # 'high' or 'low'



while True:

temp = get_temperature(TEMP_SCRIPT)

if temp is None:

time.sleep(args.interval)

continue



if temp >= args.high_threshold and fan_state != 'high':

print(f" INFO] Temp {temp} ≥ {args.high_threshold} → HIGH fan")

kill_old_fan_controls()

start_fan(args.high, FAN_CONTROL, BOARD_MODEL)

fan_state = 'high'



elif temp <= args.low_threshold and fan_state != 'low':

print(f" INFO] Temp {temp} ≤ {args.low_threshold} → LOW fan")

kill_old_fan_controls()

start_fan(args.low, FAN_CONTROL, BOARD_MODEL)

fan_state = 'low'



else:

print(f" DEBUG] Temp {temp} — Fan remains {fan_state}")



time.sleep(args.interval)



if __name__ == "__main__":

main()

 

Reply


//Terms and Conditions