Shellminator  V1.2.0
Simple Terminal
Loading...
Searching...
No Matches
Shellminator-IO.hpp
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#ifndef SHELLMINATOR_IO_HPP_
35#define SHELLMINATOR_IO_HPP_
36
38
39#ifdef ARDUINO
40#include "Arduino.h"
41#endif
42
43// This library needs an abstract class called Stream, to communicate with the
44// peripherals. If you use the Arduino environment, it is implemented already.
45// If you are make your own implementation, please check Arduino Stream class.
46// It can help a lot to implement your own.
47#include "Stream.h"
48
49#ifdef SHELLMINATOR_USE_WIFI_CLIENT
50 #ifdef ESP8266
51 #include <ESP8266WiFi.h>
52 #endif
53
54 #ifdef ESP32
55 #include <WiFi.h>
56 #endif
57#endif
58
59#ifdef SHELLMINATOR_ENABLE_WEBSOCKET_MODULE
60#include <WebSocketsServer.h>
61#endif
62
73class shellminatorDefaultChannel : public Stream{
74
75public:
76
80 int available() { return 0; }
81
85 int read() { return -1; }
86
90 int peek() { return 0; }
91
93 void flush() { return; }
94
99 size_t write( uint8_t b ) { return 0; }
100
105 size_t print( char c ) { return 0; }
106
111 size_t print( uint8_t b ) { return 0; }
112
117 size_t print( char *str ) { return 0; }
118
123 size_t print( const char *str ) { return 0; }
124
125};
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158#ifdef SHELLMINATOR_ENABLE_WEBSOCKET_MODULE
159
160class shellminatorWebSocketChannel : public Stream{
161
162public:
163
168 void select( WebSocketsServer *server_p, int8_t clientID_p );
169
170 void push( uint8_t data );
171
172 void push( uint8_t* data, size_t size );
173
177 int available() override;
178
182 int read() override;
183
187 int peek() override;
188
190 void flush() override;
191
196 size_t write( uint8_t b ) override;
197
198 size_t write( const uint8_t *buffer, size_t size ) override;
199
204 size_t print( char c );
205
210 size_t print( uint8_t b );
211
216 size_t print( char *str );
217
222 size_t print( const char *str );
223
224 int8_t getClientID();
225
226private:
227 uint8_t buffer[ SHELLMINATOR_WEBSOCKET_BUFFER_LEN ];
228 uint32_t readPointer = 0;
229 uint32_t writePointer = 0;
230
231 WebSocketsServer *server = NULL;
232 int8_t clientID = -1;
233
234};
235
236#endif
237
238
239
240
241
242
243
244
245
246
247
248
249#endif
Shellminator channel class.
size_t print(char *str)
Print c-string to the channel.
int read()
Read one byte form the channel.
size_t print(const char *str)
Print c-string to the channel.
int available()
Available bytes in the channel.
size_t print(uint8_t b)
Print one byte to the channel.
int peek()
Peek the firsts byte from the channel.
void flush()
Flush the channel.
size_t write(uint8_t b)
Write one byte to the channel.
size_t print(char c)
Print one character to the channel.