ESPHome  2024.11.0
automation.h
Go to the documentation of this file.
1 #pragma once
3 #include "nextion.h"
4 
5 namespace esphome {
6 namespace nextion {
7 
8 class SetupTrigger : public Trigger<> {
9  public:
10  explicit SetupTrigger(Nextion *nextion) {
11  nextion->add_setup_state_callback([this]() { this->trigger(); });
12  }
13 };
14 
15 class SleepTrigger : public Trigger<> {
16  public:
17  explicit SleepTrigger(Nextion *nextion) {
18  nextion->add_sleep_state_callback([this]() { this->trigger(); });
19  }
20 };
21 
22 class WakeTrigger : public Trigger<> {
23  public:
24  explicit WakeTrigger(Nextion *nextion) {
25  nextion->add_wake_state_callback([this]() { this->trigger(); });
26  }
27 };
28 
29 class PageTrigger : public Trigger<uint8_t> {
30  public:
31  explicit PageTrigger(Nextion *nextion) {
32  nextion->add_new_page_callback([this](const uint8_t page_id) { this->trigger(page_id); });
33  }
34 };
35 
36 class TouchTrigger : public Trigger<uint8_t, uint8_t, bool> {
37  public:
38  explicit TouchTrigger(Nextion *nextion) {
39  nextion->add_touch_event_callback([this](uint8_t page_id, uint8_t component_id, bool touch_event) {
40  this->trigger(page_id, component_id, touch_event);
41  });
42  }
43 };
44 
45 } // namespace nextion
46 } // namespace esphome
void add_new_page_callback(std::function< void(uint8_t)> &&callback)
Add a callback to be notified when the nextion changes pages.
Definition: nextion.cpp:185
void add_wake_state_callback(std::function< void()> &&callback)
Add a callback to be notified of wake state changes.
Definition: nextion.cpp:177
void add_setup_state_callback(std::function< void()> &&callback)
Add a callback to be notified when the nextion completes its initialize setup.
Definition: nextion.cpp:181
void trigger(Ts... x)
Inform the parent automation that the event has triggered.
Definition: automation.h:95
void add_sleep_state_callback(std::function< void()> &&callback)
Add a callback to be notified of sleep state changes.
Definition: nextion.cpp:173
WakeTrigger(Nextion *nextion)
Definition: automation.h:24
PageTrigger(Nextion *nextion)
Definition: automation.h:31
void add_touch_event_callback(std::function< void(uint8_t, uint8_t, bool)> &&callback)
Add a callback to be notified when Nextion has a touch event.
Definition: nextion.cpp:189
SleepTrigger(Nextion *nextion)
Definition: automation.h:17
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
SetupTrigger(Nextion *nextion)
Definition: automation.h:10
TouchTrigger(Nextion *nextion)
Definition: automation.h:38