def __new__(self): if self._instance is None: self._instance = super(Main, self).__new__(self) self._motor_control = MotorControl() # print(self._motor_control) self._lcd = LCD() self._lcd.start() self._temperature = temperature() self._light = light() self._distance = Distance() self._compass = compass(declination=(1, 19)) return self._instance
def main(): try: # returns current hour as a integer currentHour = datetime.now().hour # currentHour = 18 ## light theme # if currentHour in range(lightHours[0], lightHours[1]+1): if currentHour >= lightHours[0] and currentHour < lightHours[1]: ## call theme changer func light() ## light_dark theme elif currentHour >= lightHours[1] and currentHour < lightDarkHours[1]: # light plasma theme if currentHour >= lightHours[1] and currentHour < lightDarkHours[0]: ## between 15 - 19 light_dark(isDark=False) # dark plasma theme elif currentHour >= lightDarkHours[ 0] and currentHour < lightDarkHours[1]: ## between 19 - 21 light_dark(isDark=True) # print(waiting1) # commandHandler(waiting1, command1) # night theme elif currentHour >= lightDarkHours[1] and currentHour < nightHours[ 0] or currentHour >= 0 and currentHour < nightHours[1]: # night theme between 15 - 23 night() except KeyboardInterrupt as e: from sys import exit exit(0)
def InitSeneorsDic(self): try: self.SensorsObjectDic.clear() # ControlData = str(enable)+','+str(acqfre)+','+str(rediscount)+','+str(parameters) # Data = '2*'+str(type)+'*'+str(sensor_code)+'*'+str(pins)+'*'+ControlData sensors = self.mysql.GetData( "select type,sensor_code,pins,enable,acqfre,rediscount,parameters,tranfre,keep_time from ssaicsp_sensors" ) for sensor in sensors: controldata = str(sensor[3]) + ',' + str( sensor[4]) + ',' + str(sensor[5]) + ',' + str(sensor[6]) sensortype = int(sensor[0]) #print(sensortype,controldata) self.log.debug('传感器:sensortype=' + str(sensortype) + ',controldata=' + controldata) if sensortype == 1: #添加蜂鸣传感器 act = activebuzzer(sensor[0], sensor[1], sensor[2], controldata) act.Start() self.SensorsObjectDic[act.GetKey()] = act self.log.debug('添加传感器' + act.GetKey()) elif sensortype == 2: self.log.debug('添加传感器' + str(sensortype)) elif sensortype == 3: #添加一个温湿度传感器 dht = dht11(sensor[0], sensor[1], sensor[2], controldata) dht.Start() self.SensorsObjectDic[dht.GetKey()] = dht self.log.debug('添加传感器' + dht.GetKey()) elif sensortype == 4: #添加一个火焰传感器 fir = fire(sensor[0], sensor[1], sensor[2], controldata) fir.Start() self.SensorsObjectDic[fir.GetKey()] = fir self.log.debug('添加传感器' + fir.GetKey()) elif sensortype == 5: self.log.debug('添加传感器' + str(sensortype)) elif sensortype == 6: self.log.debug('添加传感器' + str(sensortype)) elif sensortype == 7: self.log.debug('添加传感器' + str(sensortype)) elif sensortype == 8: #添加一个光敏传感器 lig = light(sensor[0], sensor[1], sensor[2], controldata) lig.Start() self.SensorsObjectDic[lig.GetKey()] = lig self.log.debug('添加传感器' + lig.GetKey()) elif sensortype == 9: self.log.debug('添加传感器' + str(sensortype)) elif sensortype == 10: #添加一个雨滴传感器 ran = rain(sensor[0], sensor[1], sensor[2], controldata) ran.Start() self.SensorsObjectDic[ran.GetKey()] = ran self.log.debug('添加传感器' + ran.GetKey()) elif sensortype == 11: #添加一个烟雾传感器 smk = smoke(sensor[0], sensor[1], sensor[2], controldata) smk.Start() self.SensorsObjectDic[smk.GetKey()] = smk self.log.debug('添加传感器' + smk.GetKey()) elif sensortype == 12: #添加一个土壤传感器 sol = soil(sensor[0], sensor[1], sensor[2], controldata) sol.Start() self.SensorsObjectDic[sol.GetKey()] = sol self.log.debug('添加传感器' + sol.GetKey()) elif sensortype == 13: self.log.debug('添加传感器' + str(sensortype)) elif sensortype == 14: #添加一个测距传感器 ult = ultrasonic(sensor[0], sensor[1], sensor[2], controldata) ult.Start() self.SensorsObjectDic[ult.GetKey()] = ult self.log.debug('添加传感器' + ult.GetKey()) elif sensortype == 15: #添加led l1d = led(sensor[0], sensor[1], sensor[2], controldata) l1d.Start() self.SensorsObjectDic[l1d.GetKey()] = l1d self.log.debug('添加传感器' + l1d.GetKey()) elif sensortype == 16: self.log.debug('添加传感器' + str(sensortype)) elif sensortype == 17: self.log.debug('添加传感器' + str(sensortype)) elif sensortype == 18: self.log.debug('添加传感器' + str(sensortype)) else: #print('添加传感器',sensortype , '错误') self.log.debug('添加传感器' + str(sensortype) + '错误') pass except Exception as e: self.log.error('初始化设备失败,错误为:' + str(e))
homepath = '/home/pi/' print homepath print os.path.exists(homepath + '/autopi.config') if not os.path.exists(homepath + '/autopi.config'): print 'no user info' root = Tk() root.wm_title('AutoPi Login') app = registerGUI(root, web) root.mainloop() print 'Web' print web pi = raspberryPi(web) light = light() cam = camera() alarm = alarm() blind = blinds() reg = register(web, pi, light, cam, alarm, blind) else: config = ConfigParser.ConfigParser() config.read(homepath + '/autopi.config') username = config.get('LoginInfo', 'username') password = config.get('LoginInfo', 'password') print 'working' web.setUsername(username) web.setPassword(password) web.setAuth() pi = raspberryPi(web) if not pi.response:
def main(): config = ConfigParser.RawConfigParser() config.read("posconfig.txt") waitSecs = config.getint("general","seconds_lights_on") #sets up the socket host = config.get("database", "host") port = config.getint("database", "port") responseSize = config.getint("database","responseSize") greenLight = light(config.getint("light", "greenPin")) redLight = light(config.getint("light", "redPin")) (rfidKeyboard, magneticKeyboard) = getKeyboards() greenLight.off() redLight.off() #print("Connecting to ", host) #posSocket.connect((host, port)) while rfidKeyboard and magneticKeyboard: idInput = readKeyboards(rfidKeyboard, magneticKeyboard) currentStudent = Student(0, 0, False, 'students.db') #process to allow id input in any order and validates the student does not have a G2G container greenLight.off() redLight.off() #student number first workflow if(currentStudent.isInputStudentId(idInput)): #sets studentNumber to scanned card currentStudent.setStudentNumber(idInput) print("Connecting to ", host) posSocket = socket.socket() posSocket.connect((host, port)) currentStudent.setHasG2G(reportId(idInput,posSocket, host, port, responseSize)) if(currentStudent.hasG2G): #Red light redLight.on() greenLight.off() else: #scan RFID idInput = readKeyboards(rfidKeyboard, magneticKeyboard) while(not(currentStudent.isInputRFID(idInput))): redLight.on() greenLight.on() idInput = readKeyboards(rfidKeyboard, magneticKeyboard) redLight.off() greenLight.on() reportRfid(idInput, posSocket, host, port) #RFID first workflow elif(currentStudent.isInputRFID(idInput)): currentStudent.setRFIDCode(idInput) idInput=readKeyboards(rfidKeyboard, magneticKeyboard) while(not(currentStudent.isInputStudentId(idInput))): redLight.on() greenLight.on() idInput = readKeyboards(rfidKeyboard, magneticKeyboard) print("Connecting to ", host) posSocket = socket.socket() posSocket.connect((host, port)) currentStudent.setStudentNumber(idInput) currentStudent.setHasG2G(reportId(idInput, posSocket, host, port, responseSize)) if(currentStudent.hasG2G): greenLight.off() redLight.on() else: redLight.off() greenLight.on() reportRfid(currentStudent.RFIDCode,posSocket, host, port) else: redLight.on() greenLight.on() print("closing connection with", host) posSocket.close()
a = 0 a_zaehler += 1 c_straße = (100, 100, 100, 255) c_fence = (255, 5, 5, 255) c_finish = (255, 255, 5, 255) zaehler = 0 player_1 = pygame.Rect(100, 165, 20, 20) image_1 = pygame.image.load("car_1.png") player_2 = pygame.Rect(100, 195, 20, 20) image_2 = pygame.image.load("car_2.png") #lights l1 = light(shade, "images/light2_2.png") l2 = light(shade, "images/light2_2.png") explosion = pygame.image.load("explosion.png") # Variablen: Spieler 1 pressed_1 = "false" pressed_1_l = "false" pressed_1_r = "false" pressed_1_b = "false" # Back - Rückwärts bew_zaehler_1 = 0 winkel_1 = 0 destroy_1 = 0 count_destr_1 = 0
homepath = '/home/pi/' print homepath print os.path.exists(homepath + '/autopi.config') if not os.path.exists(homepath + '/autopi.config'): print 'no user info' root = Tk() root.wm_title('AutoPi Login') app = registerGUI(root,web) root.mainloop() print 'Web' print web pi = raspberryPi(web) light = light() cam = camera() alarm = alarm() blind = blinds() reg = register(web,pi,light,cam,alarm,blind) else: config = ConfigParser.ConfigParser() config.read(homepath+'/autopi.config') username = config.get('LoginInfo','username') password = config.get('LoginInfo','password') print 'working' web.setUsername(username) web.setPassword(password) web.setAuth() pi = raspberryPi(web) if not pi.response: