Skip to content

Commit c0c5432

Browse files
committed
More ESP32 fixes.
1 parent da67b5e commit c0c5432

File tree

3 files changed

+39
-14
lines changed

3 files changed

+39
-14
lines changed

SerialPrograms/Source/CommonFramework/VideoPipeline/Backends/CameraWidgetQt6.5.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ void CameraSession::startup(){
467467
}
468468

469469
void CameraSession::on_watchdog_timeout(){
470-
m_logger.log("CameraSession::on_watchdog_timeout()", COLOR_RED);
470+
// m_logger.log("CameraSession::on_watchdog_timeout()", COLOR_RED);
471471
{
472472
std::lock_guard<std::mutex> lg(m_lock);
473473
if (!m_device){

SerialPrograms/Source/NintendoSwitch/Controllers/NintendoSwitch_ProControllerWithScheduler.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,24 @@ struct ProControllerSchedulerState{
3434
SwitchButton_Dpad m_dpad;
3535
SwitchButton_Joystick m_left_joystick;
3636
SwitchButton_Joystick m_right_joystick;
37+
38+
bool is_active() const{
39+
for (size_t c = 0; c < 14; c++){
40+
if (m_buttons[c].is_busy()){
41+
return true;
42+
}
43+
}
44+
if (m_dpad.is_busy()){
45+
return true;
46+
}
47+
if (m_left_joystick.is_busy()){
48+
return true;
49+
}
50+
if (m_right_joystick.is_busy()){
51+
return true;
52+
}
53+
return false;
54+
}
3755
};
3856

3957

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

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
#include "CommonFramework/GlobalSettingsPanel.h"
1414
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
1515
#include "Controllers/ControllerCapability.h"
16-
#include "NintendoSwitch/Commands/NintendoSwitch_Messages_Device.h"
1716
#include "NintendoSwitch_WirelessProController.h"
1817

1918
//#include <iostream>
@@ -74,11 +73,12 @@ class SerialPABotBase_WirelessProController::MessageControllerStatus : public Bo
7473
class SerialPABotBase_WirelessProController::MessageControllerState : public BotBaseRequest{
7574
public:
7675
pabb_esp32_report30 params;
77-
MessageControllerState(uint8_t ticks, ESP32Report0x30 report)
76+
MessageControllerState(uint8_t ticks, bool active, ESP32Report0x30 report)
7877
: BotBaseRequest(true)
7978
{
8079
params.seqnum = 0;
8180
params.ticks = ticks;
81+
params.active = active;
8282
params.report = report;
8383
}
8484
virtual BotBaseMessage message() const override{
@@ -111,6 +111,7 @@ int register_message_converters_ESP32(){
111111
const auto* params = (const pabb_esp32_report30*)body.c_str();
112112
ss << "seqnum = " << (uint64_t)params->seqnum;
113113
ss << ", ticks = " << (int)params->ticks;
114+
ss << ", active = " << (int)params->active;
114115
return ss.str();
115116
}
116117
);
@@ -123,6 +124,8 @@ int init_Messages_ESP32 = register_message_converters_ESP32();
123124
void SerialPABotBase_WirelessProController::push_state(const Cancellable* cancellable, WallDuration duration){
124125
// https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering/blob/master/bluetooth_hid_notes.md
125126

127+
bool is_active = this->is_active();
128+
126129
ESP32Report0x30 report{
127130
.report_id = 0x30,
128131
.timer = 0, // Populate on controller.
@@ -172,14 +175,18 @@ void SerialPABotBase_WirelessProController::push_state(const Cancellable* cancel
172175
report.button5 |= (m_buttons[6].is_busy() ? 1 : 0) << 7; // ZL
173176

174177
// Left Joycon
175-
report.leftstick_x_lo = (m_left_joystick.x << 4) & 0xf0;
176-
report.leftstick_x_hi = (m_left_joystick.x & 0xf0) >> 4;
177-
report.leftstick_y = 255 - m_left_joystick.y;
178+
if (m_left_joystick.is_busy()){
179+
report.leftstick_x_lo = (m_left_joystick.x << 4) & 0xf0;
180+
report.leftstick_x_hi = (m_left_joystick.x & 0xf0) >> 4;
181+
report.leftstick_y = 255 - m_left_joystick.y;
182+
}
178183

179184
// Right Joycon
180-
report.rightstick_x_lo = (m_right_joystick.x << 4) & 0xf0;
181-
report.rightstick_x_hi = (m_right_joystick.x & 0xf0) >> 4;
182-
report.rightstick_y = 255 - m_right_joystick.y;
185+
if (m_right_joystick.is_busy()){
186+
report.rightstick_x_lo = (m_right_joystick.x << 4) & 0xf0;
187+
report.rightstick_x_hi = (m_right_joystick.x & 0xf0) >> 4;
188+
report.rightstick_y = 255 - m_right_joystick.y;
189+
}
183190

184191

185192
// Release the state lock since we are no longer touching state.
@@ -192,7 +199,7 @@ void SerialPABotBase_WirelessProController::push_state(const Cancellable* cancel
192199
Milliseconds current_ms = std::min(time_left, 255 * 15ms);
193200
uint8_t current_ticks = (uint8_t)milliseconds_to_ticks_15ms(current_ms.count());
194201
m_serial->issue_request(
195-
MessageControllerState(current_ticks, report),
202+
MessageControllerState(current_ticks, is_active, report),
196203
cancellable
197204
);
198205
time_left -= current_ms;
@@ -250,15 +257,15 @@ void SerialPABotBase_WirelessProController::status_thread(){
250257
last_ack.store(current_time(), std::memory_order_relaxed);
251258

252259
uint32_t status = response.data;
253-
bool status_paired = status & 1;
254-
bool status_connected = status & 2;
260+
bool status_connected = status & 1;
261+
bool status_paired = status & 2;
255262

256263
std::string str;
257-
str += "Paired: " + (status_paired
264+
str += "Connected: " + (status_connected
258265
? html_color_text("Yes", theme_friendly_darkblue())
259266
: html_color_text("No", COLOR_RED)
260267
);
261-
str += ", Connected: " + (status_connected
268+
str += ", Paired: " + (status_paired
262269
? html_color_text("Yes", theme_friendly_darkblue())
263270
: html_color_text("No", COLOR_RED)
264271
);

0 commit comments

Comments
 (0)