1010
1111
1212parser = argparse .ArgumentParser ()
13- parser .add_argument ('--threshold' , type = float , default = - 1 , help = 'Temperature threshold in degrees C to enable fan' )
14- parser .add_argument ('--hysteresis' , type = float , default = - 1 , help = 'Distance from threshold before fan is disabled' )
15-
1613parser .add_argument ('--off-threshold' , type = float , default = 55.0 , help = 'Temperature threshold in degrees C to enable fan' )
1714parser .add_argument ('--on-threshold' , type = float , default = 65.0 , help = 'Temperature threshold in degrees C to disable fan' )
15+ parser .add_argument ('--low-temp' , type = float , default = None , help = 'Temperature at which the LED is greeen' )
16+ parser .add_argument ('--high-temp' , type = float , default = None , help = 'Temperature for which LED is red' )
1817parser .add_argument ('--delay' , type = float , default = 2.0 , help = 'Delay, in seconds, between temperature readings' )
1918parser .add_argument ('--preempt' , action = 'store_true' , default = False , help = 'Monitor CPU frequency and activate cooling premptively' )
2019parser .add_argument ('--verbose' , action = 'store_true' , default = False , help = 'Output temp and fan status messages' )
2120parser .add_argument ('--nobutton' , action = 'store_true' , default = False , help = 'Disable button input' )
2221parser .add_argument ('--noled' , action = 'store_true' , default = False , help = 'Disable LED control' )
2322parser .add_argument ('--brightness' , type = float , default = 255.0 , help = 'LED brightness, from 0 to 255' )
23+ parser .add_argument ('--extended-colours' , action = 'store_true' , default = False , help = 'Extend LED colours for outside of normal low to high range' )
2424
2525args = parser .parse_args ()
2626
@@ -35,13 +35,26 @@ def clean_exit(signum, frame):
3535def update_led_temperature (temp ):
3636 led_busy .acquire ()
3737 temp = float (temp )
38- temp -= args .off_threshold
39- temp /= float (args .on_threshold - args .off_threshold )
40- temp = max (0 , min (1 , temp ))
41- temp = 1.0 - temp
42- temp *= 120.0
43- temp /= 360.0
44- r , g , b = [int (c * 255.0 ) for c in colorsys .hsv_to_rgb (temp , 1.0 , args .brightness / 255.0 )]
38+ if temp < args .low_temp and args .extended_colours :
39+ # Between minimum temp and low temp, set LED to blue through to green
40+ temp -= min_temp
41+ temp /= float (args .low_temp - min_temp )
42+ temp = max (0 , temp )
43+ hue = (120.0 / 360.0 ) + ((1.0 - temp ) * 120.0 / 360.0 )
44+ elif temp > args .high_temp and args .extended_colours :
45+ # Between high temp and maximum temp, set LED to red through to magenta
46+ temp -= args .high_temp
47+ temp /= float (max_temp - args .high_temp )
48+ temp = min (1 , temp )
49+ hue = 1.0 - (temp * 60.0 / 360.0 )
50+ else :
51+ # In the normal low temp to high temp range, set LED to green through to red
52+ temp -= args .low_temp
53+ temp /= float (args .high_temp - args .low_temp )
54+ temp = max (0 , min (1 , temp ))
55+ hue = (1.0 - temp ) * 120.0 / 360.0
56+
57+ r , g , b = [int (c * 255.0 ) for c in colorsys .hsv_to_rgb (hue , 1.0 , args .brightness / 255.0 )]
4558 fanshim .set_light (r , g , b )
4659 led_busy .release ()
4760
@@ -76,14 +89,6 @@ def set_automatic(status):
7689 last_change = 0
7790
7891
79- if args .threshold > - 1 or args .hysteresis > - 1 :
80- print ("""
81- The --threshold and --hysteresis parameters have been deprecated.
82- Use --on-threshold and --off-threshold instead!
83- """ )
84- sys .exit (1 )
85-
86-
8792fanshim = FanShim ()
8893fanshim .set_hold_time (1.0 )
8994fanshim .set_fan (False )
@@ -93,18 +98,20 @@ def set_automatic(status):
9398enable = False
9499is_fast = False
95100last_change = 0
101+ min_temp = 30
102+ max_temp = 85
96103signal .signal (signal .SIGTERM , clean_exit )
97104
98105if args .noled :
99106 led_busy .acquire ()
100107 fanshim .set_light (0 , 0 , 0 )
101108 led_busy .release ()
102109
103- t = get_cpu_temp ()
104- if t >= args .threshold :
105- last_change = get_cpu_temp ()
106- set_fan (True )
110+ if args .low_temp is None :
111+ args .low_temp = args .off_threshold
107112
113+ if args .high_temp is None :
114+ args .high_temp = args .on_threshold
108115
109116if not args .nobutton :
110117 @fanshim .on_release ()
0 commit comments