def turnOFF(): relayAddr = 7 initRelay = relayExp.driverInit(relayAddr) if relayExp.checkInit(relayAddr): logData('relay is init') else: logData('ERR relay not init') exit()
def turnON(): relayAddr = 7 initRelay = relayExp.driverInit(relayAddr) if relayExp.checkInit(relayAddr): logData('relay is init') else: logData('ERR relay not init') exit() relayExp.setChannel(relayAddr, 0, 1)
def print_relay_status(): global g_relayAddress bInit = relayExp.checkInit(g_relayAddress) oledExp.setCursor(3, 0) if bInit == 0: oledExp.write("Relay : Disabled") else: oledExp.write("Relay : Available") print_relay1_status() print_relay2_status()
def turnOFF(): relayAddr = 7 initRelay = relayExp.driverInit(relayAddr) if relayExp.checkInit(relayAddr): logData('relay is init') else: logData('ERR relay not init') exit() #when you init the relay it turns it off #relayExp.setChannel(relayAddr, 0, 0) ''' only on pro model '''
def relayBoardInit(): status = relayExp.driverInit(relay_sw_addr) errorValue = True if status == 0: errorValue = False print_line('* relay driver init=[{}]'.format(status), debug=True, error=errorValue) bInit = relayExp.checkInit(relay_sw_addr) errorValue = True if bInit != 0: errorValue = False print_line('* relay driver checkInit=[{}]'.format(status), debug=True, error=errorValue) # force all relays to off relayExp.setAllChannels(relay_sw_addr, relay_off)
def confirmInit(light): #get address led = int2Addr(light) ledAddr = led[0] ledChannel = led[1] led1Init = 0 cnt = 0 #timer, 5 cycles and exit with failure. while led1Init == 0 or cnt < 5: #check initialization led1Init = relayExp.checkInit(ledAddr) #confirm successful init. if led1Init == 0: print 'Initialization unsuccessful' led1Init = relayExp.driverInit(ledAddr) time.sleep(.5) cnt = cnt + 1 else: return led1Init print 'Initialization confirmed' return 0
# check the arguments if len(sys.argv) != 2: print "ERROR: expected addr offset:" print sys.argv[0], "<addr offset>" exit() addr = int(sys.argv[1]) print "Starting to use relay-exp functions on addr offset", addr relayExp.setVerbosity(0) # check initialization # should return 0 if the Expansion has just been plugged in ret = relayExp.checkInit(addr) print "checking if initialized: ", ret # initialize the relay-exp ret = relayExp.driverInit(addr) print "Result from relayDriverInit: ", ret if ret != 0: exit() # check initialization # should return 1 since the Expansion was initialized above ret = relayExp.checkInit(addr) print "checking if initialized: ", ret time.sleep(1)
# check the arguments if len(sys.argv) != 2: print 'ERROR: expected addr offset:' print sys.argv[0], '<addr offset>' exit() addr = int(sys.argv[1]) print 'Starting to use relay-exp functions on addr offset', addr relayExp.setVerbosity(0) # check initialization # should return 0 if the Expansion has just been plugged in ret = relayExp.checkInit(addr) print "checking if initialized: ", ret # initialize the relay-exp ret = relayExp.driverInit(addr) print "Result from relayDriverInit: ", ret if (ret != 0): exit() # check initialization # should return 1 since the Expansion was initialized above ret = relayExp.checkInit(addr) print "checking if initialized: ", ret time.sleep(1) # set channel 0 to on
""" lightScheduler.py This file contains the functionality to run grow lights in the garden The first iteration will be just to run 14h per day, 0500-1900 Intended implementation on omega2 with relay expansion """ import time from OmegaExpansion import relayExp led1 = 7 init = 0 #intiialize relay status = relayExp.driverInit(led1) print status led1Init = relayExp.checkInit(1) #check initialization if led1Init == 0: print 'Initialization unsuccessful' led1Init = relayExp.driverInit(led1) else: print 'Initialization successful' while 1: #read current relay state state1 = relayExp.readChannel(led1, 1) if state1 == 1: output1 = 0 print 'Relay found ON' else: output1 = 1 print 'Relay found OFF'