Пример #1
0
 def test_FirmataInit(self):
     self._port.data = FIRMATA_INIT[:] + ARDUINO_CAPABILITY[:] + ARDUINO_ANALOG_MAPPING[:] + ARDUINO_BOARD_STATE[:]
     board = firmata.Board('',
                           10,
                           log_to_file='/tmp/testlog',
                           start_serial=True)
     board.join(timeout=2)
     board.StopCommunications()
     self.assertEqual(board.pin_mode[2], 1)
     self.assertEqual(board.pin_mode[3], 1)
     self.assertEqual(board.pin_mode[4], 1)
     self.assertEqual(board.pin_mode[5], 1)
     self.assertEqual(board.pin_mode[6], 1)
     self.assertEqual(board.pin_mode[7], 1)
     self.assertEqual(board.pin_mode[8], 1)
     self.assertEqual(board.pin_mode[9], 1)
     self.assertEqual(board.pin_mode[10], 1)
     self.assertEqual(board.pin_mode[11], 1)
     self.assertEqual(board.pin_mode[12], 1)
     self.assertEqual(board.pin_mode[13], 1)
     self.assertEqual(board.pin_mode[14], 2)
     self.assertEqual(board.pin_mode[15], 2)
     self.assertEqual(board.pin_mode[16], 2)
     self.assertEqual(board.pin_mode[17], 2)
     self.assertEqual(board.pin_mode[18], 2)
     self.assertEqual(board.pin_mode[19], 2)
     for i in xrange(2, 19):
         self.assertEqual(board.pin_state[i], 0)
Пример #2
0
 def test_QueryBoardState(self):
     self._port.data = FIRMATA_INIT[:] + ARDUINO_CAPABILITY[:] + ARDUINO_ANALOG_MAPPING[:]
     self.board = firmata.Board('', 10, log_to_file=None, start_serial=True)
     for i in xrange(20):
         self.board.QueryPinState(i)
     self.board.join(timeout=1)
     self.board.StopCommunications()
     self.assertEqual(
         self._port.output,
         [
             # 0xF0 (START_SYSEX), 0X6D (PIN_STATE_QUERY), pin, 0XF7 (END_SYSEX)
             '\xf0\x6d\x00\xf7',
             '\xf0\x6d\x01\xf7',
             '\xf0\x6d\x02\xf7',
             '\xf0\x6d\x03\xf7',
             '\xf0\x6d\x04\xf7',
             '\xf0\x6d\x05\xf7',
             '\xf0\x6d\x06\xf7',
             '\xf0\x6d\x07\xf7',
             '\xf0\x6d\x08\xf7',
             '\xf0\x6d\x09\xf7',
             '\xf0\x6d\x0a\xf7',
             '\xf0\x6d\x0b\xf7',
             '\xf0\x6d\x0c\xf7',
             '\xf0\x6d\x0d\xf7',
             '\xf0\x6d\x0e\xf7',
             '\xf0\x6d\x0f\xf7',
             '\xf0\x6d\x10\xf7',
             '\xf0\x6d\x11\xf7',
             '\xf0\x6d\x12\xf7',
             '\xf0\x6d\x13\xf7',
         ])
Пример #3
0
 def test_basicDigitalWrite(self):
     """Test basic functionality of digitalWrite()."""
     self._port.data = FIRMATA_INIT[:] + ARDUINO_CAPABILITY[:] + ARDUINO_ANALOG_MAPPING[:]
     board = firmata.Board('', 10, log_to_file=None, start_serial=True)
     board.digitalWrite(8, 0)
     board.join(timeout=1)
     board.StopCommunications()
     self.assertEqual(self._port.output, ['\x91\x00\x00'])
Пример #4
0
 def test_SetSamplingInterval(self):
     self._port.data = FIRMATA_INIT[:] + ARDUINO_CAPABILITY[:] + ARDUINO_ANALOG_MAPPING[:]
     board = firmata.Board('', 10, log_to_file=None, start_serial=True)
     board.SetSamplingInterval(1000)
     board.SetSamplingInterval()
     board.join(timeout=1)
     board.StopCommunications()
     self.assertEqual(self._port.output,
                      ['\xf0\x7a\x68\x07\xf7', '\xf0\x7a\x13\x00\xf7'])
Пример #5
0
 def test_digitalWriteHasNoAnalogLeaks(self):
     """Test that analog values don't leak into digitalWrite()."""
     self._port.data = FIRMATA_INIT[:] + ARDUINO_CAPABILITY[:] + ARDUINO_ANALOG_MAPPING[:] + ARDUINO_BOARD_STATE[:]
     board = firmata.Board('', 10, log_to_file=None, start_serial=True)
     board.pin_state[14] = 255  # Same pseudo-port as pin 8
     board.digitalWrite(8, 0)
     board.join(timeout=1)
     board.StopCommunications()
     print self._port.output
     self.assertEqual(self._port.output, ['\x91\x00\x00'])
