Skip to content

Commit 3f02bcb

Browse files
Add SoftwareSerial::stopListening()
This allows one to explicitly stop a SoftwareSerial instance from listening, without having to make another one listening.
1 parent 7366268 commit 3f02bcb

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

libraries/SoftwareSerial/SoftwareSerial.cpp

+11
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,17 @@ bool SoftwareSerial::listen()
195195
return false;
196196
}
197197

198+
// Stop listening. Returns true if we were actually listening.
199+
bool SoftwareSerial::stopListening()
200+
{
201+
if (active_object == this)
202+
{
203+
active_object = NULL;
204+
return true;
205+
}
206+
return false;
207+
}
208+
198209
//
199210
// The receive routine called by the interrupt handler
200211
//

libraries/SoftwareSerial/SoftwareSerial.h

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class SoftwareSerial : public Stream
8787
bool listen();
8888
void end();
8989
bool isListening() { return this == active_object; }
90+
bool stopListening();
9091
bool overflow() { bool ret = _buffer_overflow; _buffer_overflow = false; return ret; }
9192
int peek();
9293

0 commit comments

Comments
 (0)