7#ifdef USE_BQ25820_SENSOR
10#ifdef USE_BINARY_SENSOR
24static constexpr size_t BQ25820_LIMIT_COUNT = 5;
25static constexpr size_t BQ25820_CONTROL_COUNT = 7;
27static constexpr uint16_t NTC_OPEN_CODE = 1020;
32 std::array<uint16_t, BQ25820_LIMIT_COUNT>
limits;
34 std::array<uint8_t, BQ25820_CONTROL_COUNT>
controls;
42#ifdef USE_BQ25820_SENSOR
52PROGMEM_STRING_TABLE(BQ25820StatusStrings,
"Not Charging",
"Trickle",
"Precharge",
"Fast Charge",
"Taper",
"Unknown",
53 "Top-Off",
"Done",
"Normal",
"Warm",
"Cool",
"Cold",
"Hot");
71 void setup()
override;
75#ifdef USE_BQ25820_SENSOR
83 void set_ntc_calibration(
float a,
float b) {
88#ifdef USE_BQ25820_STATUS_PUBLISHER
99#ifdef USE_BQ25820_SENSOR
103 const uint16_t code = ts_adc & 0x3FF;
104 if (code == 0 || code >= NTC_OPEN_CODE)
106 const float ratio = code / 1024.0f;
107 return 1.0f / (this->
ntc_a_ + this->
ntc_b_ * logf(ratio / (1.0f - ratio))) - 273.15f;
This class simplifies creating components that periodically check a state.
BQ25820Component(const BQ25820Config *config, bool force_mppt_sweep)
config points into PROGMEM
bool write_config_registers_()
BQ25820Config load_config_() const
bool configure_()
Writes the configuration, then polls again once the ADC has converted.
void dump_config() override
bool watchdog_enabled_() const
SUB_SENSOR(vbat) SUB_SENSOR(vsys) SUB_SENSOR(vac) SUB_SENSOR(ibat) SUB_SENSOR(iac) SUB_SENSOR(temp_in_c) void set_ntc_calibration(float a
float ntc_temperature_(int16_t ts_adc) const
Temperature from TS_ADC, the TS pin voltage as a 10-bit share of REGN; NAN for a shorted or open NTC.
HUB_PUBLISHER(status, const BQ25820StatusRegisters &) HUB_PUBLISHER(dump
void publish_adc_(const BQ25820AdcRegisters &adc)
const BQ25820Config * config_
This Class provides the methods to read/write bytes from/to an i2c device.
void publish_state(const std::string &state)
std::array< uint8_t, 4 > BQ25820StatusRegisters
void publish_status_text(text_sensor::TextSensor *sensor, uint8_t &last, uint8_t value, uint8_t first)
Publishes string first + (value & 7), only on change.
PROGMEM_STRING_TABLE(BQ25820StatusStrings, "Not Charging", "Trickle", "Precharge", "Fast Charge", "Taper", "Unknown", "Top-Off", "Done", "Normal", "Warm", "Cool", "Cold", "Hot")
std::array< int16_t, 7 > BQ25820AdcRegisters
std::array< uint8_t, BQ25820_CONTROL_COUNT > controls
std::array< uint16_t, BQ25820_LIMIT_COUNT > limits