@@ -12,6 +12,7 @@ const char* const TAG = "SerialInputHandler";
1212#include " FormatHelpers.h"
1313#include " http/HTTPRequestManager.h"
1414#include " Logging.h"
15+ #include " serial/SerialCompat.h"
1516#include " serial/command_handlers/CommandEntry.h"
1617#include " serial/command_handlers/common.h"
1718#include " serial/command_handlers/index.h"
@@ -367,7 +368,7 @@ enum class SerialReadResult {
367368SerialReadResult _tryReadSerialLine (SerialBuffer& buffer)
368369{
369370 // Check if there's any data available
370- int available = ::Serial. available ();
371+ int available = OpenShockSerialAvailable ();
371372 if (available <= 0 ) {
372373 return SerialReadResult::NoData;
373374 }
@@ -377,11 +378,18 @@ SerialReadResult _tryReadSerialLine(SerialBuffer& buffer)
377378
378379 // Read the data into the buffer
379380 while (available-- > 0 ) {
380- char c = ::Serial.read ();
381+ int r = OpenShockSerialRead ();
382+ if (r < 0 ) {
383+ break ; // no more data even though the previous length said otherwise
384+ }
385+
386+ char c = static_cast <char >(r);
381387
382388 // Handle backspace
383389 if (c == ' \b ' ) {
384- buffer.pop_back (); // Remove the last character from the buffer if it exists
390+ if (!buffer.empty ()) {
391+ buffer.pop_back (); // Remove the last character from the buffer if it exists
392+ }
385393 continue ;
386394 }
387395
@@ -413,10 +421,15 @@ SerialReadResult _tryReadSerialLine(SerialBuffer& buffer)
413421
414422void _skipSerialWhitespaces (SerialBuffer& buffer)
415423{
416- int available = ::Serial. available ();
424+ int available = OpenShockSerialAvailable ();
417425
418426 while (available-- > 0 ) {
419- char c = ::Serial.read ();
427+ int r = OpenShockSerialRead ();
428+ if (r < 0 ) {
429+ break ;
430+ }
431+
432+ char c = static_cast <char >(r);
420433
421434 if (c != ' ' && c != ' \r ' && c != ' \n ' ) {
422435 buffer.push_back (c);
0 commit comments