|
8 | 8 |
|
9 | 9 |
|
10 | 10 | parser = argparse.ArgumentParser() |
11 | | -parser.add_argument('--threshold', type=float, default=55.0, help='Temperature threshold in degrees C to enable fan') |
12 | | -parser.add_argument('--hysteresis', type=float, default=5.0, help='Distance from threshold before fan is disabled') |
| 11 | +parser.add_argument('--threshold', type=float, default=-1, help='Temperature threshold in degrees C to enable fan') |
| 12 | +parser.add_argument('--hysteresis', type=float, default=-1, help='Distance from threshold before fan is disabled') |
| 13 | + |
| 14 | +parser.add_argument('--off-threshold', type=float, default=55.0, help='Temperature threshold in degrees C to enable fan') |
| 15 | +parser.add_argument('--on-threshold', type=float, default=65.0, help='Temperature threshold in degrees C to disable fan') |
13 | 16 | parser.add_argument('--delay', type=float, default=2.0, help='Delay, in seconds, between temperature readings') |
14 | 17 | parser.add_argument('--preempt', action='store_true', default=False, help='Monitor CPU frequency and activate cooling premptively') |
15 | 18 | parser.add_argument('--verbose', action='store_true', default=False, help='Output temp and fan status messages') |
|
21 | 24 |
|
22 | 25 | def clean_exit(signum, frame): |
23 | 26 | set_fan(False) |
24 | | - fanshim.set_light(0, 0, 0) |
| 27 | + if not args.noled: |
| 28 | + fanshim.set_light(0, 0, 0) |
25 | 29 | sys.exit(0) |
26 | 30 |
|
27 | 31 |
|
@@ -65,6 +69,14 @@ def set_automatic(status): |
65 | 69 | last_change = 0 |
66 | 70 |
|
67 | 71 |
|
| 72 | +if args.threshold > -1 or args.hysteresis > -1: |
| 73 | + print(""" |
| 74 | +The --threshold and --hysteresis parameters have been deprecated. |
| 75 | +Use --on-threshold and --off-threshold instead! |
| 76 | +""") |
| 77 | + sys.exit(1) |
| 78 | + |
| 79 | + |
68 | 80 | fanshim = FanShim() |
69 | 81 | fanshim.set_hold_time(1.0) |
70 | 82 | fanshim.set_fan(False) |
@@ -102,19 +114,31 @@ def held_handler(): |
102 | 114 |
|
103 | 115 | signal.signal(signal.SIGTERM, clean_exit) |
104 | 116 |
|
| 117 | +update_led(fanshim.get_fan()) |
| 118 | +enable = False |
| 119 | +is_fast = False |
| 120 | +last_change = 0 |
| 121 | + |
105 | 122 | try: |
106 | 123 | while True: |
107 | | - update_led(fanshim.get_fan()) |
108 | 124 | t = get_cpu_temp() |
109 | 125 | f = get_cpu_freq() |
| 126 | + was_fast = is_fast |
| 127 | + is_fast = (int(f.current) == int(f.max)) |
110 | 128 | if args.verbose: |
111 | 129 | print("Current: {:05.02f} Target: {:05.02f} Freq {: 5.02f} Automatic: {} On: {}".format(t, args.threshold, f.current / 1000.0, armed, enabled)) |
112 | | - if abs(last_change - t) > args.hysteresis and armed: |
113 | | - enable = (t >= args.threshold) |
114 | | - if args.preempt: |
115 | | - enable = enable or (int(f.current) == int(f.max)) |
116 | | - if set_fan(enable): |
117 | | - last_change = t |
| 130 | + |
| 131 | + if args.preempt and is_fast and was_fast: |
| 132 | + enable = True |
| 133 | + elif armed: |
| 134 | + if t >= args.on_threshold: |
| 135 | + enable = True |
| 136 | + elif t <= args.off_threshold: |
| 137 | + enable = False |
| 138 | + |
| 139 | + if set_fan(enable): |
| 140 | + last_change = t |
| 141 | + |
118 | 142 | time.sleep(args.delay) |
119 | 143 | except KeyboardInterrupt: |
120 | 144 | pass |
0 commit comments