Shellminator  V1.1.1
Simple Terminal
Loading...
Searching...
No Matches
Shellminator-IO.cpp
Go to the documentation of this file.
1/*
2 * Created on Aug 10 2020
3 *
4 * Copyright (c) 2020 - Daniel Hajnal
5 * hajnal.daniel96@gmail.com
6 * This file is part of the Shellminator project.
7 * Modified 2022.05.08
8*/
9
10/*
11MIT License
12
13Copyright (c) 2020 Daniel Hajnal
14
15Permission is hereby granted, free of charge, to any person obtaining a copy
16of this software and associated documentation files (the "Software"), to deal
17in the Software without restriction, including without limitation the rights
18to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19copies of the Software, and to permit persons to whom the Software is
20furnished to do so, subject to the following conditions:
21
22The above copyright notice and this permission notice shall be included in all
23copies or substantial portions of the Software.
24
25THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
29LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
30OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31SOFTWARE.
32*/
33
34#include "Shellminator-IO.hpp"
35
36#ifdef SHELLMINATOR_USE_ARDUINO_SERIAL
37
38//----- Response for Arduino Serial Class -----//
39
40void shellminatorArduinoSerialChannel::select( HardwareSerial *serialPort_p ){
41
42 serialPort = serialPort_p;
43
44}
45
47
48 if( serialPort ) return serialPort -> available();
49 return 0;
50
51}
52
54
55 if( serialPort ) return serialPort -> read();
56 return -1;
57
58}
59
61
62 if( serialPort ) return serialPort -> peek();
63 return -1;
64
65}
66
68
69 if( serialPort ) return serialPort -> flush();
70
71}
72
74
75
76 if( serialPort ) return serialPort -> write( b );
77 return 0;
78
79}
80
82
83
84 if( serialPort ) return serialPort -> print( b );
85 return 0;
86
87}
88
90
91 if( serialPort ) return serialPort -> print( (char)c );
92 return 0;
93
94}
95
97
98 if( serialPort ) return serialPort -> print( (char*)str );
99 return 0;
100
101}
102
104
105 if( serialPort ) return serialPort -> print( (char*)str );
106 return 0;
107
108}
109
111
112 return serialPort;
113
114}
115
116
117#endif
118
119#ifdef SHELLMINATOR_USE_ARDUINO_32U4_SERIAL
120
121//----- Response for Arduino Serial Class -----//
122
124
125 serialPort = serialPort_p;
126
127}
128
130
131 if( serialPort ) return serialPort -> available();
132 return 0;
133
134}
135
137
138 if( serialPort ) return serialPort -> read();
139 return -1;
140
141}
142
144
145 if( serialPort ) return serialPort -> peek();
146 return -1;
147
148}
149
151
152 if( serialPort ) return serialPort -> flush();
153
154}
155
157
158
159 if( serialPort ) return serialPort -> write( b );
160 return 0;
161
162}
163
165
166
167 if( serialPort ) return serialPort -> print( b );
168 return 0;
169
170}
171
173
174 if( serialPort ) return serialPort -> print( (char)c );
175 return 0;
176
177}
178
180
181 if( serialPort ) return serialPort -> print( (char*)str );
182 return 0;
183
184}
185
187
188 if( serialPort ) return serialPort -> print( (char*)str );
189 return 0;
190
191}
192
194
195 return serialPort;
196
197}
198
199
200#endif
201
202#ifdef SHELLMINATOR_USE_WIFI_CLIENT
203
204//----- Response for WiFi Client Class -----//
205
206void shellminatorWiFiClientChannel::select( WiFiClient *client_p ){
207
208 client = client_p;
209
210}
211
213
214 if( client ) return client -> available();
215 return 0;
216
217}
218
220
221 if( client ) return client -> read();
222 return -1;
223
224}
225
227
228 if( client ) return client -> peek();
229 return -1;
230
231}
232
234
235 if( client ) return client -> flush();
236
237}
238
240
241 if( client ) return client -> write( b );
242 return 0;
243
244}
245
246//---- print section ----//
247
249
250 if( client ) return client -> print( c );
251 return 0;
252
253}
254
256
257 if( client ) return client -> print( b );
258 return 0;
259
260}
261
263
264 if( client ) return client -> print( str );
265 return 0;
266
267}
268
269size_t shellminatorWiFiClientChannel::print( const char *str ){
270
271 if( client ) return client -> print( str );
272 return 0;
273
274}
275
277
278 return client;
279
280}
281
282#endif
size_t print(char c) override
Print one character to the channel.
void select(Serial_ *serialPort_p)
Select Serial Port.
Serial_ * getSerialObject()
Get the address of the chosen Serial Port.
int read() override
Read one byte form the channel.
int peek() override
Peek the firtst byte from the channel.
void flush() override
Flush the channel.
int available() override
Available bytes in the channel.
size_t write(uint8_t b) override
Write one byte to the channel.
size_t write(uint8_t b) override
Write one byte to the channel.
int peek() override
Peek the firtst byte from the channel.
int read() override
Read one byte form the channel.
int available() override
Available bytes in the channel.
void select(HardwareSerial *serialPort_p)
Select Serial Port.
HardwareSerial * getSerialObject()
Get the address of the chosen Serial Port.
size_t print(char c) override
Print one character to the channel.
void flush() override
Flush the channel.
size_t print(char c) override
Print one character to the channel.
int available() override
Available bytes in the channel.
void flush() override
Flush the channel.
void select(WiFiClient *client_p)
Select WiFi Client.
size_t write(uint8_t b) override
Write one byte to the channel.
int peek() override
Peek the firtst byte from the channel.
int read() override
Read one byte form the channel.
WiFiClient * getClientObject()
Get the address of the chosen WiFi Client.