frequency change?
Fork of BridgeDriver by
Diff: BridgeDriver.cpp
- Revision:
- 6:d4afd3284a04
- Parent:
- 4:87768972db3f
- Child:
- 7:7dabd934ebe4
--- a/BridgeDriver.cpp Thu Jul 24 17:34:23 2014 +0000 +++ b/BridgeDriver.cpp Thu Jul 24 21:30:41 2014 +0000 @@ -49,8 +49,7 @@ } - - + BridgeDriver::~BridgeDriver(){ for(int i=0; i<4; i++){ if(_pwm[i]){ @@ -75,13 +74,13 @@ } } - void BridgeDriver::enablePwm(uint8_t enPwmA, uint8_t enPwmB, uint8_t enPwmC, uint8_t enPwmD){ enablePwm(BRIDGE_A, enPwmA); enablePwm(BRIDGE_B, enPwmB); enablePwm(BRIDGE_C, enPwmC); enablePwm(BRIDGE_D, enPwmD); } + void BridgeDriver::enablePwm(Bridges bridge, uint8_t enPwm){ int bNum = static_cast<int>(bridge); //numeric bridge if(enPwm == _pwm[bNum]){ @@ -104,6 +103,7 @@ enableBraking(BRIDGE_C, enBrakeC); enableBraking(BRIDGE_D, enBrakeD); } + void BridgeDriver::enableBraking(Bridges bridge, uint8_t enBrake) { _braking[static_cast<int>(bridge)] = enBrake; } @@ -118,9 +118,11 @@ return 0; } } + int BridgeDriver::forceBrake(Bridges bridge){ //force a specific motor to GND without changing braking default return static_cast<int>(drive(bridge, 0, 0)); } + int BridgeDriver::forceFloat(uint8_t ch){ //force a specific channel to float without changing braking default if( _pwm[(ch-1)/2]){ return -1; @@ -130,6 +132,7 @@ return *_d[ch-1] = 0; } } + int BridgeDriver::forceFloat(Bridges bridge){ //force a specific motor to float without changing braking default int bNum = static_cast<int>(bridge); //numeric bridge @@ -168,6 +171,7 @@ return !!state; } } + int BridgeDriver::drive(uint8_t ch, uint8_t on){ if( _pwm[(ch-1)/2]){ return -1; @@ -187,6 +191,7 @@ return *_d[ch-1] = 0; } } + float BridgeDriver::drive(Bridges bridge, float speed){ //speed from -1 to 1, speed of 0 will coast or brake depending on setting of _braking int bNum = static_cast<int>(bridge); //numeric bridge @@ -202,6 +207,7 @@ return drive(bridge, -1, -1*speed); } } + float BridgeDriver::drive(Bridges bridge, int8_t dir, float speed){ //dir: 1=fwd, -1=rev, 0=brake (regardless of setting of _braking //speed from 0 to 1, speed of 0 will coast or brake depending on setting of _braking