22static constexpr uint8_t X_AXIS = 0;
23static constexpr uint8_t Y_AXIS = 1;
24static constexpr uint8_t Z_AXIS = 2;
38 void setup()
override;
44 memcpy(this->
base_matrix_, m.data(),
sizeof(this->base_matrix_));
45 memcpy(this->
matrix_, m.data(),
sizeof(this->matrix_));
66 1, 0, 0, 0, 1, 0, 0, 0, 1,
71 1, 0, 0, 0, 1, 0, 0, 0, 1,
74 void map_axes_(
float output[3],
const float input[3])
const {
75 output[0] = input[X_AXIS] * this->
matrix_[0] + input[Y_AXIS] * this->
matrix_[1] + input[Z_AXIS] * this->
matrix_[2];
76 output[1] = input[X_AXIS] * this->matrix_[3] + input[Y_AXIS] * this->matrix_[4] + input[Z_AXIS] * this->matrix_[5];
77 output[2] = input[X_AXIS] * this->matrix_[6] + input[Y_AXIS] * this->matrix_[7] + input[Z_AXIS] * this->matrix_[8];
96 void play(
const Ts &...)
override {
121 void play(
const Ts &...)
override {
144 void play(
const Ts &...)
override {
This class simplifies creating components that periodically check a state.
void trigger(const Ts &...x) ESPHOME_ALWAYS_INLINE
Inform the parent automation that the event has triggered.
Trigger * get_error_trigger()
CalibrateHeadingAction(MotionComponent *parent)
Trigger * get_success_trigger()
void play(const Ts &...) override
MotionComponent * parent_
CalibrateLevelAction(MotionComponent *parent)
void play(const Ts &...) override
Trigger * get_error_trigger()
MotionComponent * parent_
Trigger * get_success_trigger()
void play(const Ts &...) override
ClearCalibrationAction(MotionComponent *parent)
MotionComponent * parent_
LazyCallbackManager< void(MotionData &)> motion_data_callback_
void map_axes_(float output[3], const float input[3]) const
void set_calibration_key(uint32_t key)
ESPPreferenceObject pref_
void add_listener(F &&cb)
bool calibrate_heading()
Assuming Y-axis rotation only, correct the heading so X/Y align correctly.
float get_setup_priority() const override
void set_matrix(const std::array< float, 9 > &m)
virtual bool update_data(MotionData &data)=0
bool calibrate_level()
Calibrate the matrix so the current reading maps to [0, 0, 1] (device flat).
void dump_config() override
void clear_calibration()
Restore the build-time (axis_map / transform_matrix) base, discarding calibration.
bool save_calibration()
Save the current matrix to NVS.
struct esphome::motion::CalibrationPref PACKED
constexpr float DATA
For components that import data from directly connected sensors like DHT.