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
7473class SerialPABotBase_WirelessProController ::MessageControllerState : public BotBaseRequest{
7574public:
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();
123124void 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