ESPHome  2022.12.8
syncer.h
Go to the documentation of this file.
1 #pragma once
2 
5 
6 namespace esphome {
7 namespace preferences {
8 
9 class IntervalSyncer : public Component {
10  public:
11  void set_write_interval(uint32_t write_interval) { write_interval_ = write_interval; }
12  void setup() override {
14  }
15  void on_shutdown() override { global_preferences->sync(); }
16  float get_setup_priority() const override { return setup_priority::BUS; }
17 
18  protected:
19  uint32_t write_interval_;
20 };
21 
22 } // namespace preferences
23 } // namespace esphome
void set_interval(const std::string &name, uint32_t interval, std::function< void()> &&f)
Set an interval function with a unique name.
Definition: component.cpp:51
float get_setup_priority() const override
Definition: syncer.h:16
const float BUS
For communication buses like i2c/spi.
Definition: component.cpp:15
ESPPreferences * global_preferences
void set_write_interval(uint32_t write_interval)
Definition: syncer.h:11
Definition: a4988.cpp:4
virtual bool sync()=0
Commit pending writes to flash.