AP1017 library for the Rev.E hardware with expanded capabilities.
Fork of AP1017 by
Diff: AP1017.cpp
- Revision:
- 11:ac867fa4aa10
- Parent:
- 10:16d45e3f4be3
- Child:
- 12:bebb667c182f
--- a/AP1017.cpp Wed Nov 08 21:37:24 2017 +0000 +++ b/AP1017.cpp Tue May 01 21:28:57 2018 +0000 @@ -3,27 +3,21 @@ /******************** Constructors & Destructors ****************************/ // Default constructor -AP1017::AP1017(DigitalOut* A, DigitalOut* B, I2C* M) : motorOn(false), dutyCycle(0.0) +AP1017::AP1017(DigitalOut* InputA, DigitalOut* InputB, DigitalOut* Enable) : motorOn(false), dutyCycle(0.0) { - i2cMotor = M; - inA = A; - inB = B; - - // Instantiate TCA9554A - motor = new TCA9554A(i2cMotor, TCA9554A::SLAVE_ADDRESS_38H); // 38H->Port 0->RSV + inA = InputA; + inB = InputB; + en = Enable; // Initialize RSV as output - if (motor->configurePort(TCA9554A::PORT_0, TCA9554A::DIR_OUTPUT)!= TCA9554A::SUCCESS) { - MSG("#AP1017: Error configuring TCA9554A port.\r\n"); - } - motor->setPortLevel(TCA9554A::PORT_0, TCA9554A::LOW); // Turn motor off + en->write(0); // Turn motor off } // Default destructor AP1017::~AP1017(void) { stop(); - delete inA, inB, motor, i2cMotor; + delete inA, inB, en; } /*********************** Member Functions ***********************************/ @@ -99,7 +93,7 @@ } -AP1017::Status AP1017::setSpeed(float dc) +AP1017::Status AP1017::setSpeed(double dc) { if((dc <= 100.0) && (dc >= 0.0)) { @@ -120,7 +114,7 @@ } -float AP1017::getSpeed(void) +double AP1017::getSpeed(void) { MSG("Speed: %.1f%%\r\n.", dutyCycle*100.0); return dutyCycle*100.0; @@ -129,7 +123,7 @@ AP1017::Status AP1017::start(void) { - motor->setPortLevel(TCA9554A::PORT_0, TCA9554A::HIGH); // set RSV high + en->write(1); motorOn = true; // Set ON flag return SUCCESS; @@ -138,7 +132,7 @@ AP1017::Status AP1017::stop(void) { - motor->setPortLevel(TCA9554A::PORT_0, TCA9554A::LOW); // set RSV low + en->write(0); // set RSV low motorOn = false; // Set OFF flag return SUCCESS;