Пример #6
0
 def test_digitalWriteDoesntLeakBits(self):
     """Test that digitalWrite() doesn't let one pin's value affect another's"""
     self._port.data = FIRMATA_INIT[:] + ARDUINO_CAPABILITY[:] + ARDUINO_ANALOG_MAPPING[:]
     board = firmata.Board('', 10, log_to_file=None, start_serial=True)
     board.pin_mode[14] = MODE_OUTPUT  # Lie
     board.pin_state[14] = 0xff  # Same pseudo-port as pin 8
     board.digitalWrite(8, 0)
     board.join(timeout=1)
     board.StopCommunications()
     self.assertEqual(self._port.output, ['\x91\x40\x00'])
Пример #7
0
    def test_OneTimeListener(self):
        """Test that DispatchToken() will properly delete listeners that request it"""
        board = firmata.Board('', 10, log_to_file=None, start_serial=False)

        def FakeListener(token):
            return (True, True)  # do delete, do abort processing

        FAKE_TOKEN = 'RESPONSE'
        board.AddListener(FAKE_TOKEN, FakeListener)
        token = {'token': FAKE_TOKEN}
        board.DispatchToken(token)
        self.assertEqual(board._listeners[FAKE_TOKEN], [])
Пример #8
0
 def test_Mondo(self):
     self._port.data = FIRMATA_INIT[:] + ARDUINO_CAPABILITY[:] + ARDUINO_ANALOG_MAPPING[:] + MONDO_DATA[:]
     board = firmata.Board('', 10, log_to_file=None, start_serial=True)
     board.join(timeout=1)
     board.StopCommunications()
     self.assertEqual(len(board.errors), 1)
     self.assertIn('RESERVED_COMMAND', board.errors[0])
     self.assertIn({0: 1, 1: 1, 4: 14}, board.pin_config)
     self.assertEqual(20, len(board.pin_config))
     self.assertEqual('5.2', board.firmware_version)
     self.assertEqual('Test', board.firmware_name)
     self.assertEqual(board.pin_state[13], 35)
     self.assertEqual(board.pin_state[2], True)
Пример #9
0
 def test_I2CWriteSend(self):
     """Test simple I2C write query is properly sent"""
     self._port.data = FIRMATA_INIT[:] + ARDUINO_CAPABILITY[:] + ARDUINO_ANALOG_MAPPING[:] + ARDUINO_BOARD_STATE[:]
     board = firmata.Board('', 10, log_to_file=None, start_serial=True)
     board.I2CConfig(0)
     board._i2c_device.I2CWrite(0x4f, 0x00,
                                [0x7f, 0xff])  # write 2 bytes to register 0
     board.join(timeout=1)
     board.StopCommunications()
     #                                    |    i2c config      |   | start | addr  |  reg  |   2 bytes     | end
     self.assertEqual(self._port.output, [
         '\xf0\x78\x00\x00\xf7',
         '\xf0\x76\x4f\x00\x00\x00\x7f\x00\x7f\x01\xf7'
     ])
Пример #10
0
    def test_I2CRead(self):
        """Test simple I2C read query is properly sent and reply lexxed"""
        self._port.data = FIRMATA_INIT[:] + ARDUINO_CAPABILITY[:] + ARDUINO_ANALOG_MAPPING[:] + ARDUINO_BOARD_STATE[:]
        board = firmata.Board('', 10, log_to_file=None, start_serial=True)
        board.I2CConfig(0)
        old_sysex = board.SendSysex

        def FakeSysex(*args, **kargs):
            self._port.data.extend(I2C_REPLY_MESSAGE[:])
            old_sysex(*args, **kargs)

        board.SendSysex = FakeSysex
        reply = board._i2c_device.I2CRead(0x4f, 0x00,
                                          2)  # read 2 bytes from register 0
        board.join(timeout=1)
        board.StopCommunications()
        #                            |    i2c config      |   | start | addr  |  reg  |   2   | end
        self.assertEqual(
            self._port.output,
            ['\xf0\x78\x00\x00\xf7', '\xf0\x76\x4f\x08\x00\x00\x02\x00\xf7'])
        self.assertEqual(reply, I2C_REPLY_DICT['data'])
Пример #11
0
 def test_StringData(self):
     self._port.data = FIRMATA_INIT[:] + ARDUINO_CAPABILITY[:] + ARDUINO_ANALOG_MAPPING[:] + FIRMATA_STRING_DATA[:]
     board = firmata.Board('', 10, log_to_file=None, start_serial=True)
     board.join(timeout=1)
     board.StopCommunications()
     self.assertEqual(board.errors, ['Hello'])