Skip to content

Commit 6294445

Browse files
committed
Use shorter button report. Change default color generation algorithm.
1 parent e2907ba commit 6294445

File tree

9 files changed

+80
-42
lines changed

9 files changed

+80
-42
lines changed

ClientSource/Libraries/MessageConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ int register_message_converters_framework_acks(){
197197
static const char HEX_DIGITS[] = "0123456789abcdef";
198198
for (size_t c = sizeof(seqnum_t); c < body.size(); c++){
199199
uint8_t byte = body[c];
200-
ss << " " << HEX_DIGITS[(byte >> 4)] << " " << HEX_DIGITS[byte & 15];
200+
ss << " " << HEX_DIGITS[(byte >> 4)] << HEX_DIGITS[byte & 15];
201201
}
202202
return ss.str();
203203
}

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_ESP32.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,38 @@ int register_message_converters_ESP32(){
5353
return ss.str();
5454
}
5555
);
56+
register_message_converter(
57+
PABB_MSG_ESP32_CONTROLLER_STATE_BUTTONS,
58+
[](const std::string& body){
59+
// Disable this by default since it's very spammy.
60+
if (!GlobalSettings::instance().LOG_EVERYTHING){
61+
return std::string();
62+
}
63+
std::ostringstream ss;
64+
ss << "PABB_MSG_ESP32_CONTROLLER_STATE_BUTTONS() - ";
65+
if (body.size() != sizeof(pabb_Message_ESP32_CommandButtonState)){ ss << "(invalid size)" << std::endl; return ss.str(); }
66+
const auto* params = (const pabb_Message_ESP32_CommandButtonState*)body.c_str();
67+
ss << "seqnum = " << (uint64_t)params->seqnum;
68+
ss << ", milliseconds = " << params->milliseconds;
69+
return ss.str();
70+
}
71+
);
72+
register_message_converter(
73+
PABB_MSG_ESP32_CONTROLLER_STATE_FULL,
74+
[](const std::string& body){
75+
// Disable this by default since it's very spammy.
76+
if (!GlobalSettings::instance().LOG_EVERYTHING){
77+
return std::string();
78+
}
79+
std::ostringstream ss;
80+
ss << "PABB_MSG_ESP32_CONTROLLER_STATE_FULL() - ";
81+
if (body.size() != sizeof(pabb_Message_ESP32_CommandFullState)){ ss << "(invalid size)" << std::endl; return ss.str(); }
82+
const auto* params = (const pabb_Message_ESP32_CommandFullState*)body.c_str();
83+
ss << "seqnum = " << (uint64_t)params->seqnum;
84+
ss << ", milliseconds = " << params->milliseconds;
85+
return ss.str();
86+
}
87+
);
5688
register_message_converter(
5789
PABB_MSG_ESP32_REPORT,
5890
[](const std::string& body){

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Routines_ESP32.h

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,37 @@ class MessageControllerSetColors : public BotBaseRequest{
8686
return BotBaseMessage(PABB_MSG_ESP32_REQUEST_SET_COLORS, params);
8787
}
8888
};
89-
class MessageControllerState : public BotBaseRequest{
89+
class MessageControllerStateButtons : public BotBaseRequest{
9090
public:
91-
pabb_esp32_report30 params;
92-
MessageControllerState(uint8_t ticks, bool active, NintendoSwitch_ESP32Report0x30 report)
91+
pabb_Message_ESP32_CommandButtonState params;
92+
MessageControllerStateButtons(uint16_t milliseconds, const NintendoSwitch_ButtonState& state)
9393
: BotBaseRequest(true)
9494
{
9595
params.seqnum = 0;
96-
params.ticks = ticks;
97-
params.active = active;
98-
params.report = report;
96+
params.milliseconds = milliseconds;
97+
params.buttons = state;
9998
}
10099
virtual BotBaseMessage message() const override{
101-
return BotBaseMessage(PABB_MSG_ESP32_REPORT, params);
100+
return BotBaseMessage(PABB_MSG_ESP32_CONTROLLER_STATE_BUTTONS, params);
101+
}
102+
};
103+
class MessageControllerStateFull : public BotBaseRequest{
104+
public:
105+
pabb_Message_ESP32_CommandFullState params;
106+
MessageControllerStateFull(
107+
uint16_t milliseconds,
108+
const NintendoSwitch_ButtonState& buttons,
109+
const NintendoSwitch_GyroState& gyro
110+
)
111+
: BotBaseRequest(true)
112+
{
113+
params.seqnum = 0;
114+
params.milliseconds = milliseconds;
115+
params.buttons = buttons;
116+
params.gyro = gyro;
117+
}
118+
virtual BotBaseMessage message() const override{
119+
return BotBaseMessage(PABB_MSG_ESP32_CONTROLLER_STATE_FULL, params);
102120
}
103121
};
104122

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ControllerSettings.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ namespace PokemonAutomation{
1616
namespace NintendoSwitch{
1717

1818

19+
uint32_t average_colors(uint32_t x, uint32_t y){
20+
// Average the two button colors.
21+
uint32_t red = ((x >> 16) & 0xff) + ((y >> 16) & 0xff);
22+
uint32_t green = ((x >> 8) & 0xff) + ((y >> 8) & 0xff);
23+
uint32_t blue = ((x >> 0) & 0xff) + ((y >> 0) & 0xff);
24+
red /= 2;
25+
green /= 2;
26+
blue /= 2;
27+
return (red << 16) | (green << 8) | (blue << 0);
28+
}
29+
1930

2031
struct OfficialJoyconColors{
2132
std::string name;
@@ -31,18 +42,8 @@ struct OfficialJoyconColors{
3142
// Set the grips to the joycon colors.
3243
profile.left_grip = left_body;
3344
profile.right_grip = right_body;
34-
35-
// Average the two button colors.
36-
uint32_t red = ((left_buttons >> 16) & 0xff) + ((right_buttons >> 16) & 0xff);
37-
uint32_t green = ((left_buttons >> 8) & 0xff) + ((right_buttons >> 8) & 0xff);
38-
uint32_t blue = ((left_buttons >> 0) & 0xff) + ((right_buttons >> 0) & 0xff);
39-
red /= 2;
40-
green /= 2;
41-
blue /= 2;
42-
profile.button_color = (red << 16) | (green << 8) | (blue << 0);
43-
44-
// Pick something for the controller body.
45-
profile.body_color = 0xd0d0d0;
45+
profile.body_color = average_colors(left_buttons, right_buttons);
46+
profile.button_color = average_colors(left_body, right_body);
4647
break;
4748
}
4849
case ControllerType::NintendoSwitch_LeftJoycon:

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,9 @@ void SerialPABotBase_WirelessController::stop(){
6565

6666
void SerialPABotBase_WirelessController::issue_report(
6767
const Cancellable* cancellable,
68-
const SerialPABotBase::NintendoSwitch_ESP32Report0x30& report,
68+
const SerialPABotBase::NintendoSwitch_ButtonState& buttons,
6969
WallDuration duration
7070
){
71-
bool is_active = this->is_active();
72-
7371
// Release the state lock since we are no longer touching state.
7472
// This loop can block indefinitely if the command queue is full.
7573
ReverseLockGuard<std::mutex> lg(m_state_lock);
@@ -80,7 +78,7 @@ void SerialPABotBase_WirelessController::issue_report(
8078
Milliseconds current_ms = std::min(time_left, 255 * 15ms);
8179
uint8_t current_ticks = (uint8_t)milliseconds_to_ticks_15ms(current_ms.count());
8280
m_serial->issue_request(
83-
SerialPABotBase::MessageControllerState(current_ticks, is_active, report),
81+
SerialPABotBase::MessageControllerStateButtons(current_ticks * 15, buttons),
8482
cancellable
8583
);
8684
time_left -= current_ms;

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

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

7676
void issue_report(
7777
const Cancellable* cancellable,
78-
const SerialPABotBase::NintendoSwitch_ESP32Report0x30& report,
78+
const SerialPABotBase::NintendoSwitch_ButtonState& buttons,
7979
WallDuration duration
8080
);
8181

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -129,17 +129,13 @@ void SerialPABotBase_WirelessJoycon::issue_mash_button(
129129
void SerialPABotBase_WirelessJoycon::push_state_left_joycon(const Cancellable* cancellable, WallDuration duration){
130130
// https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/bluetooth_hid_notes.md
131131

132-
SerialPABotBase::NintendoSwitch_ESP32Report0x30 report{
133-
.report_id = 0x30,
134-
.timer = 0, // Populate on controller.
135-
.byte2 = 0x9d, // Full + Charging : Joycon
132+
SerialPABotBase::NintendoSwitch_ButtonState report{
136133
.button3 = 0,
137134
.button4 = 0,
138135
.button5 = 0,
139136
.left_joystick = {0x00, 0x08, 0x80},
140137
.right_joystick = {0x00, 0x08, 0x80},
141138
.vibrator = 0x00,
142-
.gyro = {},
143139
};
144140

145141
for (size_t c = 0; c < TOTAL_BUTTONS; c++){
@@ -193,17 +189,13 @@ void SerialPABotBase_WirelessJoycon::push_state_left_joycon(const Cancellable* c
193189
void SerialPABotBase_WirelessJoycon::push_state_right_joycon(const Cancellable* cancellable, WallDuration duration){
194190
// https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/bluetooth_hid_notes.md
195191

196-
SerialPABotBase::NintendoSwitch_ESP32Report0x30 report{
197-
.report_id = 0x30,
198-
.timer = 0, // Populate on controller.
199-
.byte2 = 0x9d, // Full + Charging : Joycon
192+
SerialPABotBase::NintendoSwitch_ButtonState report{
200193
.button3 = 0,
201194
.button4 = 0,
202195
.button5 = 0,
203196
.left_joystick = {0x00, 0x08, 0x80},
204197
.right_joystick = {0x00, 0x08, 0x80},
205198
.vibrator = 0x00,
206-
.gyro = {},
207199
};
208200

209201
for (size_t c = 0; c < TOTAL_BUTTONS; c++){

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,13 @@ SerialPABotBase_WirelessProController::~SerialPABotBase_WirelessProController(){
3636
void SerialPABotBase_WirelessProController::push_state(const Cancellable* cancellable, WallDuration duration){
3737
// https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/bluetooth_hid_notes.md
3838

39-
SerialPABotBase::NintendoSwitch_ESP32Report0x30 report{
40-
.report_id = 0x30,
41-
.timer = 0, // Populate on controller.
42-
.byte2 = 0x99, // Full + charging : Pro controller + USB powered
39+
SerialPABotBase::NintendoSwitch_ButtonState report{
4340
.button3 = 0,
4441
.button4 = 0,
4542
.button5 = 0,
4643
.left_joystick = {0x00, 0x08, 0x80},
4744
.right_joystick = {0x00, 0x08, 0x80},
4845
.vibrator = 0x00,
49-
.gyro = {},
5046
};
5147

5248

SerialPrograms/Source/PokemonSwSh/Programs/DateSpamFarmers/PokemonSwSh_DateSpam-WattFarmer.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ WattFarmer_Descriptor::WattFarmer_Descriptor()
3737

3838
WattFarmer::WattFarmer()
3939
: GRIP_MENU_WAIT0(
40-
"<b>Exit Grip Menu Delay:</b> "
40+
"<b>Exit Grip Menu Delay:</b><br>"
4141
"Wait this long after leaving the grip menu to allow for the Switch to reestablish local connection.",
4242
LockMode::LOCK_WHILE_RUNNING,
4343
"5000 ms"
4444
)
4545
, EXIT_DEN_WAIT(
46-
"<b>Exit Den Wait Time:</b> "
46+
"<b>Exit Den Wait Time:</b><br>"
4747
"Wait this long after backing out of the den before date skipping.",
4848
LockMode::LOCK_WHILE_RUNNING,
4949
"1720 ms"
@@ -62,6 +62,7 @@ WattFarmer::WattFarmer()
6262
&NOTIFICATION_PROGRAM_FINISH,
6363
})
6464
{
65+
PA_ADD_OPTION(GRIP_MENU_WAIT0);
6566
PA_ADD_OPTION(START_LOCATION);
6667
PA_ADD_OPTION(EXIT_DEN_WAIT);
6768
PA_ADD_OPTION(SKIPS);

0 commit comments

Comments
 (0)