mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-04 12:00:49 +02:00
added slow mode and detach time to servo (#1413)
* added slow mode and detach time to servo * tidy * and again tidy * add change requests * tidy * tidy * tidy Co-authored-by: Andreas Hergert <andreas.hergert@otrs.com>
This commit is contained in:
@@ -14,18 +14,9 @@ extern uint32_t global_servo_id;
|
||||
class Servo : public Component {
|
||||
public:
|
||||
void set_output(output::FloatOutput *output) { output_ = output; }
|
||||
void write(float value) {
|
||||
value = clamp(value, -1.0f, 1.0f);
|
||||
|
||||
float level;
|
||||
if (value < 0.0)
|
||||
level = lerp(-value, this->idle_level_, this->min_level_);
|
||||
else
|
||||
level = lerp(value, this->idle_level_, this->max_level_);
|
||||
|
||||
this->output_->set_level(level);
|
||||
this->save_level_(level);
|
||||
}
|
||||
void loop() override;
|
||||
void write(float value);
|
||||
void internal_write(float value);
|
||||
void detach() {
|
||||
this->output_->set_level(0.0f);
|
||||
this->save_level_(0.0f);
|
||||
@@ -48,6 +39,8 @@ class Servo : public Component {
|
||||
void set_idle_level(float idle_level) { idle_level_ = idle_level; }
|
||||
void set_max_level(float max_level) { max_level_ = max_level; }
|
||||
void set_restore(bool restore) { restore_ = restore; }
|
||||
void set_auto_detach_time(uint32_t auto_detach_time) { auto_detach_time_ = auto_detach_time; }
|
||||
void set_transition_length(uint32_t transition_length) { transition_length_ = transition_length; }
|
||||
|
||||
protected:
|
||||
void save_level_(float v) { this->rtc_.save(&v); }
|
||||
@@ -57,7 +50,19 @@ class Servo : public Component {
|
||||
float idle_level_ = 0.0750f;
|
||||
float max_level_ = 0.1200f;
|
||||
bool restore_{false};
|
||||
uint32_t auto_detach_time_ = 0;
|
||||
uint32_t transition_length_ = 0;
|
||||
ESPPreferenceObject rtc_;
|
||||
uint8_t state_;
|
||||
float target_value_ = 0;
|
||||
float source_value_ = 0;
|
||||
float current_value_ = 0;
|
||||
uint32_t start_millis_ = 0;
|
||||
enum State {
|
||||
STATE_ATTACHED = 0,
|
||||
STATE_DETACHED = 1,
|
||||
STATE_TARGET_REACHED = 2,
|
||||
};
|
||||
};
|
||||
|
||||
template<typename... Ts> class ServoWriteAction : public Action<Ts...> {
|
||||
|
||||
Reference in New Issue
Block a user