Skip to content

Commit d4bf6a7

Browse files
committed
Fix inheritance of overloaded Print / Write functions
1 parent 02a5e51 commit d4bf6a7

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1717

1818
### Fixed
1919
- Compile errors / portability issues in `WString.h` and `Print.h`, first reported by `dfrencham` on GitHub
20+
- Compile errors / inheritance issues in `Print.h` and `Stream.h`, first reported by `dfrencham` on GitHub
2021

2122
### Security
2223

SampleProjects/TestSomething/test/serial.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@ unittest(serial_ports)
4343
assertEqual("bcdefg", state->serialPort[0].dataOut);
4444
}
4545

46+
unittest(all_serial_writes)
47+
{
48+
GodmodeState* state = GODMODE();
49+
state->serialPort[0].dataIn = "";
50+
state->serialPort[0].dataOut = "";
51+
52+
char str[4] = "xyz";
53+
Serial.write(reinterpret_cast<const uint8_t *>(str ), 3);
54+
Serial.print((int)1);
55+
Serial.print((long)2);
56+
Serial.print((double)3.4);
57+
Serial.print((char)'a');
58+
Serial.print("b");
59+
}
60+
4661
#endif
4762

4863
unittest_main()

cpp/arduino/HardwareSerial.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@ class HardwareSerial : public Stream, public ObservableDataStream
5757
return 1;
5858
}
5959

60-
inline size_t write(unsigned long n) { return write((uint8_t)n); }
61-
inline size_t write(long n) { return write((uint8_t)n); }
62-
inline size_t write(unsigned int n) { return write((uint8_t)n); }
63-
inline size_t write(int n) { return write((uint8_t)n); }
64-
// using Print::write; // pull in write(str) and write(buf, size) from Print
60+
// https://stackoverflow.com/a/4271276
61+
using Print::write; // pull in write(str) and write(buf, size) from Print
6562
operator bool() { return true; }
6663

6764
};

cpp/arduino/Stream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ class Stream : public Print
5656
return ret;
5757
}
5858

59+
// https://stackoverflow.com/a/4271276
5960
using Print::write;
6061

6162
virtual size_t write(uint8_t aChar) { mGodmodeDataIn->append(String((char)aChar)); return 1; }
6263

63-
6464
Stream() {
6565
mTimeoutMillis = 1000;
6666
mGodmodeMicrosDelay = NULL;

0 commit comments

Comments
 (0)