Skip to content

Commit 8a0a2fc

Browse files
committed
Show console MAC address and player lights if firmware supports it.
1 parent edc37c8 commit 8a0a2fc

13 files changed

+217
-63
lines changed

Common/SerialPABotBase/SerialPABotBase_Messages_NS1_OemControllers.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,46 @@ typedef struct{
3737

3838

3939

40-
#define PABB_MSG_INFO_NS1_OEM_CONTROLLER_RUMBLE 0x30
40+
#define PABB_MSG_INFO_NS1_OEM_CONTROLLER_RUMBLE 0x30
4141
typedef struct{
4242
pabb_NintendoSwitch_Rumble rumble;
4343
} PABB_PACK pabb_MsgInfo_NS1_OemController_Rumble;
4444

4545

4646

47-
#define PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_READ_SPI 0x60
47+
#define PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_READ_SPI 0x60
4848
typedef struct{
4949
seqnum_t seqnum;
5050
uint32_t controller_type;
5151
uint32_t address;
5252
uint8_t bytes;
5353
} PABB_PACK pabb_Message_NS1_OemController_ReadSpi;
5454

55-
#define PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_WRITE_SPI 0x61
55+
#define PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_WRITE_SPI 0x61
5656
typedef struct{
5757
seqnum_t seqnum;
5858
uint32_t controller_type;
5959
uint32_t address;
6060
uint8_t bytes;
6161
} PABB_PACK pabb_Message_NS1_OemController_WriteSpi;
6262

63+
#define PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_PLAYER_LIGHTS 0x62
64+
typedef struct{
65+
seqnum_t seqnum;
66+
uint32_t controller_type;
67+
} PABB_PACK pabb_MsgInfo_NS1_OemController_PlayerLights;
68+
6369

6470

65-
#define PABB_MSG_COMMAND_NS1_OEM_CONTROLLER_BUTTONS 0xa0
71+
#define PABB_MSG_COMMAND_NS1_OEM_CONTROLLER_BUTTONS 0xa0
6672
typedef struct{
6773
seqnum_t seqnum;
6874
uint16_t milliseconds;
6975
pabb_NintendoSwitch_OemController_State0x30_Buttons buttons;
7076
} PABB_PACK pabb_Message_Command_NS1_OemController_Buttons;
7177

7278

73-
#define PABB_MSG_COMMAND_NS1_OEM_CONTROLLER_FULL_STATE 0xa1
79+
#define PABB_MSG_COMMAND_NS1_OEM_CONTROLLER_FULL_STATE 0xa1
7480
typedef struct{
7581
seqnum_t seqnum;
7682
uint16_t milliseconds;

Common/SerialPABotBase/SerialPABotBase_Protocol.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,12 @@ typedef struct{
359359
uint32_t mode;
360360
} PABB_PACK pabb_MsgRequestReadMacAddress;
361361

362+
#define PABB_MSG_REQUEST_PAIRED_MAC_ADDRESS 0x52
363+
typedef struct{
364+
seqnum_t seqnum;
365+
uint32_t mode;
366+
} PABB_PACK pabb_MsgRequestPairedMacAddress;
367+
362368
////////////////////////////////////////////////////////////////////////////////
363369
// Commands
364370

SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Info.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class MessageType_Info_String : public BotBaseMessageType{
8282
return true;
8383
}
8484
virtual std::string tostr(const std::string& body) const override{
85-
return BotBaseMessageType::tostr(body) + body;
85+
return BotBaseMessageType::tostr(body) + ": " + body;
8686
}
8787
};
8888
class MessageType_Info_Label_i32 : public BotBaseMessageType{

SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_BaseProtocol_Misc.h

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#define PokemonAutomation_SerialPABotBase_MessageWrappers_BaseProtocol_Misc_H
99

1010
#include "Common/SerialPABotBase/SerialPABotBase_Protocol.h"
11+
#include "Controllers/ControllerTypes.h"
12+
#include "Controllers/SerialPABotBase/SerialPABotBase.h"
1113
#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h"
1214

1315
namespace PokemonAutomation{
@@ -91,7 +93,7 @@ class MessageControllerStatus : public BotBaseRequest{
9193

9294

9395
class MessageType_ReadMacAddress : public BotBaseMessageType{
94-
using Params = pabb_Message_RequestStatus;
96+
using Params = pabb_MsgRequestReadMacAddress;
9597
public:
9698
MessageType_ReadMacAddress()
9799
: BotBaseMessageType(
@@ -126,6 +128,46 @@ class DeviceRequest_read_mac_address : public BotBaseRequest{
126128

127129

128130

131+
class MessageType_PairedMacAddress : public BotBaseMessageType{
132+
using Params = pabb_MsgRequestPairedMacAddress;
133+
public:
134+
MessageType_PairedMacAddress()
135+
: BotBaseMessageType(
136+
"PABB_MSG_REQUEST_PAIRED_MAC_ADDRESS",
137+
PABB_MSG_REQUEST_PAIRED_MAC_ADDRESS,
138+
sizeof(Params)
139+
)
140+
{}
141+
virtual bool should_print(const std::string& body) const override{
142+
return GlobalSettings::instance().LOG_EVERYTHING;
143+
}
144+
virtual std::string tostr(const std::string& body) const override{
145+
std::string ret = BotBaseMessageType::tostr(body);
146+
if (!is_valid(body)){
147+
return ret;
148+
}
149+
Params params;
150+
memcpy(&params, body.data(), sizeof(params));
151+
ret += ": seqnum = " + std::to_string(params.seqnum);
152+
ret += ", mode = " + std::to_string(params.mode);
153+
return ret;
154+
}
155+
};
156+
class DeviceRequest_paired_mac_address : public BotBaseRequest{
157+
public:
158+
pabb_MsgRequestPairedMacAddress params{};
159+
DeviceRequest_paired_mac_address(ControllerType controller_type)
160+
: BotBaseRequest(false)
161+
{
162+
params.mode = controller_type_to_id(controller_type);
163+
}
164+
virtual BotBaseMessage message() const override{
165+
return BotBaseMessage(PABB_MSG_REQUEST_PAIRED_MAC_ADDRESS, params);
166+
}
167+
};
168+
169+
170+
129171
}
130172
}
131173
#endif

SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_HID_Keyboard.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
/* SerialPABotBase Messages - HID Keyboard
1+
/* SerialPABotBase Messages - StandardHid: HID Keyboard
22
*
33
* From: https://github.com/PokemonAutomation/
44
*
55
*/
66

7-
#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_HID_Keyboard_H
8-
#define PokemonAutomation_SerialPABotBase_MessageWrappers_HID_Keyboard_H
7+
#ifndef PokemonAutomation_StandardHid_MessageWrappers_HID_Keyboard_H
8+
#define PokemonAutomation_StandardHid_MessageWrappers_HID_Keyboard_H
99

1010
#include "Common/SerialPABotBase/SerialPABotBase_Messages_HID_Keyboard.h"
1111
#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h"
1212

1313
namespace PokemonAutomation{
14-
namespace SerialPABotBase{
14+
namespace StandardHid{
1515

1616

1717

SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS1_OemControllers.h

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,60 @@
1-
/* SerialPABotBase Messages - NS1 OEM Controllers
1+
/* SerialPABotBase Messages - NintendoSwitch OEM Controllers
22
*
33
* From: https://github.com/PokemonAutomation/
44
*
55
*/
66

7-
#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_NS1_OemControllers_H
8-
#define PokemonAutomation_SerialPABotBase_MessageWrappers_NS1_OemControllers_H
7+
#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_NintendoSwitch_OemControllers_H
8+
#define PokemonAutomation_SerialPABotBase_MessageWrappers_NintendoSwitch_OemControllers_H
99

1010
#include "Common/SerialPABotBase/SerialPABotBase_Messages_NS1_OemControllers.h"
1111
#include "Controllers/ControllerTypes.h"
1212
#include "Controllers/SerialPABotBase/SerialPABotBase.h"
13-
#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h"
13+
//#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h"
1414
#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h"
1515

1616
namespace PokemonAutomation{
17-
namespace SerialPABotBase{
17+
namespace NintendoSwitch{
18+
19+
20+
21+
class MessageType_NS1_PlayerLights : public BotBaseMessageType{
22+
using Params = pabb_MsgInfo_NS1_OemController_PlayerLights;
23+
public:
24+
MessageType_NS1_PlayerLights()
25+
: BotBaseMessageType(
26+
"PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_PLAYER_LIGHTS",
27+
PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_PLAYER_LIGHTS,
28+
sizeof(Params)
29+
)
30+
{}
31+
virtual bool should_print(const std::string& body) const override{
32+
return GlobalSettings::instance().LOG_EVERYTHING;
33+
}
34+
virtual std::string tostr(const std::string& body) const override{
35+
std::string ret = BotBaseMessageType::tostr(body);
36+
if (!is_valid(body)){
37+
return ret;
38+
}
39+
Params params;
40+
memcpy(&params, body.data(), sizeof(params));
41+
ret += ": seqnum = " + std::to_string(params.seqnum);
42+
return ret;
43+
}
44+
};
45+
class DeviceRequest_PlayerLights : public BotBaseRequest{
46+
public:
47+
pabb_MsgInfo_NS1_OemController_PlayerLights params;
48+
DeviceRequest_PlayerLights(ControllerType controller_type)
49+
: BotBaseRequest(false)
50+
{
51+
params.seqnum = 0;
52+
params.controller_type = SerialPABotBase::controller_type_to_id(controller_type);
53+
}
54+
virtual BotBaseMessage message() const override{
55+
return BotBaseMessage(PABB_MSG_REQUEST_NS1_OEM_CONTROLLER_PLAYER_LIGHTS, params);
56+
}
57+
};
1858

1959

2060

@@ -35,21 +75,21 @@ class MessageType_NS1_ReadSpi : public BotBaseMessageType{
3575
}
3676
Params params;
3777
memcpy(&params, body.data(), sizeof(params));
38-
ret += "seqnum = " + std::to_string(params.seqnum);
78+
ret += ": seqnum = " + std::to_string(params.seqnum);
3979
ret += ", controller = " + std::to_string(params.controller_type);
4080
ret += ", address = 0x" + tostr_hex(params.address);
4181
ret += ", bytes = " + std::to_string((size_t)params.bytes);
4282
return ret;
4383
}
4484
};
45-
class MessageControllerReadSpi : public BotBaseRequest{
85+
class DeviceRequest_NS1_ReadSpi : public BotBaseRequest{
4686
public:
4787
pabb_Message_NS1_OemController_ReadSpi params;
48-
MessageControllerReadSpi(ControllerType controller_type, uint32_t address, uint8_t bytes)
88+
DeviceRequest_NS1_ReadSpi(ControllerType controller_type, uint32_t address, uint8_t bytes)
4989
: BotBaseRequest(false)
5090
{
5191
params.seqnum = 0;
52-
params.controller_type = controller_type_to_id(controller_type);
92+
params.controller_type = SerialPABotBase::controller_type_to_id(controller_type);
5393
params.address = address;
5494
params.bytes = bytes;
5595
}
@@ -80,17 +120,17 @@ class MessageType_NS1_WriteSpi : public BotBaseMessageType{
80120
}
81121
Params params;
82122
memcpy(&params, body.data(), sizeof(params));
83-
ret += "seqnum = " + std::to_string(params.seqnum);
123+
ret += ": seqnum = " + std::to_string(params.seqnum);
84124
ret += ", controller = " + std::to_string(params.controller_type);
85125
ret += ", address = 0x" + tostr_hex(params.address);
86126
ret += ", bytes = " + std::to_string((size_t)params.bytes);
87127
return ret;
88128
}
89129
};
90-
class MessageControllerWriteSpi : public BotBaseRequest{
130+
class DeviceRequest_NS1_WriteSpi : public BotBaseRequest{
91131
public:
92132
std::string data;
93-
MessageControllerWriteSpi(
133+
DeviceRequest_NS1_WriteSpi(
94134
ControllerType controller_type,
95135
uint32_t address, uint8_t bytes,
96136
const void* p_data
@@ -99,7 +139,7 @@ class MessageControllerWriteSpi : public BotBaseRequest{
99139
{
100140
pabb_Message_NS1_OemController_WriteSpi params;
101141
params.seqnum = 0;
102-
params.controller_type = controller_type_to_id(controller_type);
142+
params.controller_type = SerialPABotBase::controller_type_to_id(controller_type);
103143
params.address = address;
104144
params.bytes = bytes;
105145
data = std::string((char*)&params, sizeof(params));
@@ -137,10 +177,10 @@ class MessageType_NS1_OemControllerStateButtons : public BotBaseMessageType{
137177
return ret;
138178
}
139179
};
140-
class MessageControllerStateButtons : public BotBaseRequest{
180+
class DeviceRequest_ControllerStateButtons : public BotBaseRequest{
141181
public:
142182
pabb_Message_Command_NS1_OemController_Buttons params;
143-
MessageControllerStateButtons(
183+
DeviceRequest_ControllerStateButtons(
144184
uint16_t milliseconds,
145185
const pabb_NintendoSwitch_OemController_State0x30_Buttons& state
146186
)
@@ -182,10 +222,10 @@ class MessageType_NS1_OemControllerStateFull : public BotBaseMessageType{
182222
return ret;
183223
}
184224
};
185-
class MessageControllerStateFull : public BotBaseRequest{
225+
class DeviceRequest_ControllerStateFull : public BotBaseRequest{
186226
public:
187227
pabb_Message_Command_NS1_OemController_FullState params;
188-
MessageControllerStateFull(
228+
DeviceRequest_ControllerStateFull(
189229
uint16_t milliseconds,
190230
const pabb_NintendoSwitch_OemController_State0x30_Buttons& buttons,
191231
const pabb_NintendoSwitch_OemController_State0x30_GyroX3& gyro

SerialPrograms/Source/Controllers/SerialPABotBase/Messages/SerialPABotBase_MessageWrappers_NS_WiredController.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
/* SerialPABotBase Messages - NS Wired Controller
1+
/* SerialPABotBase Messages - NintendoSwitch: Wired Controller
22
*
33
* From: https://github.com/PokemonAutomation/
44
*
55
*/
66

7-
#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_NS_WiredController_H
8-
#define PokemonAutomation_SerialPABotBase_MessageWrappers_NS_WiredController_H
7+
#ifndef PokemonAutomation_SerialPABotBase_MessageWrappers_NintendoSwitch_WiredController_H
8+
#define PokemonAutomation_SerialPABotBase_MessageWrappers_NintendoSwitch_WiredController_H
99

1010
#include "Common/SerialPABotBase/SerialPABotBase_Messages_NS_WiredController.h"
1111
#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h"
1212
#include "Controllers/SerialPABotBase/Connection/BotBaseMessage.h"
1313

1414
namespace PokemonAutomation{
15-
namespace SerialPABotBase{
15+
namespace NintendoSwitch{
1616

1717

1818

19-
class MessageType_NS_WiredController_ControllerStateMs : public BotBaseMessageType{
19+
class MessageType_WiredController_ControllerStateMs : public BotBaseMessageType{
2020
using Params = pabb_Message_Command_NS_WiredController_State;
2121
public:
22-
MessageType_NS_WiredController_ControllerStateMs()
22+
MessageType_WiredController_ControllerStateMs()
2323
: BotBaseMessageType(
2424
"PABB_MSG_COMMAND_NS_WIRED_CONTROLLER_STATE",
2525
PABB_MSG_COMMAND_NS_WIRED_CONTROLLER_STATE,
@@ -56,10 +56,10 @@ class MessageType_NS_WiredController_ControllerStateMs : public BotBaseMessageTy
5656
return ret;
5757
}
5858
};
59-
class DeviceRequest_NS_WiredController_ControllerStateMs : public BotBaseRequest{
59+
class DeviceRequest_WiredController_ControllerStateMs : public BotBaseRequest{
6060
public:
6161
pabb_Message_Command_NS_WiredController_State params;
62-
DeviceRequest_NS_WiredController_ControllerStateMs(
62+
DeviceRequest_WiredController_ControllerStateMs(
6363
uint16_t milliseconds,
6464
uint16_t buttons,
6565
uint8_t dpad_byte,

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ void SerialPABotBase_Connection::add_message_printers(){
180180
add_message_printer<MessageType_SystemClock>();
181181
add_message_printer<MessageType_ControllerStatus>();
182182
add_message_printer<MessageType_ReadMacAddress>();
183+
add_message_printer<MessageType_PairedMacAddress>();
183184
}
184185
void SerialPABotBase_Connection::process_queue_size(){
185186
m_logger.log("Requesting queue size...");
@@ -205,7 +206,7 @@ ControllerType SerialPABotBase_Connection::process_device(bool set_to_null_contr
205206
const std::map<pabb_ProgramID, uint8_t>* PROGRAMS;
206207
{
207208
m_logger.Logger::log("Checking Protocol Version...");
208-
m_protocol = protocol_version(*m_botbase);
209+
m_protocol = SerialPABotBase::protocol_version(*m_botbase);
209210
m_logger.Logger::log("Checking Protocol Version... (" + std::to_string(m_protocol) + ")");
210211
auto iter = SUPPORTED_VERSIONS().find(m_protocol / 100);
211212
if (iter == SUPPORTED_VERSIONS().end()){

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ class SerialPABotBase_Connection : public ControllerConnection{
4242
const std::string& device_name() const{
4343
return m_device_name;
4444
}
45+
uint32_t protocol_version() const{
46+
return m_protocol;
47+
}
48+
4549
BotBaseController* botbase();
4650

4751
ControllerType refresh_controller_type();

SerialPrograms/Source/Controllers/StandardHid/StandardHid_Keyboard_SerialPABotBase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ void SerialPABotBase_Keyboard::execute_state(
204204
while (time_left > Milliseconds::zero()){
205205
Milliseconds current = std::min(time_left, 65535ms);
206206
m_serial->issue_request(
207-
SerialPABotBase::DeviceRequest_HID_Keyboard_StateMs(
207+
DeviceRequest_HID_Keyboard_StateMs(
208208
(uint16_t)current.count(),
209209
report
210210
),

0 commit comments

Comments
 (0)