ESPHome  2024.12.2
mopeka_std_check.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <cinttypes>
4 #include <vector>
5 
9 
10 #ifdef USE_ESP32
11 
12 namespace esphome {
13 namespace mopeka_std_check {
14 
15 enum SensorType {
16  STANDARD = 0x02,
17  XL = 0x03,
18  ETRAILER = 0x46,
19 };
20 
21 // 4 values in one struct so it aligns to 8 byte. One `mopeka_std_values` is 40 bit long.
22 struct mopeka_std_values { // NOLINT(readability-identifier-naming,altera-struct-pack-align)
23  u_int16_t time_0 : 5;
24  u_int16_t value_0 : 5;
25  u_int16_t time_1 : 5;
26  u_int16_t value_1 : 5;
27  u_int16_t time_2 : 5;
28  u_int16_t value_2 : 5;
29  u_int16_t time_3 : 5;
30  u_int16_t value_3 : 5;
31 } __attribute__((packed));
32 
33 struct mopeka_std_package { // NOLINT(readability-identifier-naming,altera-struct-pack-align)
34  u_int8_t data_0 : 8;
35  u_int8_t data_1 : 8;
36  u_int8_t raw_voltage : 8;
37 
38  u_int8_t raw_temp : 6;
39  bool slow_update_rate : 1;
40  bool sync_pressed : 1;
41 
43 } __attribute__((packed));
44 
46  public:
47  void set_address(uint64_t address) { address_ = address; };
48 
49  bool parse_device(const esp32_ble_tracker::ESPBTDevice &device) override;
50  void dump_config() override;
51  float get_setup_priority() const override { return setup_priority::DATA; }
52 
53  void set_level(sensor::Sensor *level) { this->level_ = level; };
54  void set_temperature(sensor::Sensor *temperature) { this->temperature_ = temperature; };
55  void set_battery_level(sensor::Sensor *bat) { this->battery_level_ = bat; };
56  void set_distance(sensor::Sensor *distance) { this->distance_ = distance; };
57  void set_propane_butane_mix(float val) { this->propane_butane_mix_ = val; };
58  void set_tank_full(float full) { this->full_mm_ = full; };
59  void set_tank_empty(float empty) { this->empty_mm_ = empty; };
60 
61  protected:
62  uint64_t address_;
63  sensor::Sensor *level_{nullptr};
64  sensor::Sensor *temperature_{nullptr};
65  sensor::Sensor *distance_{nullptr};
66  sensor::Sensor *battery_level_{nullptr};
67 
69  uint32_t full_mm_;
70  uint32_t empty_mm_;
71 
72  float get_lpg_speed_of_sound_(float temperature);
73  uint8_t parse_battery_level_(const mopeka_std_package *message);
74  uint8_t parse_temperature_(const mopeka_std_package *message);
75 };
76 
77 } // namespace mopeka_std_check
78 } // namespace esphome
79 
80 #endif
void set_battery_level(sensor::Sensor *bat)
const float DATA
For components that import data from directly connected sensors like DHT.
Definition: component.cpp:19
esphome::mopeka_std_check::MopekaStdCheck __attribute__
mopeka_std_values val[4]
void set_temperature(sensor::Sensor *temperature)
uint16_t temperature
Definition: sun_gtil2.cpp:26
void set_level(sensor::Sensor *level)
void set_distance(sensor::Sensor *distance)
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
uint8_t address
Definition: bl0906.h:211
Base-class for all sensors.
Definition: sensor.h:57