kopia lustrzana https://github.com/pimoroni/pimoroni-pico
Minor internal function rename, and var assignment
rodzic
5192e8bc87
commit
5f3ac9411b
|
@ -45,11 +45,11 @@ namespace servo {
|
|||
}
|
||||
|
||||
void Servo::enable() {
|
||||
apply_pulse(state.enable());
|
||||
apply_pulse(state.enable_with_return());
|
||||
}
|
||||
|
||||
void Servo::disable() {
|
||||
apply_pulse(state.disable());
|
||||
apply_pulse(state.disable_with_return());
|
||||
}
|
||||
|
||||
bool Servo::is_enabled() const {
|
||||
|
|
|
@ -90,7 +90,7 @@ namespace servo {
|
|||
|
||||
void ServoCluster::enable(uint8_t servo, bool load) {
|
||||
assert(servo < pwms.get_chan_count());
|
||||
float new_pulse = states[servo].enable();
|
||||
float new_pulse = states[servo].enable_with_return();
|
||||
apply_pulse(servo, new_pulse, load);
|
||||
}
|
||||
|
||||
|
@ -122,7 +122,7 @@ namespace servo {
|
|||
|
||||
void ServoCluster::disable(uint8_t servo, bool load) {
|
||||
assert(servo < pwms.get_chan_count());
|
||||
float new_pulse = states[servo].disable();
|
||||
float new_pulse = states[servo].disable_with_return();
|
||||
apply_pulse(servo, new_pulse, load);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,32 +1,33 @@
|
|||
#include "servo_state.hpp"
|
||||
|
||||
namespace servo {
|
||||
ServoState::ServoState() {
|
||||
ServoState::ServoState()
|
||||
: servo_value(0.0f), last_enabled_pulse(0.0f), enabled(false) {
|
||||
}
|
||||
|
||||
ServoState::ServoState(CalibrationType default_type)
|
||||
: calib(default_type) {
|
||||
: servo_value(0.0f), last_enabled_pulse(0.0f), enabled(false), calib(default_type) {
|
||||
}
|
||||
|
||||
ServoState::ServoState(const Calibration& calibration)
|
||||
: calib(calibration) {
|
||||
: servo_value(0.0f), last_enabled_pulse(0.0f), enabled(false), calib(calibration) {
|
||||
}
|
||||
|
||||
float ServoState::enable() {
|
||||
float ServoState::enable_with_return() {
|
||||
// Has the servo not had a pulse value set before being enabled?
|
||||
if(last_enabled_pulse < MIN_VALID_PULSE) {
|
||||
// Set the servo to its middle
|
||||
return to_mid_with_return();
|
||||
}
|
||||
return _enable();
|
||||
return _enable_with_return();
|
||||
}
|
||||
|
||||
float ServoState::disable() {
|
||||
float ServoState::disable_with_return() {
|
||||
enabled = false;
|
||||
return 0.0f; // A zero pulse
|
||||
}
|
||||
|
||||
float ServoState::_enable() {
|
||||
float ServoState::_enable_with_return() {
|
||||
enabled = true;
|
||||
return last_enabled_pulse;
|
||||
}
|
||||
|
@ -45,10 +46,10 @@ namespace servo {
|
|||
if(calib.pulse_to_value(pulse, value_out, pulse_out)) {
|
||||
servo_value = value_out;
|
||||
last_enabled_pulse = pulse_out;
|
||||
return _enable();
|
||||
return _enable_with_return();
|
||||
}
|
||||
}
|
||||
return disable();
|
||||
return disable_with_return();
|
||||
}
|
||||
|
||||
float ServoState::get_value() const {
|
||||
|
@ -60,9 +61,9 @@ namespace servo {
|
|||
if(calib.value_to_pulse(value, pulse_out, value_out)) {
|
||||
last_enabled_pulse = pulse_out;
|
||||
servo_value = value_out;
|
||||
return _enable();
|
||||
return _enable_with_return();
|
||||
}
|
||||
return disable();
|
||||
return disable_with_return();
|
||||
}
|
||||
|
||||
float ServoState::get_min_value() const {
|
||||
|
|
|
@ -25,9 +25,9 @@ namespace servo {
|
|||
// Variables
|
||||
//--------------------------------------------------
|
||||
private:
|
||||
float servo_value = 0.0f;
|
||||
float last_enabled_pulse = 0.0f;
|
||||
bool enabled = false;
|
||||
float servo_value;
|
||||
float last_enabled_pulse;
|
||||
bool enabled;
|
||||
Calibration calib;
|
||||
|
||||
|
||||
|
@ -44,11 +44,11 @@ namespace servo {
|
|||
// Methods
|
||||
//--------------------------------------------------
|
||||
public:
|
||||
float enable();
|
||||
float disable();
|
||||
float enable_with_return();
|
||||
float disable_with_return();
|
||||
bool is_enabled() const;
|
||||
private:
|
||||
float _enable(); // Internal version of enable without convenient initialisation to the middle
|
||||
float _enable_with_return(); // Internal version of enable without convenient initialisation to the middle
|
||||
public:
|
||||
float get_pulse() const;
|
||||
float set_pulse_with_return(float pulse);
|
||||
|
@ -56,7 +56,7 @@ namespace servo {
|
|||
float get_value() const;
|
||||
float set_value_with_return(float value);
|
||||
|
||||
public:
|
||||
//--------------------------------------------------
|
||||
float get_min_value() const;
|
||||
float get_mid_value() const;
|
||||
float get_max_value() const;
|
||||
|
|
Ładowanie…
Reference in New Issue