Ejemplo n.º 1
0
 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, []))
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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, []))
Ejemplo n.º 4
0
  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, []))
Ejemplo n.º 5
0
    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, []))
Ejemplo n.º 6
0
 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
Ejemplo n.º 7
0
 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, []))
Ejemplo n.º 8
0
  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, []))
Ejemplo n.º 9
0
  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]))
Ejemplo n.º 10
0
    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]))
Ejemplo n.º 11
0
  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
Ejemplo n.º 12
0
    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
Ejemplo n.º 13
0
 def netDisconnect(self):
   self.midiParser.reset()
   self.sendEvent(quEvent(quEvent.NET_OFFLINE, []))
   self.socket.close()
   self.online=False
Ejemplo n.º 14
0
 def netDisconnect(self):
     self.midiParser.reset()
     self.sendEvent(quEvent(quEvent.NET_OFFLINE, []))
     self.socket.close()
     self.online = False
Ejemplo n.º 15
0
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))
Ejemplo n.º 16
0
Archivo: App.py Proyecto: mhlyak/quPy
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))