def registrate(): global Conf, MyThread if not Conf['input']: return False if Conf['fd'] != None: return True Conf['input'] = False if (Conf['type'] == None) or (Conf['type'][0:5].lower() != 'dylos'): MyLogger.log(modulename,'ERROR','Incorrect Dylos type: %s' % Conf['type']) return False if not open_serial(): return False Conf['input'] = True if MyThread == None: # only the first time MyThread = MyThreading.MyThreading( # init the class bufsize=Conf['bufsize'], interval=Conf['interval'], name='Dylos PM sensor', callback=Add, conf=Conf, sync=Conf['sync'], DEBUG=Conf['debug']) # first call is interval secs delayed by definition try: if MyThread.start_thread(): # start multi threading return True except: pass MyThread = None raise IOError("Unable to registrate/start Dylos thread.") Conf['input'] = False return False
def registrate(): global Conf, MyThread if not Conf['input']: return False if Conf['fd'] != None: return True Conf['input'] = False if (Conf['type'] == None) or (Conf['type'][0:7].lower() != 'arduino'): return False Conf['keys'] = [] if type(Conf['names']) is list: for i in range(0,len(Conf['fields'])): Conf['keys'].append("%s_%s" % (Conf['names'][i],Conf['units'][i].replace('#',''))) if not open_serial(): return False Conf['input'] = True if MyThread == None: # only the first time MyThread = MyThreading.MyThreading( # init the class bufsize=Conf['bufsize'], interval=Conf['interval'], name='Arduino PM sensors', callback=Add, conf=Conf, sync=Conf['sync'], DEBUG=Conf['debug']) # first call is interval secs delayed by definition try: if MyThread.start_thread(): # start multi threading return True except: pass MyThread = None raise IOError("Unable to registrate/start Arduino input thread.") Conf['input'] = False return False
def __init__(self, can, poids, coeff, py0, px0): self.can = can; self.poids = poids self.py0 = py0 self.px0 = px0 self.py = py0 self.px = px0 self.coeff = coeff self.moov = 0 self.thread = MyThreading(self)
def registrate(): global Conf, MyThread if (not Conf['input']): return False if ('fd' in Conf.keys()) and (Conf['fd'] != None): return True for key in ['i2c','sensitivity']: # handle configured arrays of values if (key in Conf.keys()) and (type(Conf[key]) is str): Conf[key] = Conf[key].replace(' ','') Conf[key] = Conf[key].replace('],[','#') Conf[key] = Conf[key].replace('[','') Conf[key] = Conf[key].replace(']','') if key == 'i2c': Conf[key] = Conf[key].split(',') else: Conf[key] = Conf[key].split('#') for i in range(0,len(Conf[key])): Conf[key][i] = [int(a) for a in Conf[key][i].split(',')] Conf['input'] = False; Conf['fd'] = [] for gas in range(0,len(Conf['i2c'])): Conf['fd'].append(None) if not int(Conf['i2c'][gas],0) in [0x48]: # address pin 0-2 to null, read MyLogger.log(modulename,'ERROR',"I2C address %s not correct. Disabled." % Conf['i2c'][gas]) return False else: try: Conf['fd'][gas] = ADC(address=int(Conf['i2c'][gas],0)) except IOError: MyLogger.log(modulename,'WARNING','Try another I2C address.') continue Conf['input'] = True cnt = 0 if not len(MyThread): # only the first time for thread in range(0,len(Conf['fd'])): if Conf['fd'][thread] == None: continue MyThread.append(MyThreading.MyThreading( bufsize=int(Conf['bufsize']), interval=int(Conf['interval']), name='Alpha Sense %s sensor' % Conf['fields'][gas].upper(), callback=Add, conf=Conf, sync=Conf['sync'], DEBUG=Conf['debug'])) # first call is interval secs delayed by definition try: if MyThread[gas].start_thread(): cnt += 1 continue except: MyThread[gas] = None if not cnt: MyLogger.log(modulename,'ERROR',"Unable to registrate/start AlphaSsense sensors thread(s).") Conf['input'] = False return False return True
def registrate(): global Conf, MyThread, IDLE, ACTIVE if not Conf['input']: return False if Conf['fd'] != None: return True Conf['input'] = False # pms5003 or pms7003 data telegrams if (Conf['type'] == None) or (not Conf['type'][-7:].lower() in ('pms7003', 'pms5003')): return False cnt = 0 for fld in Conf['fields']: # make sure fields and units are defined fnd = False for pm in PM_fields: if fld != pm[0]: continue fnd = True try: if Conf['units'][cnt][-2:] != 'qf': Conf['units'][cnt] = pm[1] except: Conf['units'].append(pm[1]) break if not fnd: MyLogger.log(modulename, 'FATAL', 'Unknown field: %s' % fld) return False Conf['Serial_Errors'] = 0 if not get_device(): # identify USB serial device return False if Conf['sample'] > Conf['interval']: Conf['sample'] = Conf['interval'] # go passive mode and switch fan on more as IDLE secs idle reading time # default on start put sensor module in active mode Conf['mode'] = ACTIVE if Conf['interval'] - Conf['sample'] >= IDLE: GoPassive(Conf) Conf['input'] = True if MyThread == None: # only the first time MyThread = MyThreading.MyThreading( # init the class bufsize=Conf['bufsize'], interval=Conf['interval'], name=Conf['type'], callback=Add, conf=Conf, sync=Conf['sync'], DEBUG=(True if Conf['debug'] > 0 else False)) # first call is interval secs delayed by definition try: if MyThread.start_thread(): # start multi threading return True except: pass MyThread = None raise IOError("Unable to registrate/start SDS011 thread.") Conf['input'] = False return False
def registrate(): global Conf, MyThread if (not Conf['input']): return False if 'fd' in Conf.keys(): return True Conf['input'] = False if (int(Conf['i2c'], 0) != 0x77) and (int(Conf['i2c'], 0) != 0x76): MyLogger.log(modulename, 'ERROR', "I2C address %s not correct. Disabled." % Conf['i2c']) Conf['Ada_import'] = None else: try: Conf['Ada_import'] = __import__('Adafruit_BME280') except ImportError: MyLogger.log(modulename, 'ERROR', "Unable to import BME Adafruit module. Disabled.") Conf['Ada_import'] = None try: Conf['fd'] = Conf['Ada_import'].BME280( mode=Conf['Ada_import'].BME280_OSAMPLE_8, address=int(Conf['i2c'], 0)) except IOError: MyLogger.log(modulename, 'WARNING', 'Try another I2C address.') if int(Conf['i2c'], 0) == 0x77: Conf['i2c'] = '0x76' else: Conf['i2c'] = '0x77' Conf['fd'] = Conf['Ada_import'].BME280( mode=Conf['Ada_import'].BME280_OSAMPLE_8, address=int(Conf['i2c'], 0)) if Conf['Ada_import'] == None: MyLogger.log(modulename, 'ERROR', "Configuration error.") return False Conf['input'] = True if MyThread == None: # only the first time MyThread = MyThreading.MyThreading(bufsize=int(Conf['bufsize']), interval=int(Conf['interval']), name='BME280 sensor', callback=Add, conf=Conf, sync=Conf['sync'], DEBUG=Conf['debug']) # first call is interval secs delayed by definition try: if MyThread.start_thread(): return True except: pass MyThread = None raise IOError("Unable to registrate/start BME280 sensor thread.") Conf['input'] = False return False
class ObjetDeLaVie: """Unobjet avec les propriete Newton""" def __init__(self, can, poids, coeff, py0, px0): self.can = can; self.poids = poids self.py0 = py0 self.px0 = px0 self.py = py0 self.px = px0 self.coeff = coeff self.moov = 0 self.thread = MyThreading(self) def shoot(self, vitesse, angle): self.angle = angle self.vitesse = vitesse self.vx = cos(self.angle * 0.0174) * vitesse self.vy = sin(self.angle * 0.0174) * vitesse self.tps = 0 self.thread.start() def deplace(self): self.moov = 1 if (self.vitesse > 2): if (self.py > 340): self.thread.stop() self.px0 = self.px self.py0 = 340 self.vitesse *= self.coeff self.shoot(self.vitesse, self.angle) if (self.px < -20): self.vx = -self.vx self.px = -20 self.angle = self.angle - 2*(self.angle - 90) self.px0 = -20 - self.px0 elif (self.px > 1000): self.vx = -self.vx self.px = 1000 self.angle = self.angle - 2*(self.angle - 90) self.px0 = 2*1000 - self.px0 if (self.px >= -20 and self.px <= 1000): self.px = self.vx*self.tps + self.px0 self.py = ((self.poids*9.81)/2)*self.tps*self.tps - self.vy*self.tps + self.py0 self.can.coords(self.image, self.px, self.py) self.tps += 0.018 else: self.moov = 0 self.thread.stop()
def registrate(): global Conf, MyThread if not Conf['input']: return False if ('mySerials' in Conf.keys()) and len(Conf['mySerials']): return True Conf['input'] = False # if (Conf['type'] == None) or (Conf['type'][6:].upper() != 'ULPSM'): # MyLogger.log(modulename,'ERROR','Incorrect Spec type: %s' % Conf['type']) # return False for key in ['serials', 'omits']: if (key in Conf.keys()) and (type(Conf[key]) is str): Conf[key] = Conf[key].replace(' ', '').split(',') if not open_serial(): return False if not len(MyThread): # only the first time for thread in range(0, len(Conf['mySerials'])): try: MyThread.append( MyThreading.MyThreading( # init the class bufsize=Conf['bufsize'], interval=Conf['interval'], name='%s' % Conf['mySerials'][thread]['gas'].upper(), callback=Add, conf=Conf['mySerials'][thread], sync=Conf['sync'], DEBUG=Conf['debug'])) # first call is interval secs delayed by definition try: # print("Start sensor thread for gas %s" % Conf['mySerials'][thread]['gas'].upper()) if MyThread[thread].start_thread( ): # start multi threading # print("and start next gas sensor") continue # else: print("start thread returned false") except: MyThread.pop() MyLogger.log(modulename, 'ERROR', 'failed to start Spec thread %d' % thread) except: pass if not len(MyThread): return False Conf['input'] = True return True
def registrate(): global Conf, MyThread if (not Conf['input']): return False if MyThread == None: # only the first time # DEBUG == True, print logging in thread # if sync is True do not start the sensor thread MyThread = MyThreading.MyThreading(bufsize=Conf['bufsize'], interval=Conf['interval'], name='Sensor', callback=Add, sync=Conf['sync'], DEBUG=True) # first call is interval secs delayed by definition try: if not MyThread.start_thread(): MyThread = None raise IOError("Unable to registrate for collecting data.") except: Conf['input'] = False return {} return True
def registrate(): global Conf, MyThread if (not Conf['input']): return False if 'fd' in Conf.keys(): return True Conf['input'] = False if Conf['port'] == None: MyLogger.log(modulename, 'ERROR', "Port not defined. Disabled.") elif Conf['port'].upper()[0] != 'A': MyLogger.log(modulename, 'ERROR', "Port %s not correct. Disabled." % Conf['port']) elif not int(Conf['port'][1]) in [0, 1, 2]: MyLogger.log(modulename, 'ERROR', "Loudness port nr number %s. Disabled." % Conf['port']) else: Conf['input'] = True Conf['fd'] = int(Conf['port'][1]) if MyThread == None: # only the first time MyThread = MyThreading.MyThreading(bufsize=Conf['bufsize'], interval=Conf['interval'], name='dB sensor', callback=Add, conf=Conf, sync=Conf['sync'], DEBUG=Conf['debug']) # first call is interval secs delayed by definition try: if MyThread.start_thread(): return True except: pass MyThread = None raise IOError("Unable to registrate/start Grove dB sensor thread.") Conf['input'] = False return False
def registrate(): global Conf, MyThread, DHT_types if (not Conf['input']): return False if 'fd' in Conf.keys(): return True Conf['input'] = False if (Conf['type'] == None) or ((Conf['pin'] == None) and (Conf['port'] == None)): MyLogger.log(modulename, 'ERROR', "Type or pin/port not defined. Disabled.") elif not Conf['type'].upper() in DHT_types.keys(): MyLogger.log(modulename, 'ERROR', "Type %s not correct. Disabled." % Conf['type']) elif Conf['pin'] != None: if not int(Conf['pin']) in [ 4, 5, 6, 12, 13, 17, 18, 22, 23, 24, 25, 26, 27 ]: MyLogger.log( modulename, 'ERROR', "GPIO pin number %s not correct. Disabled." % Conf['pin']) else: Conf['Ada_import'] = __import__('Adafruit_DHT') DHT_types = { 'DHT11': Conf['Ada_import'].DHT11, 'DHT22': Conf['Ada_import'].DHT22, # more precise as DHT11 'AM2302': Conf['Ada_import'].AM2302 # wired DHT22 } Conf['fd'] = DHT_types[Conf['type'].upper()] elif Conf['port'] != None: if (Conf['port'][0].upper() != 'D') or (not int(Conf['port'][1]) in range(0, 8)): MyLogger.log( modulename, 'ERROR', "Grove port number %s not correct. Disabled." % Conf['port']) else: Conf['Ada_import'] = __import__('grovepi') Conf['fd'] = 0 if Conf['type'].upper() == 'DHT11' else 1 Conf['port'] = int(Conf['port'][1]) if Conf['Ada_import'] == None: MyLogger.log(modulename, 'ERROR', "Pin or port configuration error.") return False Conf['input'] = True if MyThread == None: # only the first time MyThread = MyThreading.MyThreading(bufsize=int(Conf['bufsize']), interval=int(Conf['interval']), name='DHT sensor', callback=Add, conf=Conf, sync=Conf['sync'], DEBUG=Conf['debug']) # first call is interval secs delayed by definition try: if MyThread.start_thread(): return True except: pass MyThread = None raise IOError("Unable to registrate/start DHT sensor thread.") Conf['input'] = False return False