ESPHome  2024.11.1
automation.h
Go to the documentation of this file.
1 #pragma once
2 
4 #include "microphone.h"
5 
6 #include <vector>
7 
8 namespace esphome {
9 namespace microphone {
10 
11 template<typename... Ts> class CaptureAction : public Action<Ts...>, public Parented<Microphone> {
12  void play(Ts... x) override { this->parent_->start(); }
13 };
14 
15 template<typename... Ts> class StopCaptureAction : public Action<Ts...>, public Parented<Microphone> {
16  void play(Ts... x) override { this->parent_->stop(); }
17 };
18 
19 class DataTrigger : public Trigger<const std::vector<int16_t> &> {
20  public:
21  explicit DataTrigger(Microphone *mic) {
22  mic->add_data_callback([this](const std::vector<int16_t> &data) { this->trigger(data); });
23  }
24 };
25 
26 template<typename... Ts> class IsCapturingCondition : public Condition<Ts...>, public Parented<Microphone> {
27  public:
28  bool check(Ts... x) override { return this->parent_->is_running(); }
29 };
30 
31 } // namespace microphone
32 } // namespace esphome
void add_data_callback(std::function< void(const std::vector< int16_t > &)> &&data_callback)
Definition: microphone.h:23
uint16_t x
Definition: tt21100.cpp:17
DataTrigger(Microphone *mic)
Definition: automation.h:21
Base class for all automation conditions.
Definition: automation.h:74
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Helper class to easily give an object a parent of type T.
Definition: helpers.h:522