Skip to content

Commit 9596489

Browse files
committed
Add files
1 parent 1656762 commit 9596489

File tree

3 files changed

+112
-3
lines changed

3 files changed

+112
-3
lines changed

cores/esp32/Arduino.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050

5151
#define millis() (esp_timer_get_time() / 1000ULL)
5252
#define micros64() (esp_timer_get_time())
53+
#define micros() ((unsigned long)(esp_timer_get_time()))
5354

5455
#define PI 3.1415926535897932384626433832795
5556
#define HALF_PI 1.5707963267948966192313216916398
@@ -193,10 +194,11 @@ extern "C" {
193194
#include <cmath>
194195

195196
//--//#include "WCharacter.h"
196-
//--//#include "WString.h"
197+
#include "WString.h"
197198
#include "Stream.h"
198-
//--//#include "Printable.h"
199-
//--//#include "Print.h"
199+
#include "StreamString.h"
200+
#include "Printable.h"
201+
#include "Print.h"
200202
//--//#include "IPAddress.h"
201203
//--//#include "Client.h"
202204
//--//#include "Server.h"

cores/esp32/StreamString.cpp

+67
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/**
2+
StreamString.cpp
3+
4+
Copyright (c) 2015 Markus Sattler. All rights reserved.
5+
This file is part of the esp8266 core for Arduino environment.
6+
7+
This library is free software; you can redistribute it and/or
8+
modify it under the terms of the GNU Lesser General Public
9+
License as published by the Free Software Foundation; either
10+
version 2.1 of the License, or (at your option) any later version.
11+
12+
This library is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
Lesser General Public License for more details.
16+
17+
You should have received a copy of the GNU Lesser General Public
18+
License along with this library; if not, write to the Free Software
19+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20+
21+
*/
22+
23+
#include <Arduino.h>
24+
#include "StreamString.h"
25+
26+
size_t StreamString::write(const uint8_t *data, size_t size) {
27+
if(size && data) {
28+
const unsigned int newlen = length() + size;
29+
if(reserve(newlen + 1)) {
30+
memcpy((void *) (wbuffer() + len()), (const void *) data, size);
31+
setLen(newlen);
32+
*(wbuffer() + newlen) = 0x00; // add null for string end
33+
return size;
34+
}
35+
}
36+
return 0;
37+
}
38+
39+
size_t StreamString::write(uint8_t data) {
40+
return concat((char) data);
41+
}
42+
43+
int StreamString::available() {
44+
return length();
45+
}
46+
47+
int StreamString::read() {
48+
if(length()) {
49+
char c = charAt(0);
50+
remove(0, 1);
51+
return c;
52+
53+
}
54+
return -1;
55+
}
56+
57+
int StreamString::peek() {
58+
if(length()) {
59+
char c = charAt(0);
60+
return c;
61+
}
62+
return -1;
63+
}
64+
65+
void StreamString::flush() {
66+
}
67+

cores/esp32/StreamString.h

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
StreamString.h
3+
4+
Copyright (c) 2015 Markus Sattler. All rights reserved.
5+
6+
This library is free software; you can redistribute it and/or
7+
modify it under the terms of the GNU Lesser General Public
8+
License as published by the Free Software Foundation; either
9+
version 2.1 of the License, or (at your option) any later version.
10+
11+
This library is distributed in the hope that it will be useful,
12+
but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
Lesser General Public License for more details.
15+
16+
You should have received a copy of the GNU Lesser General Public
17+
License along with this library; if not, write to the Free Software
18+
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19+
20+
*/
21+
22+
#ifndef STREAMSTRING_H_
23+
#define STREAMSTRING_H_
24+
#include "Stream.h"
25+
#include "WString.h"
26+
27+
class StreamString: public Stream, public String
28+
{
29+
public:
30+
size_t write(const uint8_t *buffer, size_t size) override;
31+
size_t write(uint8_t data) override;
32+
33+
int available() override;
34+
int read() override;
35+
int peek() override;
36+
void flush() override;
37+
};
38+
39+
40+
#endif /* STREAMSTRING_H_ */

0 commit comments

Comments
 (0)