Fix startup block with USB serial adapter connected

We were using the "wrong" readable method which always returned readable == true but getc on serial will block if no data is available.
This commit is contained in:
Hogthrob
2019-08-28 17:41:04 +02:00
committed by Martin Jaeger
parent 41f142c112
commit 7e1d1374a2
2 changed files with 16 additions and 6 deletions
+1 -1
View File
@@ -58,7 +58,7 @@ void ThingSetStream::process_asap()
*/
void ThingSetStream::process_input()
{
while (stream->readable() && command_flag == false) {
while (readable() && command_flag == false) {
int c = stream->getc();
+15 -5
View File
@@ -38,6 +38,11 @@ class ThingSetStream: public ThingSetDevice
virtual void process_input(); // this is called from the ISR typically
const unsigned int channel;
virtual bool readable()
{
return stream->readable();
}
private:
Stream* stream;
@@ -50,15 +55,20 @@ class ThingSetStream: public ThingSetDevice
template<typename T> class ThingSetSerial: public ThingSetStream
{
public:
ThingSetSerial(T& s, const unsigned int c): ThingSetStream(s,c), ser(&s) {}
ThingSetSerial(T& s, const unsigned int c): ThingSetStream(s,c), ser(s) {}
virtual void enable() { {
void enable() {
Callback<void()> cb([this]() -> void { this->process_input();});
ser->attach(cb);
ser.attach(cb);
}
}
private:
T* ser;
bool readable()
{
return ser.readable();
}
private:
T& ser;
};
#endif /* THINGSET_SERIAL_H */