Skip to content

Commit de11465

Browse files
committed
Add ESP32 status message request.
1 parent 9b05fa5 commit de11465

File tree

4 files changed

+47
-20
lines changed

4 files changed

+47
-20
lines changed

Common/NintendoSwitch/NintendoSwitch_Protocol_ESP32.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ namespace NintendoSwitch{
2323
#endif
2424

2525

26+
27+
28+
#define PABB_MSG_ESP32_REQUEST_STATUS 0x50
29+
typedef struct{
30+
seqnum_t seqnum;
31+
} PABB_PACK pabb_esp32_RequestStatus;
32+
33+
34+
35+
36+
2637
typedef struct{
2738
uint8_t report_id;
2839
uint8_t timer;
@@ -40,7 +51,7 @@ typedef struct{
4051
uint8_t gyro[49 - 13];
4152
} PABB_PACK ESP32Report0x30;
4253

43-
#define PABB_MSG_ESP32_REPORT 0x9e
54+
#define PABB_MSG_ESP32_REPORT 0x9e
4455
typedef struct{
4556
seqnum_t seqnum;
4657
uint8_t ticks;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,6 @@ void SerialPABotBase_PokkenController::status_thread(){
142142
break;
143143
}
144144

145-
std::string str;
146145
std::string error;
147146
try{
148147
pabb_MsgAckRequestI32 response;

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

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,23 @@ SerialPABotBase_WirelessProController::~SerialPABotBase_WirelessProController(){
5353

5454

5555

56-
class SerialPABotBase_WirelessProController::Message : public BotBaseRequest{
56+
57+
class SerialPABotBase_WirelessProController::MessageControllerStatus : public BotBaseRequest{
58+
public:
59+
pabb_esp32_RequestStatus params;
60+
MessageControllerStatus()
61+
: BotBaseRequest(false)
62+
{
63+
params.seqnum = 0;
64+
}
65+
virtual BotBaseMessage message() const override{
66+
return BotBaseMessage(PABB_MSG_ESP32_REQUEST_STATUS, params);
67+
}
68+
};
69+
class SerialPABotBase_WirelessProController::MessageControllerState : public BotBaseRequest{
5770
public:
5871
pabb_esp32_report30 params;
59-
Message(uint8_t ticks, ESP32Report0x30 report)
72+
MessageControllerState(uint8_t ticks, ESP32Report0x30 report)
6073
: BotBaseRequest(true)
6174
{
6275
params.seqnum = 0;
@@ -159,7 +172,7 @@ void SerialPABotBase_WirelessProController::push_state(const Cancellable* cancel
159172
Milliseconds current_ms = std::min(time_left, 255 * 15ms);
160173
uint8_t current_ticks = (uint8_t)milliseconds_to_ticks_15ms(current_ms.count());
161174
m_serial->issue_request(
162-
Message(current_ticks, report),
175+
MessageControllerState(current_ticks, report),
163176
cancellable
164177
);
165178
time_left -= current_ms;
@@ -210,27 +223,30 @@ void SerialPABotBase_WirelessProController::status_thread(){
210223
break;
211224
}
212225

213-
std::string str;
214226
std::string error;
215227
try{
216228
pabb_MsgAckRequestI32 response;
217229
m_serial->issue_request_and_wait(
218-
NintendoSwitch::DeviceRequest_system_clock(),
230+
MessageControllerStatus(),
219231
&scope
220232
).convert<PABB_MSG_ACK_REQUEST_I32>(logger(), response);
221233
last_ack.store(current_time(), std::memory_order_relaxed);
222-
uint32_t wallclock = response.data;
223-
if (wallclock == 0){
224-
m_handle.set_status_line1(
225-
"Not connected to Switch.",
226-
COLOR_RED
227-
);
228-
}else{
229-
m_handle.set_status_line1(
230-
"Status Reports: " + tostr_u_commas(wallclock),
231-
theme_friendly_darkblue()
232-
);
233-
}
234+
235+
uint32_t status = response.data;
236+
bool status_paired = status & 1;
237+
bool status_connected = status & 2;
238+
239+
std::string str;
240+
str += "Paired: " + (status_paired
241+
? html_color_text("Yes", theme_friendly_darkblue())
242+
: html_color_text("No", COLOR_RED)
243+
);
244+
str += ", Connected: " + (status_connected
245+
? html_color_text("Yes", theme_friendly_darkblue())
246+
: html_color_text("No", COLOR_RED)
247+
);
248+
249+
m_handle.set_status_line1(str);
234250
}catch (InvalidConnectionStateException&){
235251
break;
236252
}catch (SerialProtocolException& e){

SerialPrograms/Source/NintendoSwitch/Controllers/SerialPABotBase/NintendoSwitch_WirelessProController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ class SerialPABotBase_WirelessProController final : public SerialPABotBase_ProCo
2626
~SerialPABotBase_WirelessProController();
2727

2828
public:
29-
class Message;
29+
class MessageControllerStatus;
30+
class MessageControllerState;
3031

3132
private:
3233
template <typename Type>

0 commit comments

Comments
 (0)