def getPressKey(self): a = [0, 1, 2, 3, 11, 18, 8, 9] r = [0, 1, 2, 3] c = [18, 11, 8, 9] key = [ ["1", "2", "3", "A"], ["4", "5", "6", "B"], ["7", "8", "9", "C"], ["*", "0", "#", "D"], ] values = [ ["0", "0", "0", "0"], ["0", "0", "0", "0"], ["0", "0", "0", "0"], ["0", "0", "0", "0"], ["0", "0", "0", "0"], ] lastvalues = copy.deepcopy(values) # close before open if used for pin in a: try: omega_gpio.closepin(pin) except: e = 1 # dummy command :-) # pin init for pin in r: omega_gpio.initpin(pin, 'out') for pin in c: omega_gpio.initpin(pin, 'in') while True: rpos = 0 for rpin in r: omega_gpio.setoutput(r[0], 0) omega_gpio.setoutput(r[1], 0) omega_gpio.setoutput(r[2], 0) omega_gpio.setoutput(r[3], 0) omega_gpio.setoutput(rpin, 1) time.sleep(0.05) cpos = 0 for cpin in c: input = omega_gpio.readinput(cpin) values[rpos][cpos] = input cpos = cpos + 1 rpos = rpos + 1 for x in range(0, 4): for y in range(0, 4): if values[x][y] != lastvalues[x][y]: self.keycode = key[x][y] if values[x][y] == 1: return self.keycode lastvalues = copy.deepcopy(values)
def selSeg(self, segNum): #------------------------ import time "Set pinout to select a LCD segment" mux0 = segNum < 8 if debug: print "Set mux 0 Enable %i " %mux0 omega_gpio.setoutput(self.muxEnablePins[0], not(mux0)) #note inverted signal if debug: print "Set mux 1 Enable %i \n" %(not mux0) omega_gpio.setoutput(self.muxEnablePins[1], mux0) #note inverted signal if mux0: for i in range(2, -1, -1): x = segNum >> i & 1 if debug: print "Set Mux0 sigSelect Pin %i to %i \n" \ %(self.muxSigSelectPins[i], x) omega_gpio.setoutput(self.muxSigSelectPins[i], x) else: for i in range(2, -1, -1): x = (segNum - 8) >> i & 1 if debug: print "Set Mux0 sigSelect Pin %i to %i \n" \ %(self.muxSigSelectPins[i], x) omega_gpio.setoutput(self.muxSigSelectPins[i], x) time.sleep(0.01) # add some delay for i/o pins to change state
def modeSelection(self): self.keypad_init() rpos = 0 if True: for rpin in self.r: omega_gpio.setoutput(self.r[0], 0) omega_gpio.setoutput(self.r[1], 0) omega_gpio.setoutput(self.r[2], 0) omega_gpio.setoutput(self.r[3], 0) omega_gpio.setoutput(rpin, 1) time.sleep(0.05) cpos = 0 for cpin in self.c: input = omega_gpio.readinput(cpin) self.values[rpos][cpos] = input cpos = cpos + 1 rpos = rpos + 1 for x in range(0, 4): for y in range(0, 4): if self.values[x][y] != self.lastvalues[x][y]: keycode = self.key[x][y] if self.values[x][y] == 1: if keycode == '1': oledExp.setCursor(7, 0) oledExp.write(keycode) time.sleep(2) configure.DL_SETTINGS() dlmode.RUN_MODE() elif keycode == '2': oledExp.setCursor(7, 0) oledExp.write(keycode) time.sleep(2) dlmode.DIRECT_RUN_MODE() elif keycode == '3': oledExp.setCursor(7, 0) oledExp.write(keycode) time.sleep(2) dlmode.DIRECT_BACKUP_MODE() else: #print(keycode) oledExp.clear() oledExp.setCursor(3, 0) oledExp.write("Invalid Selection") oledExp.setCursor(4, 0) oledExp.write("Select 1 or 2 or 3") time.sleep(2) lastvalues = copy.deepcopy(self.values)
def run(self): global onoff_flag while True: time.sleep(3) client_sock, addr = sock.accept() data = client_sock.recv(1024) print data.decode() if data == '1': onoff_flag = 1 omega_gpio.setoutput(relay_gpioNum, 0) print 'on!!!!!!!!!!!!!!!!!!!' elif data == '0': onoff_flag = 0 omega_gpio.setoutput(relay_gpioNum, 1) print 'off!!!!!!!!!!!!!!!!!!' sock.close()
def modeSelection(self): self.keypad_init() rpos = 0 if True: for rpin in self.r: omega_gpio.setoutput(self.r[0], 0) omega_gpio.setoutput(self.r[1], 0) omega_gpio.setoutput(self.r[2], 0) omega_gpio.setoutput(self.r[3], 0) omega_gpio.setoutput(rpin, 1) time.sleep(0.05) cpos = 0 for cpin in self.c: input = omega_gpio.readinput(cpin) self.values[rpos][cpos] = input cpos = cpos + 1 rpos = rpos + 1 for x in range(0, 4): for y in range(0, 4): if self.values[x][y] != self.lastvalues[x][y]: keycode = self.key[x][y] if self.values[x][y] == 1: if keycode == '1': oledExp.setCursor(7, 0) oledExp.write(keycode) time.sleep(2) CONFMODE() elif keycode == '2': oledExp.setCursor(7, 0) oledExp.write(keycode) time.sleep(2) dlmode.DIRECT_RUN_MODE() elif keycode == '3': oledExp.setCursor(7, 0) oledExp.write(keycode) time.sleep(2) dlmode.DIRECT_BACKUP_MODE() else: disp.WrongSelectionOfKey() lastvalues = copy.deepcopy(self.values)
def run(self): while True: proc = subprocess.Popen([ './checkHumidity ' + str(temphumi_gpioNum) + ' ' + sensorModel ], stdout=subprocess.PIPE, shell=True) (out, err) = proc.communicate() sensor_data = out.split('\n') print sensor_data global humidity humidity = sensor_data[0] global temperature temperature = sensor_data[1] print "Humidity:" print str(humidity) + "%" print "Temperature:" print str(temperature) + "C" if float(temperature) > 28.0: print 'hot hot QQQQQQQQQQQQQQQQQQQQ' omega_gpio.setoutput(relay_gpioNum, 0)
def setLight(state): if state == 0: for pin in GPIO_PINS: omega_gpio.setoutput(pin, 0) elif state == 1: for pin in GPIO_PINS_R: omega_gpio.setoutput(pin, 1) elif state == 2: for pin in GPIO_PINS_G: omega_gpio.setoutput(pin, 1)
import omega_gpio as gpio import time ######################### # DOES NOT WORK ######################### LED_PIN = 7 gpio.initpin(LED_PIN,'out') gpio.setoutput(LED_PIN,0) BUTTON_PIN = 9 gpio.initpin(BUTTON_PIN,'in') while True: if gpio.readinput(BUTTON_PIN): print "BUTTON PRESSED" gpio.setoutput(LED_PIN,1) else: gpio.setoutput(LED_PIN,0)
def setrgb(red,green,blue): omega_gpio.setoutput(17,1 if red==0 else 0) omega_gpio.setoutput(16,1 if green==0 else 0) omega_gpio.setoutput(15,1 if blue==0 else 0)
def checkKey(self): a = [0, 1, 2, 3, 11, 18, 8, 9] r = [0, 1, 2, 3] c = [18, 11, 8, 9] key = [ ["1", "2", "3", "A"], ["4", "5", "6", "B"], ["7", "8", "9", "C"], ["*", "0", "#", "D"], ] values = [ ["0", "0", "0", "0"], ["0", "0", "0", "0"], ["0", "0", "0", "0"], ["0", "0", "0", "0"], ["0", "0", "0", "0"], ] lastvalues = copy.deepcopy(values) # close before open if used for pin in a: try: omega_gpio.closepin(pin) except: e = 1 # dummy command :-) # pin init for pin in r: omega_gpio.initpin(pin, 'out') for pin in c: omega_gpio.initpin(pin, 'in') if True: rpos = 0 for rpin in r: omega_gpio.setoutput(r[0], 0) omega_gpio.setoutput(r[1], 0) omega_gpio.setoutput(r[2], 0) omega_gpio.setoutput(r[3], 0) omega_gpio.setoutput(rpin, 1) time.sleep(0.05) cpos = 0 for cpin in c: input = omega_gpio.readinput(cpin) values[rpos][cpos] = input cpos = cpos + 1 rpos = rpos + 1 for x in range(0, 4): for y in range(0, 4): if values[x][y] != lastvalues[x][y]: keycode = key[x][y] if values[x][y] == 1: if keycode == 'D': oledExp.clear() oledExp.write("System reseting...") time.sleep(5) os.execl(sys.executable, sys.executable, * sys.argv) #for resetting the program elif keycode == 'A': f = open('confdata.txt', 'r') lines = f.readlines() SiteID = lines[0].rstrip('\n') MonitoringID= lines[1].rstrip('\n') AnalyzerID= lines[2].rstrip('\n') ParameterID= lines[3].rstrip('\n') oledExp.clear() oledExp.setCursor(0, 0) oledExp.write(SiteID) oledExp.setCursor(1,0) oledExp.write(MonitoringID) oledExp.setCursor(2,0) oledExp.write(AnalyzerID) oledExp.setCursor(3,0) oledExp.write(ParameterID) time.sleep(5) oledExp.clear() else: oledExp.clear() oledExp.setCursor(0,0) oledExp.write("Press 'D' for Reset") oledExp.setCursor(1,0) oledExp.write("'A' for userData") time.sleep(5) oledExp.clear() lastvalues = copy.deepcopy(values)
import socket import omega_gpio relay_gpioNum = 8 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind(('',3300)) sock.listen(1) while True: client_sock, addr = sock.accept() data = client_sock.recv(1024) print data.decode() if data == '1': onoff_flag = 1 omega_gpio.setoutput(relay_gpioNum, 0) print 'on!!!!!!!!!!!!!!!!!!!' elif data == '0': onoff_flag = 0 omega_gpio.setoutput(relay_gpioNum,1) print 'off!!!!!!!!!!!!!!!!!!' sock.close()
def setrgb(red, green, blue): omega_gpio.setoutput(17, 1 if red == 0 else 0) omega_gpio.setoutput(16, 1 if green == 0 else 0) omega_gpio.setoutput(15, 1 if blue == 0 else 0)
import omega_gpio as gpio import time PIN = 7 WAIT = 1 gpio.initpin(PIN, 'out') gpio.setoutput(PIN, 0) while True: gpio.setoutput(PIN, 1) time.sleep(WAIT) gpio.setoutput(PIN, 0) time.sleep(WAIT)
import omega_gpio as gpio import time ######################### # DOES NOT WORK ######################### LED_PIN = 7 gpio.initpin(LED_PIN, 'out') gpio.setoutput(LED_PIN, 0) BUTTON_PIN = 9 gpio.initpin(BUTTON_PIN, 'in') while True: if gpio.readinput(BUTTON_PIN): print "BUTTON PRESSED" gpio.setoutput(LED_PIN, 1) else: gpio.setoutput(LED_PIN, 0)
def listOfConfigureMode(self): self.keypad_init() rpos = 0 if True: for rpin in self.r: omega_gpio.setoutput(self.r[0], 0) omega_gpio.setoutput(self.r[1], 0) omega_gpio.setoutput(self.r[2], 0) omega_gpio.setoutput(self.r[3], 0) omega_gpio.setoutput(rpin, 1) time.sleep(0.05) cpos = 0 for cpin in self.c: input = omega_gpio.readinput(cpin) self.values[rpos][cpos] = input cpos = cpos + 1 rpos = rpos + 1 for x in range(0, 4): for y in range(0, 4): if self.values[x][y] != self.lastvalues[x][y]: keycode = self.key[x][y] if self.values[x][y] == 1: if keycode == '1': oledExp.setCursor(5, 0) oledExp.write(keycode) time.sleep(2) oledExp.clear() conf.set_date_time() time.sleep(2) CONFMODE() elif keycode == '2': oledExp.setCursor(5, 0) oledExp.write(keycode) time.sleep(2) oledExp.clear() #disp.ConnectToPC() conf.site_details() time.sleep(2) CONFMODE() elif keycode == '3': oledExp.setCursor(5, 0) oledExp.write(keycode) time.sleep(2) oledExp.clear() conf.read_confdata() time.sleep(2) CONFMODE() elif keycode == 'D': oledExp.clear() oledExp.write("System reseting...") time.sleep(5) os.execl(sys.executable, sys.executable, *sys.argv) #for resetting the program else: disp.ConfigureMode_Page2() lastvalues = copy.deepcopy(self.values)
# The for loop sets the direction for the pins(always output for this) for x in range(0, pins): omega_gpio.initpin(dictPins[x],'out') # Initialize the relay. If more than one expansion then this will need to use # a for loop to do multiple units. relayStatus = relayExp.driverInit(7) if (relayStatus == 0): print('Relay is initialized') else: print('Relay is NOT initialized') # This sets all pins to off and all relays to open for x in range(0, pins): omega_gpio.setoutput(dictPins[x], 1) for x in range(0, relays): relayExp.setChannel(7,0,x) # This allows use of files in the static directory @route('/static/<filename>') def server_static(filename): return static_file(filename, root = './static/') @route('/') @post('/<pinStates>') def root1(pinStates=pinStates): global loggedIn print(loggedIn) global pinStates2
def root1(pinStates=pinStates): global loggedIn print(loggedIn) global pinStates2 if (loggedIn == False): password = request.forms.get('password') print('below is return for password') print(password) if (password != '1234'): return template('login.tpl') else: loggedIn = True pinStates = pinStates2 buttonNum = (str(request.forms.get('btnId'))).splitlines() buttonNum = buttonNum[0] print (buttonNum) if (buttonNum == 'None'): return template('gpio.tpl', pinStates = pinStates) buttonNum = int(buttonNum) pinStates = pinStates2.split(',') if (pinStates[buttonNum] == '0on'): pinStates[buttonNum] = '0off' omega_gpio.setoutput(dictPins[buttonNum], 1) elif (pinStates[buttonNum] == '0off'): pinStates[buttonNum] = '0on' omega_gpio.setoutput(dictPins[buttonNum], 0) elif (pinStates[buttonNum] == '1on'): pinStates[buttonNum] = '1off' omega_gpio.setoutput(dictPins[buttonNum], 1) elif (pinStates[buttonNum] == '1off'): pinStates[buttonNum] = '1on' omega_gpio.setoutput(dictPins[buttonNum], 0) elif (pinStates[buttonNum] == '2on'): pinStates[buttonNum] = '2off' omega_gpio.setoutput(dictPins[buttonNum], 1) elif (pinStates[buttonNum] == '2off'): pinStates[buttonNum] = '2on' omega_gpio.setoutput(dictPins[buttonNum], 0) elif (pinStates[buttonNum] == '3on'): pinStates[buttonNum] = '3off' relayExp.setChannel(7,0,0) elif (pinStates[buttonNum] == '3off'): pinStates[buttonNum] = '3on' relayExp.setChannel(7,0,1) else: print ('Unable to decode the pinStates string') print (pinStates) pinStates2 = ",".join(pinStates) print (pinStates2) return template('gpio.tpl', pinStates = pinStates2)
omega_gpio.closepin(pin) except: e = 1 # dummy command :-) # pin init for pin in r: omega_gpio.initpin(pin, 'out') for pin in c: omega_gpio.initpin(pin, 'in') while True: now = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") rpos = 0 for rpin in r: omega_gpio.setoutput(r[0], 0) omega_gpio.setoutput(r[1], 0) omega_gpio.setoutput(r[2], 0) omega_gpio.setoutput(r[3], 0) omega_gpio.setoutput(rpin, 1) time.sleep(0.05) cpos = 0 for cpin in c: input = omega_gpio.readinput(cpin) values[rpos][cpos] = input cpos = cpos + 1 rpos = rpos + 1 for x in range(0, 4): for y in range(0, 4): if values[x][y] != lastvalues[x][y]: