diff --git a/examples/two-motors.py b/examples/two-motors.py index 6449008..9a01988 100644 --- a/examples/two-motors.py +++ b/examples/two-motors.py @@ -1,31 +1,31 @@ -import time -from drv8830 import DRV8830, I2C_ADDR1, I2C_ADDR2 - - -left = DRV8830(I2C_ADDR1) -right = DRV8830(I2C_ADDR2) - -# Move forward -left.forward() -right.forward() -time.sleep(1.0) - -# Turn left -left.reverse() -right.forward() -time.sleep(1.0) - -# Turn right -left.forward() -right.reverse() -time.sleep(1.0) - -# Move backward -left.reverse() -right.reverse() -time.sleep(1.0) - -# Coast to a stop -left.coast() -right.coast() +import time +from drv8830 import DRV8830, I2C_ADDR1, I2C_ADDR2 + + +left = DRV8830(I2C_ADDR1) +right = DRV8830(I2C_ADDR2) + +# Move forward +left.forward() +right.forward() +time.sleep(1.0) + +# Turn left +left.reverse() +right.forward() +time.sleep(1.0) + +# Turn right +left.forward() +right.reverse() +time.sleep(1.0) + +# Move backward +left.reverse() +right.reverse() +time.sleep(1.0) + +# Coast to a stop +left.coast() +right.coast() time.sleep(1.0) \ No newline at end of file diff --git a/library/tests/test_features.py b/library/tests/test_features.py index 5f35333..f19330d 100644 --- a/library/tests/test_features.py +++ b/library/tests/test_features.py @@ -1,65 +1,65 @@ -from i2cdevice import MockSMBus - - -def test_forward(): - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - drv8830.forward() - - -def test_reverse(): - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - drv8830.reverse() - - -def test_brake(): - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - drv8830.brake() - - -def test_coast(): - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - drv8830.coast() - - -def test_set_outputs(): - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - drv8830.set_outputs(out1=0, out2=0) - - -def test_set_voltage(): - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - drv8830.set_voltage(5.06) - assert drv8830.get_voltage() == 5.06 - - -def test_set_voltage_snap(): - # Should snap to the nearest available voltage and read back correctly - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - drv8830.set_voltage(0.82) - assert drv8830.get_voltage() == 0.80 - - -def test_voltage_out_of_range(): - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - drv8830.set_voltage(0) - assert drv8830.get_voltage() == 0 - - -def test_get_fault(): - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - assert drv8830.get_fault().current_limit == 0 - - -def test_clear_fault(): - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - drv8830.clear_fault() +from i2cdevice import MockSMBus + + +def test_forward(): + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + drv8830.forward() + + +def test_reverse(): + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + drv8830.reverse() + + +def test_brake(): + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + drv8830.brake() + + +def test_coast(): + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + drv8830.coast() + + +def test_set_outputs(): + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + drv8830.set_outputs(out1=0, out2=0) + + +def test_set_voltage(): + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + drv8830.set_voltage(5.06) + assert drv8830.get_voltage() == 5.06 + + +def test_set_voltage_snap(): + # Should snap to the nearest available voltage and read back correctly + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + drv8830.set_voltage(0.82) + assert drv8830.get_voltage() == 0.80 + + +def test_voltage_out_of_range(): + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + drv8830.set_voltage(0) + assert drv8830.get_voltage() == 0 + + +def test_get_fault(): + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + assert drv8830.get_fault().current_limit == 0 + + +def test_clear_fault(): + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + drv8830.clear_fault() diff --git a/library/tests/test_setup.py b/library/tests/test_setup.py index 728fb78..22f726f 100644 --- a/library/tests/test_setup.py +++ b/library/tests/test_setup.py @@ -1,19 +1,19 @@ -from i2cdevice import MockSMBus - - -def test_setup(): - from drv8830 import DRV8830 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - del drv8830 - - -def test_setup_alt_addr2(): - from drv8830 import DRV8830, I2C_ADDR2 - drv8830 = DRV8830(i2c_dev=MockSMBus(1), i2c_addr=I2C_ADDR2) - del drv8830 - - -def test_setup_alt_addr3(): - from drv8830 import DRV8830, I2C_ADDR3 - drv8830 = DRV8830(i2c_dev=MockSMBus(1)) - drv8830.select_i2c_address(I2C_ADDR3) +from i2cdevice import MockSMBus + + +def test_setup(): + from drv8830 import DRV8830 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + del drv8830 + + +def test_setup_alt_addr2(): + from drv8830 import DRV8830, I2C_ADDR2 + drv8830 = DRV8830(i2c_dev=MockSMBus(1), i2c_addr=I2C_ADDR2) + del drv8830 + + +def test_setup_alt_addr3(): + from drv8830 import DRV8830, I2C_ADDR3 + drv8830 = DRV8830(i2c_dev=MockSMBus(1)) + drv8830.select_i2c_address(I2C_ADDR3)