Skip to content

Commit 8c7ab09

Browse files
committed
Use SPI read/write instead of colors directly.
1 parent adb165f commit 8c7ab09

File tree

5 files changed

+112
-4
lines changed

5 files changed

+112
-4
lines changed

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Connection.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ ControllerModeStatus SerialPABotBase_Connection::read_device_specs(
249249
}
250250

251251
m_botbase->issue_request_and_wait(
252-
MessageControllerSetColors(desired_controller, colors),
252+
MessageControllerWriteSpi(
253+
desired_controller,
254+
0x00006050, sizeof(NintendoSwitch_ControllerColors),
255+
&colors
256+
),
257+
// MessageControllerSetColors(desired_controller, colors),
253258
nullptr
254259
);
255260
}

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_ESP32.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66

77
#include <sstream>
8+
#include "Common/Cpp/PrettyPrint.h"
89
#include "Common/SerialPABotBase/SerialPABotBase_Messages_ESP32.h"
910
#include "ClientSource/Libraries/MessageConverter.h"
1011
#include "CommonFramework/GlobalSettingsPanel.h"
@@ -30,6 +31,35 @@ int register_message_converters_ESP32(){
3031
return ss.str();
3132
}
3233
);
34+
register_message_converter(
35+
PABB_MSG_ESP32_REQUEST_READ_SPI,
36+
[](const std::string& body){
37+
std::ostringstream ss;
38+
ss << "PABB_MSG_ESP32_REQUEST_READ_SPI() - ";
39+
if (body.size() != sizeof(pabb_Message_ESP32_ReadSpi)){ ss << "(invalid size)" << std::endl; return ss.str(); }
40+
const auto* params = (const pabb_Message_ESP32_ReadSpi*)body.c_str();
41+
ss << "seqnum = " << params->seqnum;
42+
ss << ", controller = " << params->controller_type;
43+
ss << ", address = 0x" << tostr_hex(params->address);
44+
ss << ", bytes = " << (size_t)params->bytes;
45+
return ss.str();
46+
}
47+
);
48+
register_message_converter(
49+
PABB_MSG_ESP32_REQUEST_WRITE_SPI,
50+
[](const std::string& body){
51+
std::ostringstream ss;
52+
ss << "PABB_MSG_ESP32_REQUEST_WRITE_SPI() - ";
53+
if (body.size() <= sizeof(pabb_Message_ESP32_WriteSpi)){ ss << "(invalid size)" << std::endl; return ss.str(); }
54+
const auto* params = (const pabb_Message_ESP32_WriteSpi*)body.c_str();
55+
ss << "seqnum = " << params->seqnum;
56+
ss << ", controller = " << params->controller_type;
57+
ss << ", address = 0x" << tostr_hex(params->address);
58+
ss << ", bytes = " << (size_t)params->bytes;
59+
return ss.str();
60+
}
61+
);
62+
#if 0
3363
register_message_converter(
3464
PABB_MSG_ESP32_REQUEST_GET_COLORS,
3565
[](const std::string& body){
@@ -53,6 +83,7 @@ int register_message_converters_ESP32(){
5383
return ss.str();
5484
}
5585
);
86+
#endif
5687
register_message_converter(
5788
PABB_MSG_ESP32_CONTROLLER_STATE_BUTTONS,
5889
[](const std::string& body){
@@ -85,6 +116,7 @@ int register_message_converters_ESP32(){
85116
return ss.str();
86117
}
87118
);
119+
#if 0
88120
register_message_converter(
89121
PABB_MSG_ESP32_REPORT,
90122
[](const std::string& body){
@@ -102,6 +134,7 @@ int register_message_converters_ESP32(){
102134
return ss.str();
103135
}
104136
);
137+
#endif
105138
return 0;
106139
}
107140
int init_Messages_ESP32 = register_message_converters_ESP32();

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_ESP32.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,70 @@ class MessageControllerStatus : public BotBaseRequest{
3030
return BotBaseMessage(PABB_MSG_ESP32_REQUEST_STATUS, params);
3131
}
3232
};
33+
class MessageControllerReadSpi : public BotBaseRequest{
34+
public:
35+
pabb_Message_ESP32_ReadSpi params;
36+
MessageControllerReadSpi(ControllerType controller_type, uint32_t address, uint8_t bytes)
37+
: BotBaseRequest(false)
38+
{
39+
uint32_t controller_id = PABB_CID_NONE;
40+
switch (controller_type){
41+
case ControllerType::NintendoSwitch_WirelessProController:
42+
controller_id = PABB_CID_NINTENDO_SWITCH_WIRELESS_PRO_CONTROLLER;
43+
break;
44+
case ControllerType::NintendoSwitch_LeftJoycon:
45+
controller_id = PABB_CID_NINTENDO_SWITCH_LEFT_JOYCON;
46+
break;
47+
case ControllerType::NintendoSwitch_RightJoycon:
48+
controller_id = PABB_CID_NINTENDO_SWITCH_RIGHT_JOYCON;
49+
break;
50+
default:;
51+
}
52+
params.seqnum = 0;
53+
params.controller_type = controller_id;
54+
params.address = address;
55+
params.bytes = bytes;
56+
}
57+
virtual BotBaseMessage message() const override{
58+
return BotBaseMessage(PABB_MSG_ESP32_REQUEST_READ_SPI, params);
59+
}
60+
};
61+
class MessageControllerWriteSpi : public BotBaseRequest{
62+
public:
63+
std::string data;
64+
MessageControllerWriteSpi(
65+
ControllerType controller_type,
66+
uint32_t address, uint8_t bytes,
67+
const void* p_data
68+
)
69+
: BotBaseRequest(false)
70+
{
71+
uint32_t controller_id = PABB_CID_NONE;
72+
switch (controller_type){
73+
case ControllerType::NintendoSwitch_WirelessProController:
74+
controller_id = PABB_CID_NINTENDO_SWITCH_WIRELESS_PRO_CONTROLLER;
75+
break;
76+
case ControllerType::NintendoSwitch_LeftJoycon:
77+
controller_id = PABB_CID_NINTENDO_SWITCH_LEFT_JOYCON;
78+
break;
79+
case ControllerType::NintendoSwitch_RightJoycon:
80+
controller_id = PABB_CID_NINTENDO_SWITCH_RIGHT_JOYCON;
81+
break;
82+
default:;
83+
}
84+
pabb_Message_ESP32_WriteSpi params;
85+
params.seqnum = 0;
86+
params.controller_type = controller_id;
87+
params.address = address;
88+
params.bytes = bytes;
89+
data = std::string((char*)&params, sizeof(params));
90+
data += std::string((const char*)p_data, bytes);
91+
}
92+
virtual BotBaseMessage message() const override{
93+
return BotBaseMessage(PABB_MSG_ESP32_REQUEST_WRITE_SPI, data);
94+
}
95+
};
96+
#if 0
3397
class MessageControllerGetColors : public BotBaseRequest{
3498
public:
3599
pabb_Message_ESP32_GetColors params;
@@ -86,6 +150,7 @@ class MessageControllerSetColors : public BotBaseRequest{
86150
return BotBaseMessage(PABB_MSG_ESP32_REQUEST_SET_COLORS, params);
87151
}
88152
};
153+
#endif
89154
class MessageControllerStateButtons : public BotBaseRequest{
90155
public:
91156
pabb_Message_ESP32_CommandButtonState params;

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,17 @@ void SerialPABotBase_WirelessController::status_thread(){
117117
#if 1
118118
try{
119119
m_logger.log("Reading Controller Colors...");
120+
121+
using ControllerColors = SerialPABotBase::NintendoSwitch_ControllerColors;
122+
120123
BotBaseMessage response = m_serial->issue_request_and_wait(
121-
SerialPABotBase::MessageControllerGetColors(m_controller_type),
124+
SerialPABotBase::MessageControllerReadSpi(
125+
m_controller_type,
126+
0x00006050, sizeof(ControllerColors)
127+
),
122128
&m_scope
123129
);
124130

125-
using ControllerColors = SerialPABotBase::NintendoSwitch_ControllerColors;
126131
ControllerColors colors{};
127132
if (response.body.size() == sizeof(seqnum_t) + sizeof(ControllerColors)){
128133
memcpy(&colors, response.body.data() + sizeof(seqnum_t), sizeof(ControllerColors));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class SerialPABotBase_WirelessController : public SerialPABotBase_Controller{
3434

3535
public:
3636
Milliseconds ticksize() const{
37-
return Milliseconds(15);
37+
return Milliseconds(0);
3838
}
3939
Milliseconds cooldown() const{
4040
return Milliseconds(15);

0 commit comments

Comments
 (0)