ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
mt6701.h
Go to the documentation of this file.
1#pragma once
2
4
5namespace esphome::mt6701 {
6
7// A 14-bit absolute angle: one revolution is 16384 counts
8static constexpr float COUNTS_TO_DEGREES = 360.0f / 16384;
9// Consecutive read or CRC failures tolerated before the component reports a warning
10static constexpr uint8_t MAX_CONSECUTIVE_ERRORS = 5;
11
13class MT6701Component : public Component {
14 public:
16 bool read_encoder();
17
19 uint16_t get_count() const { return this->count_; }
21 float get_angle_degrees() const { return this->count_ * COUNTS_TO_DEGREES; }
22
23 protected:
25 virtual bool read_count(uint16_t &count) = 0;
26
27 uint16_t count_{0};
29 // Set by the I2C hub while the EEPROM is programmed; no bus access until it clears
30 bool suspend_sampling_{false};
31};
32
33} // namespace esphome::mt6701
Bus-independent core; the I2C and SSI hubs provide read_count(), the entities poll it.
Definition mt6701.h:13
virtual bool read_count(uint16_t &count)=0
The current 14-bit count from the bus; false on a bus or CRC error.
bool read_encoder()
Read a fresh angle; false on a bus or CRC error, while suspended, or when setup failed.
Definition mt6701.cpp:6
uint16_t get_count() const
Most recent absolute angle as a raw count in the range [0, 16383].
Definition mt6701.h:19
float get_angle_degrees() const
Most recent absolute shaft angle in degrees, in the range [0, 360).
Definition mt6701.h:21
unsigned count
Definition gif.cpp:51