Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of AP1017 by
Diff: AP1017.cpp
- Revision:
- 9:1ca7d16de1c4
- Parent:
- 8:bc70a421ef4c
- Child:
- 10:16d45e3f4be3
diff -r bc70a421ef4c -r 1ca7d16de1c4 AP1017.cpp
--- a/AP1017.cpp Wed May 03 18:55:18 2017 +0000
+++ b/AP1017.cpp Fri May 19 23:09:27 2017 +0000
@@ -1,23 +1,15 @@
#include "AP1017.h"
#include "debug.h"
-#define I2C_SPEED 400000
-
/******************** Constructors & Destructors ****************************/
// Default constructor
-AP1017::AP1017(void) : motorOn(false), dutyCycle(0.0)
+AP1017::AP1017(DigitalOut* A, DigitalOut* B, I2C* M) : motorOn(false), dutyCycle(0.0)
{
- // TODO: Move pin assignments to Ap1017Ctrl and pass references here
-
- //motor = new PwmOut(P0_10);
- inA = new DigitalOut(P0_11);
- inB = new DigitalOut(P0_9);
-
- // Instantiate I2C
- i2cMotor = new I2C(I2C_SDA0, I2C_SCL0);
- i2cMotor->frequency(I2C_SPEED);
-
+ i2cMotor = M;
+ inA = A;
+ inB = B;
+
// Instantiate TCA9554A
motor = new TCA9554A(i2cMotor, TCA9554A::SLAVE_ADDRESS_38H); // 38H->Port 0->RSV
@@ -93,16 +85,16 @@
AP1017::Status AP1017::setSpeed(float dc)
{
- if((dc <= 100.0) && (dc >= 0.0)){
+ if((dc <= 100.0) && (dc >= 0.0))
+ {
dutyCycle = dc/100.0;
- MSG("#AP1017.cpp: dutyCycle = %.1f%%\r\n", dc);
if(motorOn == true){
- //TODO
MSG("#AP1017.cpp: Changed running motor speed.\r\n");
}
}
- else{
+ else
+ {
dutyCycle = 0.0;
return ERROR_DUTY_CYCLE;
@@ -114,7 +106,6 @@
float AP1017::getSpeed(void)
{
- MSG("#AP1017.cpp: Speed = %.1f%%\r\n", dutyCycle);
return dutyCycle*100.0;
}
@@ -122,7 +113,6 @@
AP1017::Status AP1017::start(void)
{
motor->setPortLevel(TCA9554A::PORT_0, TCA9554A::HIGH); // set RSV high
- MSG("#AP1017.cpp: Motor: ON\r\n");
motorOn = true; // Set ON flag
return SUCCESS;
@@ -132,7 +122,6 @@
AP1017::Status AP1017::stop(void)
{
motor->setPortLevel(TCA9554A::PORT_0, TCA9554A::LOW); // set RSV low
- MSG("#AP1017.cpp: Motor: OFF\r\n");
motorOn = false; // Set OFF flag
return SUCCESS;
@@ -141,14 +130,12 @@
AP1017::Status AP1017::brake(void)
{
setDirection(DIRECTION_BRAKE);
- MSG("#AP1017.cpp: Motor: BRAKE\r\n");
return SUCCESS;
}
AP1017::Status AP1017::coast(void)
{
setDirection(DIRECTION_COAST);
- MSG("#AP1017.cpp: Motor: COAST\r\n");
return SUCCESS;
}
