13static constexpr float STALLGUARD_RESULT_MAX = 510.0f;
16 if (sensor ==
nullptr)
18 if (!data.has_value()) {
23 sensor->
publish_state(field.
is_signed ?
static_cast<float>(
static_cast<int32_t
>(value)) :
static_cast<float>(value));
33 auto read = [
this, &reachable](uint8_t reg) -> optional<uint32_t> {
37 reachable = data.has_value();
42 auto drv_status = read(tmc22xx::REG_DRV_STATUS);
44 if (drv_status.has_value()) {
54 auto sg_result = read(REG_SG_RESULT);
60 if (moving && sg_result.has_value() && stall_result < STALLGUARD_RESULT_MAX) {
62 load = (STALLGUARD_RESULT_MAX - result) / (STALLGUARD_RESULT_MAX - stall_result) * 100.0f;
71 auto pwm_scale = read(tmc22xx::REG_PWM_SCALE);
77 auto pwm_auto = read(tmc22xx::REG_PWM_AUTO);
84 ESP_LOGCONFIG(TAG,
"TMC2209 Sensor:");
85 LOG_UPDATE_INTERVAL(
this);
Base-class for all sensors.
void publish_state(float state)
Publish a new state to the front-end.
bool has_reached_target()
void dump_config() override
sensor::Sensor * pwm_grad_auto_sensor_
sensor::Sensor * stallguard_result_sensor_
sensor::Sensor * pwm_scale_auto_sensor_
sensor::Sensor * actual_current_sensor_
sensor::Sensor * pwm_ofs_auto_sensor_
sensor::Sensor * motor_load_sensor_
sensor::Sensor * pwm_scale_sum_sensor_
uint8_t get_stallguard_threshold() const
Base class for Trinamic stepper drivers that are configured over the single wire UART interface.
static uint32_t extract_field(uint32_t data, const RegisterField &field)
bool is_unreachable() const
True while the driver does not answer, until the status poll reads it again (every 10 s).
optional< uint32_t > read_register(uint8_t reg)
float scale_to_current(uint8_t scale)
Convert a current scale (0-31) to A RMS, without analog current scale.
ESPHOME_LOG_TAG(TAG, "tmc2209.sensor")
A bit field inside one register.