mirror of
https://github.com/Threnklyn/esphome-dev.git
synced 2026-06-04 20:09:35 +02:00
🏗 Merge C++ into python codebase (#504)
## Description: Move esphome-core codebase into esphome (and a bunch of other refactors). See https://github.com/esphome/feature-requests/issues/97 Yes this is a shit ton of work and no there's no way to automate it :( But it will be worth it 👍 Progress: - Core support (file copy etc): 80% - Base Abstractions (light, switch): ~50% - Integrations: ~10% - Working? Yes, (but only with ported components). Other refactors: - Moves all codegen related stuff into a single class: `esphome.codegen` (imported as `cg`) - Rework coroutine syntax - Move from `component/platform.py` to `domain/component.py` structure as with HA - Move all defaults out of C++ and into config validation. - Remove `make_...` helpers from Application class. Reason: Merge conflicts with every single new integration. - Pointer Variables are stored globally instead of locally in setup(). Reason: stack size limit. Future work: - Rework const.py - Move all `CONF_...` into a conf class (usage `conf.UPDATE_INTERVAL` vs `CONF_UPDATE_INTERVAL`). Reason: Less convoluted import block - Enable loading from `custom_components` folder. **Related issue (if applicable):** https://github.com/esphome/feature-requests/issues/97 **Pull request in [esphome-docs](https://github.com/esphome/esphome-docs) with documentation (if applicable):** esphome/esphome-docs#<esphome-docs PR number goes here> ## Checklist: - [ ] The code change is tested and works locally. - [ ] Tests have been added to verify that the new code works (under `tests/` folder). If user exposed functionality or configuration variables are added/changed: - [ ] Documentation added/updated in [esphomedocs](https://github.com/OttoWinter/esphomedocs).
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#pragma once
|
||||
|
||||
#include "esphome/core/component.h"
|
||||
#include "esphome/core/automation.h"
|
||||
#include "esphome/components/stepper/stepper.h"
|
||||
|
||||
namespace esphome {
|
||||
namespace stepper {
|
||||
|
||||
#define LOG_STEPPER(this) \
|
||||
ESP_LOGCONFIG(TAG, " Acceleration: %.0f steps/s^2", this->acceleration_); \
|
||||
ESP_LOGCONFIG(TAG, " Deceleration: %.0f steps/s^2", this->deceleration_); \
|
||||
ESP_LOGCONFIG(TAG, " Max Speed: %.0f steps/s", this->max_speed_);
|
||||
|
||||
class Stepper {
|
||||
public:
|
||||
void set_target(int32_t steps) { this->target_position = steps; }
|
||||
void report_position(int32_t steps) { this->current_position = steps; }
|
||||
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; }
|
||||
bool has_reached_target() { return this->current_position == this->target_position; }
|
||||
|
||||
int32_t current_position{0};
|
||||
int32_t target_position{0};
|
||||
|
||||
protected:
|
||||
void calculate_speed_(uint32_t now);
|
||||
int32_t should_step_();
|
||||
|
||||
float acceleration_{1e6f};
|
||||
float deceleration_{1e6f};
|
||||
float current_speed_{0.0f};
|
||||
float max_speed_{1e6f};
|
||||
uint32_t last_calculation_{0};
|
||||
uint32_t last_step_{0};
|
||||
};
|
||||
|
||||
template<typename... Ts> class SetTargetAction : public Action<Ts...> {
|
||||
public:
|
||||
explicit SetTargetAction(Stepper *parent) : parent_(parent) {}
|
||||
|
||||
TEMPLATABLE_VALUE(int32_t, target)
|
||||
|
||||
void play(Ts... x) override {
|
||||
this->parent_->set_target(this->target_.value(x...));
|
||||
this->play_next(x...);
|
||||
}
|
||||
|
||||
protected:
|
||||
Stepper *parent_;
|
||||
};
|
||||
|
||||
template<typename... Ts> class ReportPositionAction : public Action<Ts...> {
|
||||
public:
|
||||
explicit ReportPositionAction(Stepper *parent) : parent_(parent) {}
|
||||
|
||||
TEMPLATABLE_VALUE(int32_t, position)
|
||||
|
||||
void play(Ts... x) override {
|
||||
this->parent_->report_position(this->position_.value(x...));
|
||||
this->play_next(x...);
|
||||
}
|
||||
|
||||
protected:
|
||||
Stepper *parent_;
|
||||
};
|
||||
|
||||
} // namespace stepper
|
||||
} // namespace esphome
|
||||
Reference in New Issue
Block a user