Exemple #1
0
    def __init__(self, mainClass):
        self._logger = logging.getLogger('SnipsLedControl')
        self._logger.info('Initializing leds controller')

        self._mainClass = mainClass  # type: SnipsLedControl

        if self.INSTANCE is None:
            self.INSTANCE = self
        else:
            self._logger.fatal(
                'Trying to instanciate LedsController but instance already exists'
            )
            self._mainClass.onStop()

        self._params = self._mainClass.params
        self._hardware = self._mainClass.hardware
        self._interface = None
        self._running = False
        self._active = True if self._params.defaultState == 'on' else False

        if self._params.pattern == 'google':
            self._pattern = GoogleHomeLedPattern(self)
        elif self._params.pattern == 'alexa':
            self._pattern = AlexaLedPattern(self)
        else:
            self._pattern = CustomLedPattern(self)

        if not self.initHardware():
            self._logger.fatal("Couldn't start hardware")
            self._mainClass.onStop()
            return

        self._queue = Queue.Queue()
        self._thread = threading.Thread(target=self._run)
        self._thread.daemon = True
	def __init__(self, mainClass):
		self._logger = logging.getLogger('SnipsLedControl')
		self._logger.info('Initializing leds controller')

		self._mainClass = mainClass # type: SnipsLedControl

		if self.INSTANCE is None:
			self.INSTANCE = self
		else:
			self._logger.fatal('Trying to instanciate LedsController but instance already exists')
			self._mainClass.onStop()

		self._params 			= self._mainClass.params
		self._hardware 			= self._mainClass.hardware
		self._interface 		= None
		self._running 			= False
		self._defaultBrightness = self._params.defaultBrightness
		self._stickyAnimation 	= None

		self._active = threading.Event()
		if self._params.defaultState == 'on':
			self._active.set()
		else:
			self._active.clear()


		if not self.initHardware():
			self._logger.fatal("Couldn't start hardware")
			self._mainClass.onStop()
			return


		if self._params.pattern == 'google':
			self._pattern = GoogleHomeLedPattern(self)
		elif self._params.pattern == 'alexa':
			self._pattern = AlexaLedPattern(self)
		elif self._params.pattern == 'kiboost':
			self._pattern = KiboostLedPattern(self)
		elif self._params.pattern == 'projectalice':
			self._pattern = ProjectAlicePattern(self)
		else:
			self._pattern = CustomLedPattern(self)


		self._buttonsThread = None
		if 'extras' in self._hardware and 'buttons' in self.hardware['extras']:
			import RPi.GPIO
			RPi.GPIO.setmode(RPi.GPIO.BCM)
			for button in self._hardware['extras']['buttons']:
				RPi.GPIO.setup(int(self._hardware['extras']['buttons'][button]['bcm_gpio']), RPi.GPIO.IN)

			self._buttonsThread = threading.Thread(target=self._runButtons)
			self._buttonsThread.setDaemon(True)


		self._queue = Queue.Queue()
		self._animationThread = threading.Thread(target=self._runAnimation)
		self._animationThread.setDaemon(True)