mirror of
https://github.com/esphome/esphome.git
synced 2024-11-24 12:06:26 +01:00
Update stepper.h to use enums
This commit is contained in:
parent
5040a9146d
commit
eccf7860b5
@ -7,6 +7,13 @@
|
||||
namespace esphome {
|
||||
namespace stepper {
|
||||
|
||||
// Possible rotations
|
||||
enum Rotations {
|
||||
ROTATION_CCW = -1, /// Only rotate counter-clockwise
|
||||
ROTATION_BOTH = 0, /// Rotation possible in 2 directions
|
||||
ROTATION_CW = 1, /// Only rotate clockwise
|
||||
};
|
||||
|
||||
#define LOG_STEPPER(this) \
|
||||
ESP_LOGCONFIG(TAG, " Acceleration: %.0f steps/s^2", this->acceleration_); \
|
||||
ESP_LOGCONFIG(TAG, " Deceleration: %.0f steps/s^2", this->deceleration_); \
|
||||
@ -20,7 +27,7 @@ class Stepper {
|
||||
void set_acceleration(float acceleration) { this->acceleration_ = acceleration; }
|
||||
void set_deceleration(float deceleration) { this->deceleration_ = deceleration; }
|
||||
void set_max_speed(float max_speed) { this->max_speed_ = max_speed; }
|
||||
void set_rotation(int rotation) { this->rotation_ = rotation; }
|
||||
void set_rotation(Rotations rotation) { this->rotation_ = rotation; }
|
||||
virtual void on_update_speed() {}
|
||||
bool has_reached_target() { return this->current_position == this->target_position; }
|
||||
|
||||
@ -35,7 +42,7 @@ class Stepper {
|
||||
float deceleration_{1e6f};
|
||||
float current_speed_{0.0f};
|
||||
float max_speed_{1e6f};
|
||||
int rotation_{0};
|
||||
Rotations rotation_{ROTATION_BOTH};
|
||||
uint32_t last_calculation_{0};
|
||||
uint32_t last_step_{0};
|
||||
};
|
||||
@ -114,10 +121,10 @@ template<typename... Ts> class SetRotationAction : public Action<Ts...> {
|
||||
public:
|
||||
explicit SetRotationAction(Stepper *parent) : parent_(parent) {}
|
||||
|
||||
TEMPLATABLE_VALUE(int, rotation);
|
||||
TEMPLATABLE_VALUE(Rotations, rotation);
|
||||
|
||||
void play(Ts... x) override {
|
||||
int rotation = this->rotation_.value(x...);
|
||||
Rotations rotation = this->rotation_.value(x...);
|
||||
this->parent_->set_rotation(rotation);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user