diff --git a/devtimer.py b/devtimer.py index 24d6f73..d30aeba 100755 --- a/devtimer.py +++ b/devtimer.py @@ -5,39 +5,92 @@ # Permission Hereby Granted For Unrestricted Personal Or Commercial Use +from threading import Thread from time import time, sleep from tm1637 import * from wiringpi import wiringPiSetupGpio wiringPiSetupGpio() +##### +# Constants +##### + +# Display + BRIGHTNESS = 0x09 CLK = 21 DIO = 20 +# Compensate for program execution time in master timing loop + +CALIBRATION_OFFSET = 0.0032 + +# Reference temperature in degrees F + +NORMAL_TEMP = 68 + +##### +# Lookup Table For Compensating Factors +##### + +''' + Each paper|film-developer combo has an entry here, expressed as: + + +- correction/degree + + 68F is considered "normal". Temperatures below this will cause the + timer to run slower. Temperatures above it, will cause the timer to + run faster. This creates a "virtual second" that reflect time, + material, and developer selected. + + WARNING: It takes about 250ms to update the display on a Pi Zero. + So, if the "virtual second" falls at or below this, the + code will be attempting to do updates faster than the + display can handle. So the total amount of compensation + cannot be smaller than about 0.300 to be on the safe side. +''' + +compensate = ( + 0.000, # Normal + 0.002, # Small temperature dependency + 0.004, # Medium temperature dependency + 0.010, # Large temperature dependency + ) + +# Return the current temperature in degrees F + +def get_temp(): + return 72 -def show_elapsed(tm, elapsed): +# Update the display with elapsed time + +def show_elapsed(display0, elapsed): + min = elapsed // 60 sec = elapsed % 60 - d0 = tm.digit_to_segment[min // 10] - d1 = tm.digit_to_segment[min % 10] - d2 = tm.digit_to_segment[sec // 10] - d3 = tm.digit_to_segment[sec % 10] - tm.set_segments([d0, 0x80 + d1, d2, d3]) + d0 = display0.digit_to_segment[min // 10] + d1 = display0.digit_to_segment[min % 10] + d2 = display0.digit_to_segment[sec // 10] + d3 = display0.digit_to_segment[sec % 10] + display0.set_segments([d0, 0x80 + d1, d2, d3]) - +# Program entry point if __name__ == "__main__": - tm = TM1637(CLK, DIO, BRIGHTNESS) + display0 = TM1637(CLK, DIO, BRIGHTNESS) - start_time = int(time()) - show_elapsed(tm, 0) - + compensation_profile = 0 + elapsed_time = 0 while True: - sleep(.05) - show_elapsed(tm, int(time())-start_time) - if int(time())-start_time == 5999: - start_time = int(time()) + last = time() + update_thread = Thread(None, show_elapsed, None, (display0, elapsed_time)) + sleep((1.000 + ((NORMAL_TEMP-get_temp()) * compensate[3])) - CALIBRATION_OFFSET) + elapsed_time += 1 + elapsed_time %= 6000 + update_thread = Thread(None, show_elapsed, None, (display0, elapsed_time)) + print(time()-last) + update_thread.start() diff --git a/tm1637.py b/tm1637.py index e417b5a..bbadd76 100644 --- a/tm1637.py +++ b/tm1637.py @@ -1,5 +1,5 @@ # Tip of the hat to https://github.com/johnlr/raspberrypi-tm1637 for -# this code. I has been very slightly modified, but it mostly his +# this code. This has been very slightly modified, but it mostly his # work. from time import sleep