ESPHome 2026.9.0-dev
Loading...
Searching...
No Matches
ufm01.h
Go to the documentation of this file.
1#pragma once
2
5#ifdef USE_BINARY_SENSOR
7#endif
8#ifdef USE_SENSOR
10#endif
12
13#include <array>
14#include <cstdint>
15
16// component API definition at https://www.sciosense.com/wp-content/uploads/2025/06/UFM-01-Datasheet-1.pdf
17
18namespace esphome::ufm01 {
19
20namespace testing {
21class TestableUFM01;
22} // namespace testing
23
24static constexpr size_t FRAME_SIZE = 32;
25static constexpr size_t PASSIVE_FRAME_SIZE = 23;
26
27enum class OperatingMode : uint8_t {
28 STARTUP = 0,
29 ACTIVE_STREAM = 1,
30 PASSIVE_POLL = 2,
31};
32
33enum class StartupPhase : uint8_t {
34 WAIT = 0,
40};
41
47
49#ifdef USE_SENSOR
50 SUB_SENSOR(accumulated_flow)
51 SUB_SENSOR(flow)
52 SUB_SENSOR(temperature)
53#endif
54
55#ifdef USE_BINARY_SENSOR
56 SUB_BINARY_SENSOR(ufc_chip_error)
57 SUB_BINARY_SENSOR(flow_direction_wrong)
58 SUB_BINARY_SENSOR(empty_tube)
59 SUB_BINARY_SENSOR(flow_rate_out_of_range)
60#endif
61
62 public:
63 void setup() override;
64
65 void dump_config() override;
66
67 void loop() override;
68
69 float get_setup_priority() const override;
70
71 protected:
73 bool set_active_mode_();
74 bool reset_device_();
75
76 private:
77 bool send_command_(const std::array<uint8_t, 7> &command);
78 void send_command_no_wait_(const std::array<uint8_t, 7> &command);
79 bool consume_ack_();
80 void flush_rx_();
81 bool process_active_stream_();
82 void on_active_frame_(uint8_t data[FRAME_SIZE]);
83
84 void loop_startup_();
85 void loop_active_stream_();
86 void loop_passive_poll_();
87 void set_startup_phase_(StartupPhase phase);
88 void enter_active_stream_(const char *reason);
89 void start_passive_read_();
90 PassiveReadResult continue_passive_read_();
91
93 StartupPhase startup_phase_{StartupPhase::WAIT};
94 uint32_t phase_start_ms_{0};
95 uint32_t startup_wait_ms_{0};
96 bool reset_retried_{false};
97 uint32_t last_valid_frame_ms_{0};
98 uint32_t last_poll_ms_{0};
99
100 bool passive_read_pending_{false};
101 uint32_t passive_start_ms_{0};
102 size_t passive_index_{0};
103 uint8_t passive_frame_[PASSIVE_FRAME_SIZE];
104
105 int32_t read_index_ = 0;
106 uint8_t data_[FRAME_SIZE];
107
108 friend class testing::TestableUFM01;
109};
110
111} // namespace esphome::ufm01
virtual void setup()
Where the component's initialization should happen.
Definition component.cpp:84
static void uint32_t
uint16_t temperature
Definition sun_gtil2.cpp:12