Skip to content

Commit bbbda4e

Browse files
committed
Fix serial error messages not sticking.
1 parent 50b5ec2 commit bbbda4e

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_StatusThread.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include "Common/Cpp/PrettyPrint.h"
1313
#include "SerialPABotBase_Connection.h"
1414

15+
//#include <iostream>
16+
//using std::cout;
17+
//using std::endl;
18+
1519
namespace PokemonAutomation{
1620
namespace SerialPABotBase{
1721

@@ -35,6 +39,7 @@ class ControllerStatusThread{
3539
: m_connection(connection)
3640
, m_callback(callback)
3741
, m_stopping(false)
42+
, m_error(false)
3843
, m_status_thread(&ControllerStatusThread::status_thread, this)
3944
{}
4045
~ControllerStatusThread(){
@@ -61,7 +66,10 @@ class ControllerStatusThread{
6166
std::thread watchdog([&, this]{
6267
WallClock next_ping = current_time();
6368
while (true){
64-
if (m_stopping.load(std::memory_order_relaxed) || !m_connection.is_ready()){
69+
if (m_stopping.load(std::memory_order_relaxed) ||
70+
m_error.load(std::memory_order_acquire) ||
71+
!m_connection.is_ready()
72+
){
6573
break;
6674
}
6775

@@ -75,7 +83,10 @@ class ControllerStatusThread{
7583
}
7684

7785
std::unique_lock<std::mutex> lg(m_sleep_lock);
78-
if (m_stopping.load(std::memory_order_relaxed) || !m_connection.is_ready()){
86+
if (m_stopping.load(std::memory_order_relaxed) ||
87+
m_error.load(std::memory_order_acquire) ||
88+
!m_connection.is_ready()
89+
){
7990
break;
8091
}
8192

@@ -101,8 +112,8 @@ class ControllerStatusThread{
101112
last_ack.store(current_time(), std::memory_order_relaxed);
102113
}catch (OperationCancelledException&){
103114
break;
104-
}catch (InvalidConnectionStateException&){
105-
break;
115+
}catch (InvalidConnectionStateException& e){
116+
error = e.message();
106117
}catch (SerialProtocolException& e){
107118
error = e.message();
108119
}catch (ConnectionException& e){
@@ -111,6 +122,7 @@ class ControllerStatusThread{
111122
error = "Unknown error.";
112123
}
113124
if (!error.empty()){
125+
m_error.store(true, std::memory_order_release);
114126
m_connection.set_status_line1(error, COLOR_RED);
115127
m_callback.stop_with_error(std::move(error));
116128
}
@@ -140,6 +152,7 @@ class ControllerStatusThread{
140152
ControllerStatusThreadCallback& m_callback;
141153
CancellableHolder<CancellableScope> m_scope;
142154
std::atomic<bool> m_stopping;
155+
std::atomic<bool> m_error;
143156
std::mutex m_sleep_lock;
144157
std::condition_variable m_cv;
145158
std::thread m_status_thread;

SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_SerialPABotBase_WirelessController.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ void SerialPABotBase_WirelessController::update_status(Cancellable& cancellable)
329329
"Invalid response size to PABB_MSG_ESP32_REQUEST_READ_SPI: body = " + std::to_string(response.body.size()),
330330
COLOR_RED
331331
);
332-
m_handle.set_status_line1("Error: See log for more information.", COLOR_RED);
332+
// m_handle.set_status_line1("Error: See log for more information.", COLOR_RED);
333333
return;
334334
}
335335
m_logger.log("Reading Controller Colors... Done");
@@ -355,8 +355,7 @@ void SerialPABotBase_WirelessController::update_status(Cancellable& cancellable)
355355

356356
}catch (Exception& e){
357357
e.log(m_logger);
358-
m_handle.set_status_line1("Error: See log for more information.", COLOR_RED);
359-
return;
358+
throw;
360359
}
361360
}
362361

0 commit comments

Comments
 (0)