diff --git a/TODO b/TODO index 69a7ca2..85e51a6 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,6 @@ - Cleanups: + - Check to make sure out of range temps still handled properly - Collect globals into a more coherent centralized namespace - Cleanup debug handling using that centralized state info - Cleanup timer run code into separate thread that gets started/stopped instead of always running with 0 displayed diff --git a/devtimer.py b/devtimer.py index 60c489e..e114548 100755 --- a/devtimer.py +++ b/devtimer.py @@ -72,7 +72,7 @@ # So, shoot me ... CURRENT_PROFILE = REALTIME -CURRENT_TEMP = TEMP_SENTINEL + # Operating globals @@ -147,8 +147,6 @@ def monitor_temps(): - global CURRENT_TEMP - while True: probe = open("/opt/devtimer/temp_probe/w1_slave") @@ -165,19 +163,19 @@ # display an outrageous temperature. If it stays on, it means # the temperature measurement process isn't working. - if CURRENT_TEMP == TEMP_SENTINEL: - CURRENT_TEMP = temp + if monitor_temps.current_temp == TEMP_SENTINEL: + monitor_temps.current_temp = temp - elif abs(temp - CURRENT_TEMP) <= 10: - CURRENT_TEMP = temp + elif abs(temp - monitor_temps.current_temp) <= 10: + monitor_temps.current_temp = temp probe.close() - Thread(name="Temp", target=show_temp, args=(temp_led, CURRENT_TEMP)).start() + Thread(name="Temp", target=show_temp, args=(temp_led, monitor_temps.current_temp)).start() if DEBUG: - sys.stdout.write("Temp: %sF\n" % CURRENT_TEMP) + sys.stdout.write("Temp: %sF\n" % monitor_temps.current_temp) sleep(1) @@ -374,8 +372,8 @@ if (CURRENT_PROFILE == REALTIME): compensation_factor = 1 # Realtime requires no compensation - elif TEMP_LOW <= CURRENT_TEMP <= TEMP_HIGH: - compensation_factor = compensate[CURRENT_PROFILE][CURRENT_TEMP-TEMP_LOW] + elif TEMP_LOW <= monitor_temps.current_temp <= TEMP_HIGH: + compensation_factor = compensate[CURRENT_PROFILE][monitor_temps.current_temp-TEMP_LOW] # Temperature is out of range for our correction table # This implictly uses the last known compensation factor so we can keep running @@ -388,7 +386,7 @@ elapsed_time %= 6000 if DEBUG: - print("Elapsed Time: %s Current Temp: %s Factor: %s Inter-update Time: %s" % (elapsed_time, CURRENT_TEMP, compensation_factor, str(time()-last))) + print("Elapsed Time: %s Current Temp: %s Factor: %s Inter-update Time: %s" % (elapsed_time, monitor_temps.current_temp, compensation_factor, str(time()-last))) ##### @@ -437,7 +435,8 @@ Thread(name="InitTimeDisplay", target=show_elapsed, args=[time_led, 0]).start() # Show the initial temp sentinel - show_temp(temp_led, CURRENT_TEMP) + monitor_temps.current_temp = TEMP_SENTINEL + show_temp(temp_led, monitor_temps.current_temp) # Start measuring temperature