Exemple #1
0
def ledBrightnessDown():
    try:
        currentBrightness = int (readData('datafiles/alphaNumBrightness.txt'))
        if currentBrightness > 0:
            currentBrightness -= 1
            writeData('datafiles/alphaNumBrightness.txt', str(currentBrightness))
    except:
        pass
Exemple #2
0
def desiredTemperatureUp():
    try:
        currentTemp = int (readData('datafiles/desiredTemperature.txt'))
        currentTemp += 1
        writeData('datafiles/desiredTemperature.txt', str(currentTemp))
        writeData ('datafiles/showStatus.txt', "DESIRED")
    except:
        pass
Exemple #3
0
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
Exemple #4
0
def startRemoteScanning():
    for event in dev.read_loop():
        #
        # type should always be 1 for a keypress
        # code is the numeric value of the key that has been pressed
        # value 0 = key up, 1 = key down, 2 = key hold

        if event.type == ecodes.EV_KEY:
            # my_logger.debug (categorize(event))
            if event.value == 0:  # key up
                #remoteControlLogger.debug ( 'type: ' + str (event.type) + \
                #' code: ' + str (event.code) + ' value ' + str (event.value))
                # Pressing any key switches of the time override
                writeData ('datafiles/timeOverride.txt', 'OFF')

                if event.code == REMOTE_KEY_RED:
                    updateOn()
                elif event.code == REMOTE_KEY_GREEN:
                    updateOff()
                elif event.code == REMOTE_KEY_YELLOW:
                    updateAuto()
                elif event.code == REMOTE_KEY_BLUE:
                    toggleDisplayMode()
                elif event.code == REMOTE_KEY_UP:
                    desiredTemperatureUp()
                elif event.code == REMOTE_KEY_DOWN:
                    desiredTemperatureDown()
                elif event.code == REMOTE_KEY_NONE:
                    pass
                elif event.code == LED_BRIGHTNESS_KEY_UP:
                    ledBrightnessUp()
                elif event.code == LED_BRIGHTNESS_KEY_DOWN:
                    ledBrightnessDown()
                else:
                    # TODO Up/DOWN for desired temperature
                    print "Code: " + str (event.code)
Exemple #5
0
def startTempSensor():

    tempSensorLogger = initLogging('/var/log/fireV3/tempSensor.log')

    #bluetooth_adr = sys.argv[1] # 'A0:E6:F8:AF:3C:06'
    bluetooth_adr = "A0:E6:F8:AF:3C:06"
    print "connecting to " + bluetooth_adr

    startUSB = pexpect.spawn('sudo hciconfig hci0 up')
    tool = pexpect.spawn('gatttool -b ' + bluetooth_adr + ' --interactive')
    tool.expect('\[LE\]>')
    j = 1
    count = 0
    while True:
        #print "Preparing to connect. You might need to press the side button..."
        #tool.sendline('connect')
        # test for success of connect
        #j = tool.expect([pexpect.TIMEOUT, 'Connection successful'], timeout=60)

        j = connectSensor(tool)
        if j == 1:
            print "Connection successful"
            writeData('datafiles/systemStatus.txt', "GOOD")
            tool.expect('\[LE\]>')
            goodConnection = True
            while goodConnection == True:
                # Switch on  Temp sensor
                tool.sendline('char-write-cmd 0x0027 01')
                time.sleep(1)
                # Read the temp data
                tool.sendline('char-read-hnd 0x0024')
                i = 1
                i = tool.expect([pexpect.TIMEOUT, 'descriptor: .*'], timeout=5)
                if i == 1:
                    rVal = tool.after.split()
                    rObjTemp = floatfromhex(rVal[2] + rVal[1])

                    rAmbTemp = floatfromhex(rVal[4] + rVal[3])

                    objTemp = calcTemp(rObjTemp)
                    ambTemp = calcTemp(rAmbTemp)

                    # print "Obj: " + "%.2f C" % objTemp + " Amb:  " + "%.2f " % ambTemp + "%"
                    #tempSensorLogger.debug ( "Obj: " + "%.2fC" % objTemp + " Amb:  " + "%.2fC" % ambTemp)
                    writeData('datafiles/measuredTemperature.txt',
                              "%.1f" % ambTemp)
                    #TODO, only save temperature to file every 5 minutes
                    if count >= 100:
                        saveAmbTempToFile(str(ambTemp))
                        count = 0
                    else:
                        count += 1
                    # Now read the battery life
                    tool.sendline('char-read-hnd 0x001e')
                    k = tool.expect([pexpect.TIMEOUT, 'descriptor: .*'],
                                    timeout=5)
                    if k == 1:
                        rVal = tool.after.split()
                        #print "Battery: " + str(floatfromhex(rVal[1]))
                        writeData('datafiles/batteryLife.txt',
                                  "%.0f" % floatfromhex(rVal[1]))
                    else:
                        goodConnection = False
                        writeData('datafiles/systemStatus.txt', "BTEr")

                else:
                    print "Bad Connection"
                    goodConnection = False
                    writeData('datafiles/systemStatus.txt', "BTEr")
                # Switch off the temp sensor
                tool.sendline('char-write-cmd 0x0027 00')
                time.sleep(1)
        else:
            print "Bad Connection"
            goodConnection = False
            writeData('datafiles/systemStatus.txt', "BTEr")
            time.sleep(1)
Exemple #6
0
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
Exemple #7
0
def updateAuto():
    writeData ('datafiles/controlStatus.txt', 'AUTO')
    # Default desired temperature to 19 when moving to AUTO
    writeData('datafiles/desiredTemperature.txt', str(19))
    writeData ('datafiles/showStatus.txt', "CONTROL")
Exemple #8
0
def updateOff ():
    writeData ('datafiles/controlStatus.txt', 'OFF')
    writeData ('datafiles/showStatus.txt', "CONTROL")
Exemple #9
0
def updateOff():
    writeData('datafiles/controlStatus.txt', 'OFF')
Exemple #10
0
temperatureOverrideThread = Thread(target=startTemperatureOverride, args=())
temperatureOverrideThread.daemon = True
temperatureOverrideThread.start()

temperatureSensorThread = Thread(target=startTempSensor, args=())
temperatureSensorThread.daemon = True
temperatureSensorThread.start()

# 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')