ESPHome
2024.10.2
esphome
esphome
components
speaker
speaker.h
Go to the documentation of this file.
1
#pragma once
2
3
#include <cstddef>
4
#include <cstdint>
5
#include <vector>
6
7
namespace
esphome
{
8
namespace
speaker {
9
10
enum
State
: uint8_t {
11
STATE_STOPPED
= 0,
12
STATE_STARTING
,
13
STATE_RUNNING
,
14
STATE_STOPPING
,
15
};
16
17
class
Speaker
{
18
public
:
19
virtual
size_t
play
(
const
uint8_t *data,
size_t
length
) = 0;
20
size_t
play
(
const
std::vector<uint8_t> &data) {
return
this->
play
(data.data(), data.size()); }
21
22
virtual
void
start
() = 0;
23
virtual
void
stop
() = 0;
24
// In compare between *STOP()* and *FINISH()*; *FINISH()* will stop after emptying the play buffer,
25
// while *STOP()* will break directly.
26
// When finish() is not implemented on the plateform component it should just do a normal stop.
27
virtual
void
finish
() { this->
stop
(); }
28
29
virtual
bool
has_buffered_data
()
const
= 0;
30
31
bool
is_running
()
const
{
return
this->
state_
==
STATE_RUNNING
; }
32
bool
is_stopped
()
const
{
return
this->
state_
==
STATE_STOPPED
; }
33
34
protected
:
35
State
state_
{
STATE_STOPPED
};
36
};
37
38
}
// namespace speaker
39
}
// namespace esphome
esphome::speaker::Speaker::play
virtual size_t play(const uint8_t *data, size_t length)=0
esphome::speaker::Speaker::is_running
bool is_running() const
Definition:
speaker.h:31
esphome::speaker::Speaker::state_
State state_
Definition:
speaker.h:35
esphome::speaker::STATE_STOPPED
Definition:
speaker.h:11
esphome::speaker::Speaker
Definition:
speaker.h:17
esphome::speaker::Speaker::finish
virtual void finish()
Definition:
speaker.h:27
esphome::speaker::Speaker::has_buffered_data
virtual bool has_buffered_data() const =0
esphome::speaker::Speaker::is_stopped
bool is_stopped() const
Definition:
speaker.h:32
esphome::speaker::Speaker::play
size_t play(const std::vector< uint8_t > &data)
Definition:
speaker.h:20
esphome::speaker::State
State
Definition:
speaker.h:10
esphome::speaker::STATE_STARTING
Definition:
speaker.h:12
esphome::speaker::STATE_STOPPING
Definition:
speaker.h:14
esphome::speaker::Speaker::start
virtual void start()=0
length
uint16_t length
Definition:
tt21100.cpp:12
esphome
Implementation of SPI Controller mode.
Definition:
a01nyub.cpp:7
esphome::speaker::STATE_RUNNING
Definition:
speaker.h:13
esphome::speaker::Speaker::stop
virtual void stop()=0
Generated by
1.8.13