def run(self): while True: input = sys.stdin.readline() if input.strip() == "exit": self.sendEvent(quEvent(quEvent.SYS_SHUTDOWN, [])) break elif input.strip() == "test": self.sendEvent(quEvent(quEvent.SYS_TEST, [])) else: event = quEvent.getEventNumber(input.strip()) if event == __doc__: sys.stderr.write("Unknown event name\n") else: self.sendEvent(quEvent(event, []))
def pollButton(self, buttonPin, isToggle, invert, onAction, offAction): # button is pushed down and held if (not self.btn_held[buttonPin]) and ((not GPIO.input(buttonPin) == GPIO.HIGH) and invert): self.btn_held[buttonPin] = True # if this is a not a toggle (so oneshot), or a toggle and ON is the required action, # send event if (not isToggle) or (not self.btn_toggle[onAction]): self.sendEvent(quEvent(onAction, [])) # otherwise, (toggle and OFF is required) send event else: self.sendEvent(quEvent(offAction, [])) # button is released if (self.btn_held[buttonPin]) and ((not GPIO.input(buttonPin) == GPIO.LOW) and invert): self.btn_held[buttonPin] = False
def run(self): while True: input = sys.stdin.readline() if (input.strip() == "exit"): self.sendEvent(quEvent(quEvent.SYS_SHUTDOWN, [])) break elif (input.strip() == "test"): self.sendEvent(quEvent(quEvent.SYS_TEST, [])) else: event = quEvent.getEventNumber(input.strip()) if (event == __doc__): sys.stderr.write("Unknown event name\n") else: self.sendEvent(quEvent(event, []))
def netConnect(self): ''' Connects via TCP/IP to the Qu console, going into a re-connect loop if the console is not reachable. ''' # might have been connected otherwise if (not self.online): # keep trying to connect constantly self.initSocket() while (not self.shutdownState): try: #sys.stderr.write("NET: connecting\n"); self.socket.connect((config.QU_HOSTNAME, config.QU_PORT)) self.online = True # ask the conosole to dump its status self.socket.sendall(qurawmidi.generateSystemStateRequest()) break except socket.error as emsg: #sys.stderr.write("NET: connect failed \n"); self.online = False time.sleep(self.RECONNECT_TIME) # if we ever got here and we're not dying, we are online if (not self.shutdownState): self.sendEvent(quEvent(quEvent.NET_ONLINE, []))
def pollButton(self, buttonPin, isToggle, invert, onAction, offAction): # button is pushed down and held if ((not self.btn_held[buttonPin]) and ((not GPIO.input(buttonPin) == GPIO.HIGH) and invert)): self.btn_held[buttonPin] = True # if this is a not a toggle (so oneshot), or a toggle and ON is the required action, # send event if ((not isToggle) or (not self.btn_toggle[onAction])): self.sendEvent(quEvent(onAction, [])) # otherwise, (toggle and OFF is required) send event else: self.sendEvent(quEvent(offAction, [])) #button is released if ((self.btn_held[buttonPin]) and ((not GPIO.input(buttonPin) == GPIO.LOW) and invert)): self.btn_held[buttonPin] = False
def run(self): while (True): time.sleep(self.internalInterval) self.sleepCounter += self.internalInterval if (self.shutdownState): break if (self.sleepCounter > self.KEEPALIVE_TIME): self.sendEvent(quEvent(quEvent.NET_KEEPALIVE, []))
def handleEvent(self, sender, event): ''' Handles incoming TAP events, ignores events from self and echoHandler ''' if (sender == self or sender.getName() == "ECO"): return() if ( event.getType() in self.timers.keys() ): self.timers[event.getType()].tap() delay = self.timers[event.getType()].getTime() # if there is a usable delay, send it out if ( delay > 0 ): self.sendEvent(quEvent(self.events[event.getType()], [delay]))
def handleEvent(self, sender, event): ''' Handles incoming TAP events, ignores events from self and echoHandler ''' if (sender == self or sender.getName() == "ECO"): return () if (event.getType() in self.timers.keys()): self.timers[event.getType()].tap() delay = self.timers[event.getType()].getTime() # if there is a usable delay, send it out if (delay > 0): self.sendEvent(quEvent(self.events[event.getType()], [delay]))
def handleMidiEvent(self, type, data): # TODO: implement tap delay values received from console here # FIXME: this should be in an extra class, since it is to be used also by other components # previous msg was note on, and note values are the same if ( type == midiStreamParser.NOTE_OFF and self.lastMidiType == midiStreamParser.NOTE_ON and self.lastMidiData[1] == data[1]): ## check for volume value and adjust event data accordingly if (self.lastMidiData[2] < 0x40): muteGrp = self.mute_grp_off else: muteGrp = self.mute_grp_on # search the event for that midi note for ev in muteGrp.keys(): if ( muteGrp[ev] == self.lastMidiData[1] ): self.sendEvent(quEvent(ev, [])) self.lastMidiData = data self.lastMidiType = type
def handleMidiEvent(self, type, data): # TODO: implement tap delay values received from console here # FIXME: this should be in an extra class, since it is to be used also by other components # previous msg was note on, and note values are the same if (type == midiStreamParser.NOTE_OFF and self.lastMidiType == midiStreamParser.NOTE_ON and self.lastMidiData[1] == data[1]): ## check for volume value and adjust event data accordingly if (self.lastMidiData[2] < 0x40): muteGrp = self.mute_grp_off else: muteGrp = self.mute_grp_on # search the event for that midi note for ev in muteGrp.keys(): if (muteGrp[ev] == self.lastMidiData[1]): self.sendEvent(quEvent(ev, [])) self.lastMidiData = data self.lastMidiType = type
def netDisconnect(self): self.midiParser.reset() self.sendEvent(quEvent(quEvent.NET_OFFLINE, [])) self.socket.close() self.online=False
def netDisconnect(self): self.midiParser.reset() self.sendEvent(quEvent(quEvent.NET_OFFLINE, [])) self.socket.close() self.online = False
def signal_term_handler(signal, frame): # use debug handler to initiate a proper shutdown in SIGTERM sys.stderr.write("APP: Received SIGTERM, sending SYS_SHUTDOWN to all handlers.\n") deb.sendEvent(quEvent(quEvent.SYS_SHUTDOWN))