def configure_ht0740(self): self._log.warning('configure ht0740...') from lib.switch import Switch self._log.info('configuring switch...') self._ros._switch = Switch(Level.INFO) # since we're using the HT0740 Switch we need to turn it on to enable # the sensors that rely upon its power # self._ros._switch.enable() self._ros._switch.on()
def start(self): """ Ejecuta el comando y mira si tiene que ejecutarlo localmente o se tiene que ejecutar en otro host. """ tmp_exec = {'out': None, 'err': None} if self.__is_command_exist(): with Switch(self.location) as case: if case(EnumLocationExec.local): tmp_exec = self.__execute_local() elif case(EnumLocationExec.remote): tmp_exec = self.__execute_remote() return tmp_exec['out'], tmp_exec['err'], tmp_exec['code'], tmp_exec[ 'exception']
def run(self): self.pi_setup() switch_obj = Switch(self, Water_System.push_button) switch_obj.run(Water_System.led) thread1 = threading.Thread(target=self.data_generator.monitor_data, name="thread1", args=(self.lock, ), daemon=True) thread1.start() try: while True: pass except KeyboardInterrupt: return
def Risposta(r): risultato = r # Inizializzazione risultato clear = False # Inizializzazione variabile operators = ['×', '÷', '+', '-', '√'] # Lista degli operatori while not clear: # Finchè l'espressione non è stata analizzata tutta, allora... for operator in operators: # ... per ogni operatore della lista operators ... trovato = r.find(operator) # trova l'operatore nella stringa if trovato != -1: # Se l'operatore è stato trovato... l = r.split(operator) # Dividi la stringa in base all'operatore if operator == "-" and not l[0]: # Se l'operatore è il - e se l'elemento in prima posizione # dell'espressione è vuoto (ad esempio: -2-1 --> l = ["", "2", "1"] del l[0] # elimina quell'elemento l[0] = -float(l[0]) # trasforma il nuovo primo elemento in un float (numero decimale) negativo for p, e in enumerate(l): # Per ogni elemento (e la sua posizione) nell'espressione: if type(e) == str: # se l'elemento attuale è una stringa ... e = e.replace(",", ".") # ... sostituisci tutte le virgole con dei punti (per la trasformazione in stringa) l[p] = float(e) # Trasforma l'elemento in float with Switch(operator) as case: # Switch (controlla che l'operatore sia uguale a... if case(operators[0]): # Primo operatore nella lista (multiply) + calcolo risultato = 1 for x in l: risultato = risultato * x elif case(operators[1]): # Secondo operatore nella lista (divide) + calcolo risultato = l[0] for p, x in enumerate(l): if p == 0: continue risultato = risultato / x elif case(operators[2]): # Terzo operatore nella lista (plus) + calcolo risultato = sum(l) elif case(operators[3]): # Quarto operatore nella lista (minus) + calcolo for p, e in enumerate(l): if p != 0 and float(e) > 0: l[p] = -float(e) risultato = sum(l) elif case(operators[4]): # Quinto operatore nella lista (square root) + calcolo risultato = math.sqrt(float(l[1])) clear = True # Quando il ciclo è concluso, imposta la variabile clear a True # (l'espressione è stata analizzata) salvaInCronologia(r, risultato) # Salva nella cronologia l'espressione e il risultato return risultato
def update(self, key: str, option: str, value) -> bool: """ Actualiza alguna de las propiedades de un return que ya existe. :param key: Key del return :param option: Nombre de la opción. :param value: Nuevo valor. :return: True si todo ha ido bien y False si algo ha fallado. """ if key: with Switch(option, invariant_culture_ignore_case=True) as case: if case("status", "message", "send", "other_data"): if self.is_exist(key): self.__dict_return[key][option] = value return True else: # Opción no valida!! pass return False
def resetIdleCountdown(): settings.lastMotionEndTime = None def onMotionSwitchChange(value): if (value): light.switchOn() resetIdleCountdown() if (app.is_running == False): app.start() print("Started") else: light.switchOff() settings.lastMotionEndTime = time.time() Switch(15, onMotionSwitchChange) while True: if (is_idle()): idle = calcSecondsIdle() print(idle) if (idle >= settings.maxIdleSeconds): resetIdleCountdown() app.stop() print("Stopped") time.sleep(1) GPIO.cleanup()
def _configure(self): ''' Configures ROS based on both KR01 standard hardware as well as optional features, the latter based on devices showing up (by address) on the I²C bus. Optional devices are only enabled at startup time via registration of their feature availability. ''' scanner = I2CScanner(Level.WARN) self._addresses = scanner.getAddresses() hexAddresses = scanner.getHexAddresses() self._addrDict = dict( list(map(lambda x, y: (x, y), self._addresses, hexAddresses))) for i in range(len(self._addresses)): self._log.debug( Fore.BLACK + Style.DIM + 'found device at address: {}'.format(hexAddresses[i]) + Style.RESET_ALL) self._log.info('configure default features...') # standard devices ........................................... self._log.info('configuring integrated front sensors...') self._ifs = IntegratedFrontSensor(self._config, self._queue, Level.INFO) self._log.info('configure ht0740 switch...') self._switch = Switch(Level.INFO) # since we're using the HT0740 Switch, turn it on to enable sensors that rely upon its power # self._switch.enable() self._switch.on() self._log.info('configuring button...') self._button = Button(self._config, self.get_message_queue(), self._mutex) self._log.info('configure battery check...') _battery_check = BatteryCheck(self._config, self.get_message_queue(), Level.INFO) self.add_feature(_battery_check) self._log.info('configure CPU temperature check...') _temperature_check = Temperature(self._config, self._queue, Level.INFO) self.add_feature(_temperature_check) ultraborg_available = (0x36 in self._addresses) if ultraborg_available: self._log.debug(Fore.CYAN + Style.BRIGHT + '-- UltraBorg available at 0x36.' + Style.RESET_ALL) else: self._log.debug(Fore.RED + Style.BRIGHT + '-- no UltraBorg available at 0x36.' + Style.RESET_ALL) self._set_feature_available('ultraborg', ultraborg_available) thunderborg_available = (0x15 in self._addresses) if thunderborg_available: # then configure motors self._log.debug(Fore.CYAN + Style.BRIGHT + '-- ThunderBorg available at 0x15' + Style.RESET_ALL) _motor_configurer = MotorConfigurer(self, self._config, Level.INFO) self._motors = _motor_configurer.configure() else: self._log.debug(Fore.RED + Style.BRIGHT + '-- no ThunderBorg available at 0x15.' + Style.RESET_ALL) self._set_feature_available('thunderborg', thunderborg_available) # optional devices ........................................... # the 5x5 RGB Matrix is at 0x74 for port, 0x77 for starboard rgbmatrix5x5_stbd_available = (0x74 in self._addresses) if rgbmatrix5x5_stbd_available: self._log.debug(Fore.CYAN + Style.BRIGHT + '-- RGB Matrix available at 0x74.' + Style.RESET_ALL) else: self._log.debug(Fore.RED + Style.BRIGHT + '-- no RGB Matrix available at 0x74.' + Style.RESET_ALL) self._set_feature_available('rgbmatrix5x5_stbd', rgbmatrix5x5_stbd_available) rgbmatrix5x5_port_available = (0x77 in self._addresses) if rgbmatrix5x5_port_available: self._log.debug(Fore.CYAN + Style.BRIGHT + '-- RGB Matrix available at 0x77.' + Style.RESET_ALL) else: self._log.debug(Fore.RED + Style.BRIGHT + '-- no RGB Matrix available at 0x77.' + Style.RESET_ALL) self._set_feature_available('rgbmatrix5x5_port', rgbmatrix5x5_port_available) if rgbmatrix5x5_stbd_available or rgbmatrix5x5_port_available: self._log.info('configure rgbmatrix...') self._rgbmatrix = RgbMatrix(Level.INFO) self.add_feature(self._rgbmatrix) # FIXME this is added twice # ............................................ # the 11x7 LED matrix is at 0x75 for starboard, 0x77 for port. The latter # conflicts with the RGB LED matrix, so both cannot be used simultaneously. matrix11x7_stbd_available = (0x75 in self._addresses) if matrix11x7_stbd_available: self._log.debug(Fore.CYAN + Style.BRIGHT + '-- 11x7 Matrix LEDs available at 0x75.' + Style.RESET_ALL) else: self._log.debug(Fore.RED + Style.BRIGHT + '-- no 11x7 Matrix LEDs available at 0x75.' + Style.RESET_ALL) self._set_feature_available('matrix11x7_stbd', matrix11x7_stbd_available) # device availability ........................................ bno055_available = (0x28 in self._addresses) if bno055_available: self._log.info('configuring BNO055 9DoF sensor...') self._bno055 = BNO055(self._config, self.get_message_queue(), Level.INFO) else: self._log.debug(Fore.RED + Style.BRIGHT + 'no BNO055 orientation sensor available at 0x28.' + Style.RESET_ALL) self._set_feature_available('bno055', bno055_available) # NOTE: the default address for the ICM20948 is 0x68, but this conflicts with the PiJuice icm20948_available = (0x69 in self._addresses) if icm20948_available: self._log.debug(Fore.CYAN + Style.BRIGHT + 'ICM20948 available at 0x69.' + Style.RESET_ALL) else: self._log.debug(Fore.RED + Style.BRIGHT + 'no ICM20948 available at 0x69.' + Style.RESET_ALL) self._set_feature_available('icm20948', icm20948_available) lsm303d_available = (0x1D in self._addresses) if lsm303d_available: self._log.debug(Fore.CYAN + Style.BRIGHT + 'LSM303D available at 0x1D.' + Style.RESET_ALL) else: self._log.debug(Fore.RED + Style.BRIGHT + 'no LSM303D available at 0x1D.' + Style.RESET_ALL) self._set_feature_available('lsm303d', lsm303d_available) vl53l1x_available = (0x29 in self._addresses) if vl53l1x_available: self._log.debug(Fore.CYAN + Style.BRIGHT + 'VL53L1X available at 0x29.' + Style.RESET_ALL) else: self._log.debug(Fore.RED + Style.BRIGHT + 'no VL53L1X available at 0x29.' + Style.RESET_ALL) self._set_feature_available('vl53l1x', vl53l1x_available) as7262_available = (0x49 in self._addresses) if as7262_available: self._log.debug(Fore.CYAN + Style.BRIGHT + '-- AS7262 Spectrometer available at 0x49.' + Style.RESET_ALL) else: self._log.debug(Fore.RED + Style.BRIGHT + '-- no AS7262 Spectrometer available at 0x49.' + Style.RESET_ALL) self._set_feature_available('as7262', as7262_available) pijuice_available = (0x68 in self._addresses) if pijuice_available: self._log.debug(Fore.CYAN + Style.BRIGHT + 'PiJuice hat available at 0x68.' + Style.RESET_ALL) else: self._log.debug(Fore.RED + Style.BRIGHT + 'no PiJuice hat available at 0x68.' + Style.RESET_ALL) self._set_feature_available('pijuice', pijuice_available) self._log.info('configured.')