-
Notifications
You must be signed in to change notification settings - Fork 6
/
Port_ESPEasySerial_base.h
110 lines (79 loc) · 2.34 KB
/
Port_ESPEasySerial_base.h
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_BASE_H
#define ESPEASYSERIAL_PORT_ESPEASYSERIAL_BASE_H
#include "ESPEasySerialPort.h"
#include "ESPEasySerial_common_defines.h"
#include "ESPEasySerialConfig.h"
#include <Stream.h>
class Port_ESPEasySerial_base {
public:
Port_ESPEasySerial_base();
virtual ~Port_ESPEasySerial_base();
virtual void begin(unsigned long baud) = 0;
virtual void end() = 0;
virtual int available(void) = 0;
virtual int availableForWrite(void) = 0;
// return -1 when data is unavailable (arduino api)
virtual int peek(void) = 0;
virtual int read(void) = 0;
virtual size_t read(uint8_t *buffer,
size_t size) = 0;
inline size_t read(char *buffer, size_t size)
{
return read((uint8_t *)buffer, size);
}
virtual void flush(void) = 0;
virtual void flush(bool txOnly) = 0;
virtual size_t write(uint8_t) = 0;
virtual size_t write(const uint8_t *buffer,
size_t size) = 0;
inline size_t write(const char *buffer, size_t size)
{
return write((uint8_t *)buffer, size);
}
inline size_t write(const char *s)
{
return write((uint8_t *)s, strlen(s));
}
inline size_t write(unsigned long n)
{
return write((uint8_t)n);
}
inline size_t write(long n)
{
return write((uint8_t)n);
}
inline size_t write(unsigned int n)
{
return write((uint8_t)n);
}
inline size_t write(int n)
{
return write((uint8_t)n);
}
virtual int getBaudRate() const;
virtual operator bool() const = 0;
virtual void setDebugOutput(bool) = 0;
virtual size_t setRxBufferSize(size_t new_size) = 0;
virtual size_t setTxBufferSize(size_t new_size) = 0;
const ESPEasySerialConfig& getSerialConfig() const {
return _config;
}
#ifdef ESP8266
void setPortConfig(unsigned long baud,
SerialConfig config,
SerialMode mode)
{
_config.setPortConfig(baud, config, mode);
}
#endif // ifdef ESP8266
#ifdef ESP32
void setPortConfig(unsigned long baud, uint32_t config)
{
_config.setPortConfig(baud, config);
}
#endif // ifdef ESP32
virtual String getPortDescription() const;
protected:
ESPEasySerialConfig _config;
};
#endif // ifndef ESPEASYSERIAL_PORT_ESPEASYSERIAL_BASE_H