esphome/esphome/components/qmc5883l/qmc5883l.h
Tim P fa1adfd934 Add QMC5883L Sensor + Improvements to HMC5883L (#671)
* Add QMC5883L and Updated HMC5883L

* add tests

* changed to oversampling

* fix pylint

* fix private method

* typo fix

* fix protected method

* Clean up code and PR recomendations

* fix tests

* remote file

* fix qmc oversampling unit

* Remove hmc5883l config logging

Either the units are converted to the user values like 1x, 8x oversampling or not printed at all. Printing the machine-value of these is only confusing users.

* Changes for validate_enum

Move stuff that can be done beforehand out of the bound function, use text_type for py2/3 compatability.

* Remove unused constant

* Remove duplicate tests

* Repeat remove config print

* remove changes to test2 since bin is to large

* Add comment to HMC5583L


Co-authored-by: Timothy Purchas <timothy@TPF.local>
Co-authored-by: Otto Winter <otto@otto-winter.com>
2019-11-26 18:43:11 +01:00

60 lines
1.8 KiB
C++

#pragma once
#include "esphome/core/component.h"
#include "esphome/components/sensor/sensor.h"
#include "esphome/components/i2c/i2c.h"
namespace esphome {
namespace qmc5883l {
enum QMC5883LDatarate {
QMC5883L_DATARATE_10_HZ = 0b00,
QMC5883L_DATARATE_50_HZ = 0b01,
QMC5883L_DATARATE_100_HZ = 0b10,
QMC5883L_DATARATE_200_HZ = 0b11,
};
enum QMC5883LRange {
QMC5883L_RANGE_200_UT = 0b00,
QMC5883L_RANGE_800_UT = 0b01,
};
enum QMC5883LOversampling {
QMC5883L_SAMPLING_512 = 0b00,
QMC5883L_SAMPLING_256 = 0b01,
QMC5883L_SAMPLING_128 = 0b10,
QMC5883L_SAMPLING_64 = 0b11,
};
class QMC5883LComponent : public PollingComponent, public i2c::I2CDevice {
public:
void setup() override;
void dump_config() override;
float get_setup_priority() const override;
void update() override;
void set_datarate(QMC5883LDatarate datarate) { datarate_ = datarate; }
void set_range(QMC5883LRange range) { range_ = range; }
void set_oversampling(QMC5883LOversampling oversampling) { oversampling_ = oversampling; }
void set_x_sensor(sensor::Sensor *x_sensor) { x_sensor_ = x_sensor; }
void set_y_sensor(sensor::Sensor *y_sensor) { y_sensor_ = y_sensor; }
void set_z_sensor(sensor::Sensor *z_sensor) { z_sensor_ = z_sensor; }
void set_heading_sensor(sensor::Sensor *heading_sensor) { heading_sensor_ = heading_sensor; }
protected:
QMC5883LDatarate datarate_{QMC5883L_DATARATE_10_HZ};
QMC5883LRange range_{QMC5883L_RANGE_200_UT};
QMC5883LOversampling oversampling_{QMC5883L_SAMPLING_512};
sensor::Sensor *x_sensor_;
sensor::Sensor *y_sensor_;
sensor::Sensor *z_sensor_;
sensor::Sensor *heading_sensor_;
enum ErrorCode {
NONE = 0,
COMMUNICATION_FAILED,
} error_code_;
bool read_byte_16_(uint8_t a_register, uint16_t *data);
};
} // namespace qmc5883l
} // namespace esphome