ESPHome  2024.11.1
m5stack_8angle_sensor.cpp
Go to the documentation of this file.
2 
3 namespace esphome {
4 namespace m5stack_8angle {
5 
7  if (this->parent_ != nullptr) {
8  int32_t raw_pos = this->parent_->read_knob_pos_raw(this->channel_, this->bits_);
9  if (raw_pos == -1) {
10  this->status_set_warning("Could not read knob position from M5Stack 8Angle.");
11  return;
12  }
13  if (this->raw_) {
14  this->publish_state(raw_pos);
15  } else {
16  float knob_pos = (float) raw_pos / ((1 << this->bits_) - 1);
17  this->publish_state(knob_pos);
18  }
19  this->status_clear_warning();
20  };
21 }
22 
23 } // namespace m5stack_8angle
24 } // namespace esphome
void status_set_warning(const char *message="unspecified")
Definition: component.cpp:151
M5Stack8AngleComponent * parent_
Definition: helpers.h:533
void status_clear_warning()
Definition: component.cpp:166
void publish_state(float state)
Publish a new state to the front-end.
Definition: sensor.cpp:39
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7