Minor cleanup with enable and step polarity

This commit is contained in:
Rob Giseburt
2018-03-15 14:33:28 -05:00
parent 90f7003a69
commit 29abfa48ef
3 changed files with 34 additions and 19 deletions

View File

@@ -37,6 +37,7 @@ using Motate::pin_number;
using Motate::OutputPin;
using Motate::PWMOutputPin;
using Motate::kStartHigh;
using Motate::kStartLow;
using Motate::kNormal;
using Motate::Timeout;
@@ -61,13 +62,16 @@ struct StepDirStepper final : Stepper {
OutputPin<ms2_num> _ms2;
PWMOutputPin<vref_num> _vref;
ioMode _enable_polarity; // 0=active HIGH, 1=active LOW
ioMode _step_polarity; // IO_ACTIVE_LOW or IO_ACTIVE_HIGH
ioMode _enable_polarity; // IO_ACTIVE_LOW or IO_ACTIVE_HIGH
// sets default pwm freq for all motor vrefs (commented line below also sets HiZ)
StepDirStepper(ioMode enable_polarity = IO_ACTIVE_LOW, const uint32_t frequency = 250000) :
Stepper{enable_polarity},
StepDirStepper(ioMode step_polarity, ioMode enable_polarity, const uint32_t frequency = 250000) :
Stepper{},
_step{step_polarity==IO_ACTIVE_LOW?kStartHigh:kStartLow},
_enable{enable_polarity==IO_ACTIVE_LOW?kStartHigh:kStartLow},
_vref{kNormal, frequency},
_step_polarity{step_polarity},
_enable_polarity{enable_polarity}
{};
@@ -141,17 +145,17 @@ struct StepDirStepper final : Stepper {
};
void stepStart() override {
if (_invert_step)
_step.clear();
else
_step.set();
if (_step_polarity == IO_ACTIVE_LOW)
_step.clear();
else
_step.set();
};
void stepEnd() override {
if (_invert_step)
_step.set();
else
_step.clear();
if (_step_polarity == IO_ACTIVE_LOW)
_step.set();
else
_step.clear();
};
void setDirection(uint8_t new_direction) override {
@@ -170,7 +174,18 @@ struct StepDirStepper final : Stepper {
}
};
ioMode getEnablePolarity() override
ioMode getStepPolarity() const override
{
return _step_polarity;
};
void setStepPolarity(ioMode new_sp) override
{
_step_polarity = new_sp;
stepEnd();
};
ioMode getEnablePolarity() const override
{
return _enable_polarity;
};

View File

@@ -1050,7 +1050,7 @@ stat_t st_set_sp(nvObj_t *nv) // set motor step polarity
uint8_t motor = _get_motor(nv->index);
if (motor > MOTORS) { return STAT_INPUT_VALUE_RANGE_ERROR; };
Motors[motor]->setStepPolarity((int)nv->value);
Motors[motor]->setStepPolarity((ioMode)nv->value);
return (STAT_OK);
}
@@ -1148,7 +1148,7 @@ static const char fmt_0mi[] = "[%s%s] m%s microsteps%16d [1,2,4,8,16,32]\n";
static const char fmt_0su[] = "[%s%s] m%s steps per unit %17.5f steps per%s\n";
static const char fmt_0po[] = "[%s%s] m%s polarity%18d [0=normal,1=reverse]\n";
static const char fmt_0ep[] = "[%s%s] m%s enable polarity%11d [0=active HIGH,1=active LOW]\n";
static const char fmt_0ps[] = "[%s%s] m%s step polarity%13d [0=active HIGH,1=active LOW]\n";
static const char fmt_0sp[] = "[%s%s] m%s step polarity%13d [0=active HIGH,1=active LOW]\n";
static const char fmt_0pm[] = "[%s%s] m%s power management%10d [0=disabled,1=always on,2=in cycle,3=when moving]\n";
static const char fmt_0pl[] = "[%s%s] m%s motor power level%13.3f [0.000=minimum, 1.000=maximum]\n";
static const char fmt_pwr[] = "[%s%s] Motor %c power level:%12.3f\n";
@@ -1188,7 +1188,7 @@ void st_print_mi(nvObj_t *nv) { _print_motor_int(nv, fmt_0mi);}
void st_print_su(nvObj_t *nv) { _print_motor_flt_units(nv, fmt_0su, cm_get_units_mode(MODEL));}
void st_print_po(nvObj_t *nv) { _print_motor_int(nv, fmt_0po);}
void st_print_ep(nvObj_t *nv) { _print_motor_int(nv, fmt_0ep);}
void st_print_ps(nvObj_t *nv) { _print_motor_int(nv, fmt_0ps);}
void st_print_sp(nvObj_t *nv) { _print_motor_int(nv, fmt_0sp);}
void st_print_pm(nvObj_t *nv) { _print_motor_int(nv, fmt_0pm);}
void st_print_pl(nvObj_t *nv) { _print_motor_flt(nv, fmt_0pl);}
void st_print_pwr(nvObj_t *nv){ _print_motor_pwr(nv, fmt_pwr);}

View File

@@ -458,7 +458,7 @@ public:
}
};
virtual ioMode getEnablePolarity()
virtual ioMode getEnablePolarity() const
{
return IO_ACTIVE_LOW; // we have to say something here
};
@@ -467,12 +467,12 @@ public:
{
// do nothing
};
virtual ioMode getStepPolarity()
virtual ioMode getStepPolarity() const
{
return IO_ACTIVE_LOW; // we have to say something here
};
virtual void setStepPolarity(ioMode new_mp)
{
// do nothing