2019-04-17 12:06:00 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "esphome/core/component.h"
|
2021-09-20 11:47:51 +02:00
|
|
|
#include "esphome/core/hal.h"
|
2019-04-17 12:06:00 +02:00
|
|
|
#include "esphome/components/sensor/sensor.h"
|
|
|
|
|
|
|
|
namespace esphome {
|
|
|
|
namespace hx711 {
|
|
|
|
|
|
|
|
enum HX711Gain {
|
|
|
|
HX711_GAIN_128 = 1,
|
|
|
|
HX711_GAIN_32 = 2,
|
|
|
|
HX711_GAIN_64 = 3,
|
|
|
|
};
|
|
|
|
|
2019-04-22 21:56:30 +02:00
|
|
|
class HX711Sensor : public sensor::Sensor, public PollingComponent {
|
2019-04-17 12:06:00 +02:00
|
|
|
public:
|
2019-04-22 21:56:30 +02:00
|
|
|
void set_dout_pin(GPIOPin *dout_pin) { dout_pin_ = dout_pin; }
|
|
|
|
void set_sck_pin(GPIOPin *sck_pin) { sck_pin_ = sck_pin; }
|
|
|
|
void set_gain(HX711Gain gain) { gain_ = gain; }
|
2019-04-17 12:06:00 +02:00
|
|
|
|
|
|
|
void setup() override;
|
|
|
|
void dump_config() override;
|
|
|
|
float get_setup_priority() const override;
|
|
|
|
void update() override;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool read_sensor_(uint32_t *result);
|
|
|
|
|
|
|
|
GPIOPin *dout_pin_;
|
|
|
|
GPIOPin *sck_pin_;
|
|
|
|
HX711Gain gain_{HX711_GAIN_128};
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace hx711
|
|
|
|
} // namespace esphome
|