def printDebugToFile(self): try: f = open("debug.txt", 'wt') if self.fireState == FIRE_ON: f.write("Fire is on\n") else: f.write("Fire is off\n") f.write("Desired temperature : " + str(self.desiredTemperature) + "\n") f.write("Measured temperature: " + str(self.measuredTemperature) + "\n") f.write("Control Status : " + self.controlStatus + "\n") f.write("Time Override : " + self.timeOverride + "\n") f.write("=============Datafiles===============\n") f.write("Control Status: " + readData('datafiles/controlStatus.txt') + "\n") f.write("Desired temperature: " + readData('datafiles/desiredTemperature.txt') + "\n") f.write("Measured Temperature: " + readData('datafiles/measuredTemperature.txt') + "\n") f.write("showStatus: " + readData('datafiles/showStatus.txt') + "\n") f.write("systemStatus: " + readData('datafiles/systemStatus.txt') + "\n") f.write("timeOverride: " + readData('datafiles/timeOverride.txt') + "\n") f.write("LED Brightness: " + readData('datafiles/alphaNumBrightness.txt') + "\n") f.write("Override count: " + readData('datafiles/overrideCount.txt.txt') + "\n") f.close() except: pass
def startTemperatureOverride(): currentOverrideCount = 30 writeData('datafiles/overrideCount.txt', str(currentOverrideCount)) while True: # read timeCount from file try: currentOverrideCount = int(readData('datafiles/overrideCount.txt')) currentOverrideCount -= 1 writeData('datafiles/overrideCount.txt', str(currentOverrideCount)) except: pass if currentOverrideCount == 0: currentOverrideCount = 30 localtime = datetime.datetime.time(datetime.datetime.now()) start = datetime.time(16, 0, 0) # 4pm end = datetime.time(22, 0, 0) # 10pm if not (time_in_range(start, end, localtime)): # switch the fire off tempOverrideLogger.warning( 'Switch fire OFF as outside time range at: ' + str(localtime)) updateOff() # Tell the world we are in override mode. writeData('datafiles/timeOverride.txt', 'ON') time.sleep(60 * 1) # sleep for 1 minute
def ledBrightnessDown(): try: currentBrightness = int (readData('datafiles/alphaNumBrightness.txt')) if currentBrightness > 0: currentBrightness -= 1 writeData('datafiles/alphaNumBrightness.txt', str(currentBrightness)) except: pass
def desiredTemperatureUp(): try: currentTemp = int (readData('datafiles/desiredTemperature.txt')) currentTemp += 1 writeData('datafiles/desiredTemperature.txt', str(currentTemp)) writeData ('datafiles/showStatus.txt', "DESIRED") except: pass
def toggleDisplayMode(): # display measured -> display desired -> display off currentStatus = readData('datafiles/showStatus.txt') if currentStatus == "MEASURED": writeData ('datafiles/showStatus.txt', "DESIRED") elif currentStatus == "DESIRED": writeData ('datafiles/showStatus.txt', "BLANK") elif currentStatus == "BLANK": writeData ('datafiles/showStatus.txt', "CONTROL") elif currentStatus == "CONTROL": writeData ('datafiles/showStatus.txt', "BATTERY") elif currentStatus == "BATTERY": writeData ('datafiles/showStatus.txt', "SYSTEM") elif currentStatus == "SYSTEM": writeData ('datafiles/showStatus.txt', "MEASURED") else: pass #error
def printDebugToScreen(self): if self.fireState == FIRE_ON: print "Fire is on" else: print "Fire is off" print "Desired temperature : " + str(self.desiredTemperature) print "Measured temperature: " + str(self.measuredTemperature) print "Control Status : " + self.controlStatus print "Time Override : " + self.timeOverride print "=============Datafiles===============" print "Control Status: " + readData('datafiles/controlStatus.txt') print "Desired temperature: " + readData( 'datafiles/desiredTemperature.txt') print "Measured Temperature: " + readData( 'datafiles/measuredTemperature.txt') print "showStatus: " + readData('datafiles/showStatus.txt') print "systemStatus: " + readData('datafiles/systemStatus.txt') print "timeOverride: " + readData('datafiles/timeOverride.txt') print "LED Brightness: " + readData('datafiles/alphaNumBrightness.txt') print "Override count: " + readData('datafiles/overrideCount.txt.txt')
def startShowStatus(): while True: # First set the brightness try: brightness = int(readData('datafiles/alphaNumBrightness.txt')) setBrightness(brightness) except ValueError: print "Value error reading: " + readData( 'datafiles/alphaNumBrightness.txt') dataToShow = readData('datafiles/showStatus.txt') # print dataToShow if dataToShow == "MEASURED": data = readData('datafiles/measuredTemperature.txt') data = 'm' + data # Take care of the decimal point printNumberMessage(data) elif dataToShow == "DESIRED": data = readData('datafiles/desiredTemperature.txt') data = 'd' + data printMessage(data) elif dataToShow == "BLANK": printMessage(' ') elif dataToShow == "CONTROL": data = readData('datafiles/controlStatus.txt') printMessage(data) elif dataToShow == "SYSTEM": data = readData('datafiles/systemStatus.txt') printMessage(data) elif dataToShow == "BATTERY": data = readData('datafiles/batteryLife.txt') data = 'b' + data printMessage(data) else: pass #error time.sleep(UI_SLEEP_TIME)
def OLD_startShowStatus(): while True: data = readData('datafiles/measuredTemperature.txt') print str(data) printMessage(data) time.sleep(1)
# Control what gets sent to the alphanumeric display showMessageThread = Thread(target=startShowStatus, args=()) showMessageThread.daemon = True showMessageThread.start() #TODO - Consider moving all logs and data files to a USB drive writeData('datafiles/showStatus.txt', "BLANK") # Default to nothing on the alphanumeric writeData('datafiles/systemStatus.txt', "GOOD") #BTEr Batt etc. show any errors writeData('datafiles/alphaNumBrightness.txt', "0") # 0 to 15 writeData('datafiles/overrideCount.txt', "30") # Check if we need to do a time override every 30 minutes try: while True: fire.desiredTemperature = readData('datafiles/desiredTemperature.txt') fire.measuredTemperature = readData( 'datafiles/measuredTemperature.txt') fire.controlStatus = readData('datafiles/controlStatus.txt') fire.timeOverride = readData('datafiles/timeOverride.txt') fire.systemStatus = readData('datafiles/systemStatus.txt') fire.runControlAlgorithm() time.sleep(CONTROL_SLEEP_TIME) except KeyboardInterrupt: fire.switchFireOff() controlFireLogger.debug('Switch fire OFF Program Terminates')