-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSerialProtocol.h
More file actions
95 lines (78 loc) · 1.92 KB
/
SerialProtocol.h
File metadata and controls
95 lines (78 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef __SERIAL_H__
#define __SERIAL_H__
#include <Arduino.h>
#include "Player.h"
#include "WaveTooEasy_Protocol.h"
class SerialProtocol
{
public:
static inline SerialProtocol& getInstance()
{
static SerialProtocol serial_protocol;
return serial_protocol;
}
static uint32_t cbMillis()
{
return millis();
}
static uint8_t cbReceive(uint8_t* c, void* param)
{
SerialProtocol* p = (SerialProtocol*) param;
if (p->serial->available())
{
*c = p->serial->read();
return 1;
}
return 0;
}
static void cbSend(uint8_t* data, size_t len, void* param)
{
SerialProtocol* p = (SerialProtocol*) param;
p->serial->write(data, len);
}
void begin(UARTClass& uart, uint32_t baudrate = 115200)
{
serial = &uart;
serial->begin(baudrate);
wteInit(cbMillis, cbReceive, cbSend, this);
}
void end()
{
serial->end();
}
bool pullPacket(wtePacket* packet)
{
return wtePullPacket(packet, 2);
}
void sendPacket(wtePacket* packet)
{
wtePushPacket(packet);
}
void sendErrorCode(uint8_t code)
{
wteSendErrorCode(code);
}
bool poll();
private:
SerialProtocol() : serial(NULL) {}
Player* verify(wtePacket* packet);
void onPlayFile(wtePacket* packet);
void onPlayChannel(wtePacket* packet);
void onStopAll(wtePacket* packet);
void onStop(wtePacket* packet);
void onPause(wtePacket* packet);
void onPauseAll(wtePacket* packet);
void onResume(wtePacket* packet);
void onResumeAll(wtePacket* packet);
void onChannelsStatus(wtePacket* packet);
void onChannelStatus(wtePacket* packet);
void onGetChannelVolume(wtePacket* packet);
void onSetChannelVolume(wtePacket* packet);
void onSetSpeakersVolume(wtePacket* packet);
void onSetHeadphoneVolume(wtePacket* packet);
void onGetSpeakersVolume(wtePacket* packet);
void onGetHeadphoneVolume(wtePacket* packet);
UARTClass* serial;
wtePacket packet;
};
#endif /* __SERIAL_H__ */