8static const char *
const TAG = 
"hmc5883l";
 
    9static const uint8_t HMC5883L_ADDRESS = 0x1E;
 
   10static const uint8_t HMC5883L_REGISTER_CONFIG_A = 0x00;
 
   11static const uint8_t HMC5883L_REGISTER_CONFIG_B = 0x01;
 
   12static const uint8_t HMC5883L_REGISTER_MODE = 0x02;
 
   13static const uint8_t HMC5883L_REGISTER_DATA_X_MSB = 0x03;
 
   14static const uint8_t HMC5883L_REGISTER_DATA_X_LSB = 0x04;
 
   15static const uint8_t HMC5883L_REGISTER_DATA_Z_MSB = 0x05;
 
   16static const uint8_t HMC5883L_REGISTER_DATA_Z_LSB = 0x06;
 
   17static const uint8_t HMC5883L_REGISTER_DATA_Y_MSB = 0x07;
 
   18static const uint8_t HMC5883L_REGISTER_DATA_Y_LSB = 0x08;
 
   19static const uint8_t HMC5883L_REGISTER_STATUS = 0x09;
 
   20static const uint8_t HMC5883L_REGISTER_IDENTIFICATION_A = 0x0A;
 
   21static const uint8_t HMC5883L_REGISTER_IDENTIFICATION_B = 0x0B;
 
   22static const uint8_t HMC5883L_REGISTER_IDENTIFICATION_C = 0x0C;
 
   26  if (!this->
read_byte(HMC5883L_REGISTER_IDENTIFICATION_A, &
id[0]) ||
 
   27      !this->
read_byte(HMC5883L_REGISTER_IDENTIFICATION_B, &
id[1]) ||
 
   28      !this->
read_byte(HMC5883L_REGISTER_IDENTIFICATION_C, &
id[2])) {
 
   38  if (
id[0] != 0x48 || 
id[1] != 0x34 || 
id[2] != 0x33) {
 
   48  if (!this->
write_byte(HMC5883L_REGISTER_CONFIG_A, config_a)) {
 
   55  config_b |= this->
range_ << 5;
 
   56  if (!this->
write_byte(HMC5883L_REGISTER_CONFIG_B, config_b)) {
 
 
   72  ESP_LOGCONFIG(TAG, 
"HMC5883L:");
 
   75    ESP_LOGE(TAG, ESP_LOG_MSG_COMM_FAIL);
 
   77    ESP_LOGE(TAG, 
"The ID registers don't match - Is this really an HMC5883L?");
 
   79  LOG_UPDATE_INTERVAL(
this);
 
   81  LOG_SENSOR(
"  ", 
"X Axis", this->
x_sensor_);
 
   82  LOG_SENSOR(
"  ", 
"Y Axis", this->
y_sensor_);
 
   83  LOG_SENSOR(
"  ", 
"Z Axis", this->
z_sensor_);
 
 
   88  uint16_t raw_x, raw_y, raw_z;
 
   89  if (!this->
read_byte_16(HMC5883L_REGISTER_DATA_X_MSB, &raw_x) ||
 
   90      !this->
read_byte_16(HMC5883L_REGISTER_DATA_Y_MSB, &raw_y) ||
 
   91      !this->
read_byte_16(HMC5883L_REGISTER_DATA_Z_MSB, &raw_z)) {
 
  127  const float x = int16_t(raw_x) * mg_per_bit * 0.1f;
 
  128  const float y = int16_t(raw_y) * mg_per_bit * 0.1f;
 
  129  const float z = int16_t(raw_z) * mg_per_bit * 0.1f;
 
  131  float heading = atan2f(0.0f - 
x, 
y) * 180.0f / M_PI;
 
  132  ESP_LOGD(TAG, 
"Got x=%0.02fµT y=%0.02fµT z=%0.02fµT heading=%0.01f°", 
x, 
y, 
z, heading);
 
 
 
BedjetMode mode
BedJet operating mode.
uint32_t get_loop_interval() const
virtual void mark_failed()
Mark this component as failed.
void status_set_warning(const char *message=nullptr)
void start()
Start running the loop continuously.
virtual uint32_t get_update_interval() const
Get the update interval in ms of this sensor.
void dump_config() override
HMC5883LDatarate datarate_
sensor::Sensor * z_sensor_
HighFrequencyLoopRequester high_freq_
sensor::Sensor * heading_sensor_
HMC5883LOversampling oversampling_
float get_setup_priority() const override
sensor::Sensor * y_sensor_
sensor::Sensor * x_sensor_
enum esphome::hmc5883l::HMC5883LComponent::ErrorCode error_code_
bool write_byte(uint8_t a_register, uint8_t data) const
bool read_byte(uint8_t a_register, uint8_t *data)
bool read_byte_16(uint8_t a_register, uint16_t *data)
void publish_state(float state)
Publish a new state to the front-end.
const float DATA
For components that import data from directly connected sensors like DHT.
Providing packet encoding functions for exchanging data with a remote host.
Application App
Global storage of Application pointer - only one Application can exist.