DriftKingTW / Raspberry-Pi-PWM-Fan-Control

Raspberry Pi PWM fan contorl (for Notcua PWM fans)
MIT License
81 stars 33 forks source link

[Bug] Ctrl+C does not set fan to High #9

Closed lightmaster closed 3 years ago

lightmaster commented 3 years ago

https://github.com/DriftKingTW/Raspberry-Pi-PWM-Fan-Control/blob/79e191710c338823fa19573017137b4afc5eb753/fan_control.py#L82

As the title says, when testing the script, when I kill the script with Ctrl+C, the fan shuts off instead of getting set to high. Can you adjust this to instead use its own variable and make it so if the script is killed by any means it'll get set to this new variable?

DriftKingTW commented 3 years ago

Hi, thanks for the feedback! I find that just using the GPIO.cleanup() can do the trick. So I removed the setFanSpeed function in exception and add an atexit to detect if the process is killed or not, and now even kill the process by kill command the fan should reset to full speed.

lightmaster commented 3 years ago

If you are using other GPIO pins in other scripts, will GPIO.cleanup() effect those other pins?

DriftKingTW commented 3 years ago

If you are using other GPIO pins in other scripts, will GPIO.cleanup() effect those other pins?

No, GPIO.cleanup() only effects the pins use in this script.