Skip to content

Commit 9be7557

Browse files
authored
Merge pull request #57 from bxparks/develop
merge v1.2.2 into master
2 parents 88b345a + 90ba694 commit 9be7557

File tree

10 files changed

+142
-12
lines changed

10 files changed

+142
-12
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# Changelog
22

33
* Unreleased
4+
* 1.2.2 (2022-02-02)
5+
* Add a `using Print::write` statement in `StdioSerial.h` to
6+
pull in all other overloaded `write()` methods from the parent `Print`
7+
class.
48
* 1.2.1 (2022-01-10)
59
* Add `strncasecmp_P()` to `pgmspace.h`. See
610
[PR#52](https://github.com/bxparks/EpoxyDuino/pull/52).
7-
* Add [Bugs and Limitations](README.md##BugsAndLimitations) section in
11+
* Add [Bugs and Limitations](README.md#BugsAndLimitations) section in
812
README.md
913
* Add comment in [aunit_tests.yml](.github/workflows/aunit_tests.yml)
1014
that a `pull_request` event may be useful. Upgrade GitHub docker image to

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ The disadvantages are:
6868
environments (e.g. 16-bit `int` versus 32-bit `int`, or 32-bit `long` versus
6969
64-bit `long`).
7070

71-
**Version**: 1.2.1 (2022-01-10)
71+
**Version**: 1.2.2 (2022-02-02)
7272

7373
**Changelog**: See [CHANGELOG.md](CHANGELOG.md)
7474

@@ -990,6 +990,9 @@ The following environments are Tier 2 because I do not test them often enough:
990990
has implemented a slightly different version of the "Arduino API".
991991
* EpoxyDuino does not support the idiosyncrasies of all of these
992992
different Arduino platforms.
993+
* A few features relevant to the ESP8266 and ESP32 platforms can
994+
be activated by setting `EPOXY_CORE := EPOXY_CORE_ESP8266` in the
995+
`Makefile`. See [Alternate Arduino Core](#AlternateArduinoCore).
993996
* There is yet another version of the "Arduino API" described by
994997
[ArduinoCore-API](https://github.com/arduino/ArduinoCore-API).
995998
* Some Arduino-branded microcontrollers have been migrated to

cores/epoxy/Arduino.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#define EPOXY_DUINO_EPOXY_ARDUINO_H
1515

1616
// xx.yy.zz => xxyyzz (without leading 0)
17-
#define EPOXY_DUINO_VERSION 10201
18-
#define EPOXY_DUINO_VERSION_STRING "1.2.1"
17+
#define EPOXY_DUINO_VERSION 10202
18+
#define EPOXY_DUINO_VERSION_STRING "1.2.2"
1919

2020
#include <algorithm> // min(), max()
2121
#include <cmath> // abs()

cores/epoxy/Print.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,14 @@ class Print
6767
void clearWriteError() { setWriteError(0); }
6868

6969
virtual size_t write(uint8_t) = 0;
70+
7071
size_t write(const char *str) {
7172
if (str == NULL) return 0;
7273
return write((const uint8_t *)str, strlen(str));
7374
}
75+
7476
virtual size_t write(const uint8_t *buffer, size_t size);
77+
7578
size_t write(const char *buffer, size_t size) {
7679
return write((const uint8_t *)buffer, size);
7780
}

cores/epoxy/StdioSerial.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,23 @@ class StdioSerial: public Stream {
1919

2020
size_t write(uint8_t c) override;
2121

22+
// Pull in all other overloaded versions of the write() function from the
23+
// Print parent class. This is required because when we override one version
24+
// of write() above, C++ performs a static binding to the write() function
25+
// in the current class and doesn't bother searching the parent classes for
26+
// any other overloaded function that it could bind to. (30 years of C++ and
27+
// I still get shot with C++ footguns like this. I have no idea what happens
28+
// if the Stream class overloaded the write() function.)
29+
using Print::write;
30+
2231
operator bool() { return true; }
2332

2433
int available() override;
2534

2635
int read() override;
27-
36+
2837
int peek() override;
29-
38+
3039
private:
3140
int bufch;
3241
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# See https://github.com/bxparks/EpoxyDuino for documentation about this
22
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
33

4-
APP_NAME := echo
4+
APP_NAME := StdioSerialEcho
55
ARDUINO_LIBS :=
66
include ../../../EpoxyDuino/EpoxyDuino.mk

examples/echo/echo.ino renamed to examples/StdioSerialEcho/StdioSerialEcho.ino

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,27 @@
44
* Usage:
55
*
66
* To test keyboard input:
7-
* $ ./echo.out
7+
* $ ./StdioSerialEcho.out
88
* Echo test
99
* 'char' is signed.
1010
* # Type 'a', 'b', 'c, 'd' on keyboad
1111
* 61('a')62('b')63('c')64('d')
1212
*
1313
* To test reading of 0xFF character (which should not interfere with -1 error):
14-
* $ printf '\xff' | ./echo.out
14+
* $ printf '\xff' | ./StdioSerialEcho.out
1515
* Echo test
1616
* 'char' is signed.
1717
* FF(' ')
1818
*
1919
* To test reading from a directory, which generates a -1 error status when
2020
* ::read() is called:
21-
* $ ./echo.out < .
21+
* $ ./StdioSerialEcho.out < .
2222
* Echo test
2323
* 'char' is signed.
2424
* # Nothing should print.
2525
*
2626
* To test piping:
27-
* $ yes | ./echo.out
27+
* $ yes | ./StdioSerialEcho.out
2828
* Echo test
2929
* 'char' is signed.
3030
* 79('y')0A(' ')79('y')0A(' ')[...]
@@ -87,10 +87,17 @@ void loopImplicitly() {
8787
//-----------------------------------------------------------------------------
8888

8989
void setup(void) {
90+
#if ! defined(EPOXY_DUINO)
9091
delay(1000);
92+
#endif
93+
9194
Serial.begin(115200);
9295
while (!Serial);
9396

97+
#if defined(EPOXY_DUINO)
98+
Serial.setLineModeUnix();
99+
#endif
100+
94101
// Check if 'char' is a signed or unsigned on this system.
95102
Serial.println(F("Echo test"));
96103
char c = (char) 128;

examples/StdioSerialWrite/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# See https://github.com/bxparks/EpoxyDuino for documentation about this
2+
# Makefile to compile and run Arduino programs natively on Linux or MacOS.
3+
4+
APP_NAME := StdioSerialWrite
5+
ARDUINO_LIBS :=
6+
include ../../../EpoxyDuino/EpoxyDuino.mk
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* StdioSerialWrite makes ad-hoc calls to various print(), println(), and
3+
* write() output methods in the `Serial` object to verify that they work as
4+
* expected. This cannot be written as an AUnit unit test because we want to
5+
* test the StdioSerial class itself, not the Print parent class.
6+
*
7+
* On Linux or Mac, type:
8+
* * $ make
9+
* * $ ./StdioSerialWrite.out
10+
*
11+
* Should print out the following:
12+
*
13+
* ==== Testing print(s)
14+
* print(s)
15+
* ==== Testing println(s)
16+
* println(s)
17+
* ==== Testing print(F(s))
18+
* print(F(s))
19+
* ==== Testing println(F(s))
20+
* println(F(s))
21+
* ==== Testing write(c)
22+
* w
23+
* ==== Testing write(s)
24+
* some string
25+
* ==== Testing write(buf, n)
26+
* some
27+
*/
28+
29+
#include <Arduino.h>
30+
31+
void setup() {
32+
#if ! defined(EPOXY_DUINO)
33+
delay(1000); // some boards reboot twice
34+
#endif
35+
36+
SERIAL_PORT_MONITOR.begin(115200); // baud ignored on EpoxyDuino
37+
while (!SERIAL_PORT_MONITOR); // Wait on Leonardo/Micro, no-op on EpoxyDuino
38+
39+
#if defined(EPOXY_DUINO)
40+
SERIAL_PORT_MONITOR.setLineModeUnix();
41+
#endif
42+
43+
size_t n;
44+
45+
SERIAL_PORT_MONITOR.println(F("==== Testing print(s)"));
46+
n = SERIAL_PORT_MONITOR.print("print(s)");
47+
SERIAL_PORT_MONITOR.println();
48+
if (n != 8) {
49+
SERIAL_PORT_MONITOR.println("print(s) should have returned 8");
50+
}
51+
52+
SERIAL_PORT_MONITOR.println(F("==== Testing println(s)"));
53+
n = SERIAL_PORT_MONITOR.println("println(s)");
54+
if (n != 11) { // 10 + newline
55+
SERIAL_PORT_MONITOR.println("print(s) should have returned 11");
56+
}
57+
58+
SERIAL_PORT_MONITOR.println(F("==== Testing print(F(s))"));
59+
n = SERIAL_PORT_MONITOR.print(F("print(F(s))"));
60+
SERIAL_PORT_MONITOR.println();
61+
if (n != 11) {
62+
SERIAL_PORT_MONITOR.println(F("print(F(s)) should have returned 11"));
63+
}
64+
65+
SERIAL_PORT_MONITOR.println(F("==== Testing println(F(s))"));
66+
n = SERIAL_PORT_MONITOR.println(F("println(F(s))"));
67+
if (n != 14) { // 13 + newline
68+
SERIAL_PORT_MONITOR.println(F("println(F(s)) should have returned 14"));
69+
}
70+
71+
SERIAL_PORT_MONITOR.println(F("==== Testing write(c)"));
72+
n = SERIAL_PORT_MONITOR.write('w');
73+
SERIAL_PORT_MONITOR.println();
74+
if (n != 1) {
75+
SERIAL_PORT_MONITOR.println(F("write(c) should have returned 1"));
76+
}
77+
78+
const char buf[] = "some string"; // strlen(buf) == 11
79+
SERIAL_PORT_MONITOR.println(F("==== Testing write(s)"));
80+
n = SERIAL_PORT_MONITOR.write(buf);
81+
SERIAL_PORT_MONITOR.println();
82+
if (n != 11) {
83+
SERIAL_PORT_MONITOR.println(F("write(s) should have returned 11"));
84+
}
85+
86+
SERIAL_PORT_MONITOR.println(F("==== Testing write(buf, n)"));
87+
n = SERIAL_PORT_MONITOR.write((const uint8_t*) buf, 5);
88+
SERIAL_PORT_MONITOR.println();
89+
if (n != 5) {
90+
SERIAL_PORT_MONITOR.println(F("write(buf, n) should have returned 5"));
91+
}
92+
93+
#if defined(EPOXY_DUINO)
94+
exit(0);
95+
#endif
96+
}
97+
98+
void loop() {}

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "EpoxyDuino",
3-
"version": "1.2.1",
3+
"version": "1.2.2",
44
"description": "Compile and run Arduino programs natively on Linux, MacOS and FreeBSD.",
55
"keywords": [
66
"unit-test",

0 commit comments

Comments
 (0)