mirror of https://github.com/rusefi/rusefi-1.git
dc motor api (#2869)
* iwpm * dc motor has configure * consume * format * spelling
This commit is contained in:
parent
c1178a0464
commit
cd055a687d
|
@ -31,7 +31,7 @@ private:
|
|||
SimplePwm m_pwmDir2;
|
||||
|
||||
public:
|
||||
DcHardware() : dcMotor(&m_pwmEnable, &m_pwmDir1, &m_pwmDir2, &m_disablePin) {}
|
||||
DcHardware() : dcMotor(m_disablePin) {}
|
||||
|
||||
TwoPinDcMotor dcMotor;
|
||||
|
||||
|
@ -83,6 +83,8 @@ public:
|
|||
0
|
||||
);
|
||||
#endif /* EFI_UNIT_TEST */
|
||||
|
||||
dcMotor.configure(m_pwmEnable, m_pwmDir1, m_pwmDir2);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -10,15 +10,18 @@
|
|||
#include "efi_gpio.h"
|
||||
#include "pwm_generator_logic.h"
|
||||
|
||||
TwoPinDcMotor::TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2, OutputPin* disablePin)
|
||||
: m_enable(enable)
|
||||
, m_dir1(dir1)
|
||||
, m_dir2(dir2)
|
||||
, m_disable(disablePin)
|
||||
TwoPinDcMotor::TwoPinDcMotor(OutputPin& disablePin)
|
||||
: m_disable(&disablePin)
|
||||
{
|
||||
disable();
|
||||
}
|
||||
|
||||
void TwoPinDcMotor::configure(IPwm& enable, IPwm& dir1, IPwm& dir2) {
|
||||
m_enable = &enable;
|
||||
m_dir1 = &dir1;
|
||||
m_dir2 = &dir2;
|
||||
}
|
||||
|
||||
void TwoPinDcMotor::enable() {
|
||||
if (m_disable) {
|
||||
m_disable->setValue(false);
|
||||
|
@ -49,6 +52,15 @@ bool TwoPinDcMotor::set(float duty)
|
|||
{
|
||||
m_value = duty;
|
||||
|
||||
// If not init, don't try to set
|
||||
if (!m_dir1 || !m_dir2 || !m_enable) {
|
||||
if (m_disable) {
|
||||
m_disable->setValue(true);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool isPositive = duty > 0;
|
||||
|
||||
if (!isPositive) {
|
||||
|
|
|
@ -38,7 +38,7 @@ public:
|
|||
virtual bool isOpenDirection() const = 0;
|
||||
};
|
||||
|
||||
class SimplePwm;
|
||||
struct IPwm;
|
||||
class OutputPin;
|
||||
|
||||
/**
|
||||
|
@ -71,20 +71,22 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
SimplePwm* const m_enable;
|
||||
SimplePwm* const m_dir1;
|
||||
SimplePwm* const m_dir2;
|
||||
IPwm* m_enable;
|
||||
IPwm* m_dir1;
|
||||
IPwm* m_dir2;
|
||||
OutputPin* const m_disable;
|
||||
float m_value = 0;
|
||||
|
||||
ControlType m_type = ControlType::PwmDirectionPins;
|
||||
public:
|
||||
/**
|
||||
* @param enable SimplePwm driver for enable pin, for PWM speed control.
|
||||
* @param enable IPwm driver for enable pin, for PWM speed control.
|
||||
* @param dir1 Enable 1 or direction 1 pin. Gets set high to rotate forward.
|
||||
* @param dir2 Enable 2 or direction 2 pin. Gets set high to rotate backward.
|
||||
*/
|
||||
TwoPinDcMotor(SimplePwm* enable, SimplePwm* dir1, SimplePwm* dir2, OutputPin* disable);
|
||||
TwoPinDcMotor(OutputPin& disable);
|
||||
|
||||
void configure(IPwm& enable, IPwm& dir1, IPwm& dir2);
|
||||
|
||||
virtual bool set(float duty) override;
|
||||
float get() const override;
|
||||
|
|
|
@ -117,11 +117,15 @@ private:
|
|||
|
||||
struct hardware_pwm;
|
||||
|
||||
class SimplePwm : public PwmConfig {
|
||||
struct IPwm {
|
||||
virtual void setSimplePwmDutyCycle(float dutyCycle) = 0;
|
||||
};
|
||||
|
||||
class SimplePwm : public PwmConfig, public IPwm {
|
||||
public:
|
||||
SimplePwm();
|
||||
explicit SimplePwm(const char *name);
|
||||
virtual void setSimplePwmDutyCycle(float dutyCycle);
|
||||
void setSimplePwmDutyCycle(float dutyCycle) override;
|
||||
pin_state_t pinStates[2];
|
||||
SingleChannelStateSequence sr[1];
|
||||
float _switchTimes[2];
|
||||
|
|
Loading…
Reference in New Issue