- pin_string, pin_value_string = self.arduino_device.readline().rstrip().split(',', 1)
- pin = int(pin_string)
- pin_value = int(pin_value_string)
- print dt.datetime.now(), 'Pin: %d, Value: %d' % (pin, pin_value)
- try:
- print "sensor-update %s %d" % (self.values[pin], (pin_value * 100) / 1024)
- self.scratch_sender.send_scratch_command("sensor-update %s %d" % (self.values[pin], (pin_value * 100) / 1024))
- except KeyError:
- # Do nothing
- pass
- try:
- print "broadcast %s" % self.instruments[pin]
- self.scratch_sender.send_scratch_command('broadcast %s' % self.instruments[pin])
- except KeyError:
- # Do nothing
- pass
+ device_line = self.arduino_device.readline()
+ if device_line :
+ instrument, instrument_value_string = device_line.rstrip().split(',', 1)
+ instrument_value = int(instrument_value_string)
+ logging.info('Instrument: %s, Value: %d' % (instrument, instrument_value))
+ if instrument in self.values:
+ try:
+ logging.info("sensor-update %s %d" % (self.values[instrument], (instrument_value * 100) / 1024))
+ self.scratch_sender.send_scratch_command("sensor-update %s %d" % (self.values[instrument], (instrument_value * 100) / 1024))
+ except KeyError:
+ # Do nothing
+ pass
+ if isinstance(self.instruments[instrument], dict):
+ broadcast = self.instruments[instrument][instrument_value]
+ else:
+ broadcast = self.instruments[instrument]
+ try:
+ logging.info("broadcast %s" % broadcast)
+ self.scratch_sender.send_scratch_command('broadcast %s' % broadcast)
+ except KeyError:
+ # Do nothing
+ pass