예제 #1
0
 def run(self):
     print "starting bluetooth listener"
     while not sync.terminate.isSet():
         msg = self.readSock()
         if msg is None:
             continue
         logging.debug("bluetooth message: %s" % msg)
         self.live()
         if msg == 'RUN OK':
             self.running = True
             sync.runOK.set()
             continue
         if msg == 'STP OK':
             self.running = False
             sync.stopOK.set()
             continue
         if msg == 'RST OK':
             sync.resetOK.set()
             continue
         if msg == 'CAL OK':
             sync.calibrateOK.set()
             continue
         if msg == 'TRG ON':
             cmd = (command.TRG_ON, None)
             sync.putCommand(cmd)
             continue
         if msg == 'TRG OFF':
             cmd = (command.TRG_OFF, None)
             sync.putCommand(cmd)
             continue            
         if msg == 'RFI ON':            
             cmd = (command.RFI_ON, None)
             sync.putCommand(cmd)
             continue
         if msg == 'RFI OFF':            
             cmd = (command.RFI_OFF, None)
             sync.putCommand(cmd)
             continue
         m = re.search('POS (-?\d+\.\d+),(-?\d+\.\d+),(-?\d+\.\d+)', msg)
         if m:
             x = -float(m.group(3)); # FIXME: changed order of readings
             y = float(m.group(1));
             z = float(m.group(2));
             cmd = (command.SET_POS, (x,y,z))
             sync.putCommand(cmd)
             continue
         logging.warning("illegal message  '%s'" % msg)
     print "stopping bluetooth listener"
예제 #2
0
 def die(self):
     if not self.running:
         # avoid suicide before start
         self.watchdog = Timer(0.5, self.die)
         self.watchdog.start()
         return
     if self.alive:
         # see if someone will claim we are alive in the next second or so
         self.alive = False
         self.watchdog = Timer(0.5, self.die)
         self.watchdog.start()
     else:
         # ok, no one claimed we are alive, so we are probably dead
         cmd = (command.TRG_OFF, None)
         sync.putCommand(cmd)
         sync.disconnect.set()
         print "I'm dead :-("            
예제 #3
0
 def run(self):
     print "starting bluetooth listener"
     while self.alive and not sync.terminate.isSet():
         msg = self.readSock()
         if msg is None:
             continue
         logging.debug("bluetooth message: %s" % msg)
         if msg == 'ALIVE':
             self.live()
             continue
         if msg == 'RUN OK':
             sync.runOK.set()
             continue
         if msg == 'STP OK':
             sync.stopOK.set()
             continue
         if msg == 'RST OK':
             sync.resetOK.set()
             continue
         if msg == 'TRG ON':
             cmd = (command.TRG_ON, None)
             sync.putCommand(cmd)
             continue
         if msg == 'TRG OFF':
             cmd = (command.TRG_OFF, None)
             sync.putCommand(cmd)
             continue            
         m = re.search('POT (\d+)', msg)
         if m:
             pot = int(m.group(1)); 
             cmd = (command.SET_POT, pot)
             sync.putCommand(cmd)
             continue
         logging.warning("illegal message  '%s'" % msg)
     print "stopping bluetooth listener"
예제 #4
0
 def run(self):
     print "starting alsa listener"
     while not sync.terminate.isSet():
         if alsaseq.inputpending():
             event = alsaseq.input()
             evtype = event[0]
             pitch = event[7][1]
             if evtype == alsaseq.SND_SEQ_EVENT_NOTEON:
                 cmd = (PSH_NOTE, pitch)
             elif evtype == alsaseq.SND_SEQ_EVENT_NOTEOFF:
                 cmd = (POP_NOTE, pitch)
             elif evtype == alsaseq.SND_SEQ_EVENT_START:
                 cmd = (TRP_START, None)
             elif evtype == alsaseq.SND_SEQ_EVENT_STOP:
                 cmd = (TRP_STOP, None)
             elif evtype == alsaseq.SND_SEQ_EVENT_CLOCK:
                 cmd = (TRP_TICK, None)
             else:
                 continue
             sync.putCommand(cmd)
         else:
             time.sleep(0.005)
             continue
     print "stopping alsa listener"
예제 #5
0
 def die(self):
     self.alive = False
     cmd = (command.TRG_OFF, None)
     sync.putCommand(cmd)
     sync.disconnect.set()
     print "I'm dead :-("