def setUpClass(self): ThunderBorg.DEFAULT_I2C_ADDRESS = 0x15 ThunderBorg.set_i2c_address(ThunderBorg.DEFAULT_I2C_ADDRESS) tb = ThunderBorg() tb.halt_motors() tb.set_both_leds(0, 0, 0) tb.set_led_battery_state(False) tb.set_comms_failsafe(False) tb.write_external_led_word(0, 0, 0, 0)
def test_set_i2c_address_with_address_range_invalid(self): """ Test that an exception is raised when the address is out of range. """ new_addr = 0x78 with self.assertRaises(ThunderBorgException) as cm: ThunderBorg.set_i2c_address(new_addr)
def test_config_with_auto_set_address(self): """ Test that ``auto_set_addr`` if set to ``True`` causes the API to find the first valid board and configure itself to that board. """ # First change the board address so it cannot be found at the # default address. new_addr = 0x70 ThunderBorg.set_i2c_address(new_addr) # Now instantiate ThunderBorg. tb = ThunderBorg(logger_name=self._LOG_FILENAME, log_level=logging.DEBUG, auto_set_addr=True)
def test_set_i2c_address_without_current_address(self): """ Test that the ThunderBorg.set_i2c_address() can set a different address. Scans address range to find current address. """ # Set a new address new_addr = 0x70 ThunderBorg.set_i2c_address(new_addr) found = ThunderBorg.find_board() found = found[0] if found else 0 msg = "Found address '0x{:02X}', should be '0x{:02X}'.".format( found, new_addr) self.assertEqual(found, new_addr, msg)
def test_set_i2c_address_with_current_address(self): """ Test that the ThunderBorg.set_i2c_address() can set a different address. The current address is provided. """ # Set a new address new_addr = 0x70 cur_addr = ThunderBorg.DEFAULT_I2C_ADDRESS ThunderBorg.set_i2c_address(new_addr, cur_addr=cur_addr) found = ThunderBorg.find_board() found = found[0] if found else 0 msg = "Found address '0x{:02X}', should be '0x{:02X}'.".format( found, new_addr) self.assertEqual(found, new_addr, msg)
def tearDown(self): ThunderBorg.set_i2c_address(ThunderBorg.DEFAULT_I2C_ADDRESS)