Skip to content

Commit 146649f

Browse files
committed
Add abstraction layer between SerialPABotBase and the programs.
1 parent 4e7531b commit 146649f

33 files changed

+850
-105
lines changed

ClientSource/Connection/BotBase.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class BotBaseController{
7373

7474

7575

76-
class ControllerContext : public CancellableScope{
76+
class ControllerContext0 : public CancellableScope{
7777
public:
7878
virtual void wait_for_all_requests() const = 0;
7979
virtual void cancel_now() = 0;
@@ -82,7 +82,7 @@ class ControllerContext : public CancellableScope{
8282

8383

8484
// A wrapper for BotBase that allows for asynchronous cancelling.
85-
class BotBaseControllerContext final : public ControllerContext{
85+
class BotBaseControllerContext final : public ControllerContext0{
8686
public:
8787
using ControllerType = BotBaseController;
8888

ClientSource/Connection/PABotBaseConnection.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
#define PokemonAutomation_PABotBaseConnection_H
1616

1717
#include <memory>
18-
#include <string>
1918
#include <deque>
20-
#include "Common/Compiler.h"
2119
#include "Common/Microcontroller/MessageProtocol.h"
2220
#include "BotBase.h"
2321
#include "MessageSniffer.h"

SerialPrograms/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,8 @@ file(GLOB MAIN_SOURCES
802802
Source/NintendoSwitch/Commands/NintendoSwitch_Messages_Superscalar.h
803803
Source/NintendoSwitch/Controllers/NintendoSwitch_Controller.cpp
804804
Source/NintendoSwitch/Controllers/NintendoSwitch_Controller.h
805+
Source/NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.cpp
806+
Source/NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.h
805807
Source/NintendoSwitch/DevPrograms/BoxDraw.cpp
806808
Source/NintendoSwitch/DevPrograms/BoxDraw.h
807809
Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp

SerialPrograms/SerialPrograms.pro

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,7 @@ SOURCES += \
397397
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Routines.cpp \
398398
Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.cpp \
399399
Source/NintendoSwitch/Controllers/NintendoSwitch_Controller.cpp \
400+
Source/NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.cpp \
400401
Source/NintendoSwitch/DevPrograms/BoxDraw.cpp \
401402
Source/NintendoSwitch/DevPrograms/TestProgramComputer.cpp \
402403
Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp \
@@ -1528,6 +1529,7 @@ HEADERS += \
15281529
Source/NintendoSwitch/Commands/NintendoSwitch_Messages_PushButtons.h \
15291530
Source/NintendoSwitch/Commands/NintendoSwitch_Messages_Superscalar.h \
15301531
Source/NintendoSwitch/Controllers/NintendoSwitch_Controller.h \
1532+
Source/NintendoSwitch/Controllers/NintendoSwitch_SerialPABotBase.h \
15311533
Source/NintendoSwitch/DevPrograms/BoxDraw.h \
15321534
Source/NintendoSwitch/DevPrograms/TestProgramComputer.h \
15331535
Source/NintendoSwitch/DevPrograms/TestProgramSwitch.h \

SerialPrograms/Source/CommonTools/Async/InterruptableCommands.tpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,10 @@ bool AsyncCommandSession<ControllerType>::cancel(std::exception_ptr exception) n
134134
if (m_current != nullptr){
135135
m_current->context.cancel(std::move(exception));
136136
}else{
137-
try{
138-
m_controller.stop_all_commands();
139-
}catch (...){}
137+
// REMOVE: Check that this can actually be deleted.
138+
// try{
139+
// m_controller.stop_all_commands();
140+
// }catch (...){}
140141
}
141142
m_cv.notify_all();
142143
return false;

SerialPrograms/Source/Controllers/SerialPABotBase/SerialPABotBase_Handle.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616
#include "Common/NintendoSwitch/NintendoSwitch_ControllerDefs.h"
1717
#include "ClientSource/Libraries/MessageConverter.h"
1818
#include "ClientSource/Connection/SerialConnection.h"
19+
//#include "ClientSource/Connection/BotBase.h"
1920
#include "ClientSource/Connection/PABotBase.h"
2021
#include "CommonFramework/Globals.h"
2122
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
2223
#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Device.h"
24+
#include "NintendoSwitch/Commands/NintendoSwitch_Messages_Device.h"
2325
#include "SerialPABotBase_Globals.h"
2426
#include "SerialPABotBase_Handle.h"
2527
#include "SerialPABotBase_Descriptor.h"
@@ -380,7 +382,9 @@ void BotBaseHandle::thread_body(){
380382
}
381383
});
382384

385+
// REMOVE
383386
BotBaseControllerContext context(*m_botbase);
387+
384388
while (true){
385389
if (m_state.load(std::memory_order_acquire) != State::READY){
386390
break;
@@ -390,7 +394,13 @@ void BotBaseHandle::thread_body(){
390394
std::string error;
391395
try{
392396
// cout << "system_clock()" << endl;
393-
uint32_t wallclock = NintendoSwitch::system_clock(context);
397+
pabb_MsgAckRequestI32 response;
398+
context.issue_request_and_wait(
399+
NintendoSwitch::DeviceRequest_system_clock()
400+
).convert<PABB_MSG_ACK_REQUEST_I32>(context.controller().logger(), response);
401+
uint32_t wallclock = response.data;
402+
403+
// uint32_t wallclock = NintendoSwitch::system_clock(context);
394404
// cout << "system_clock() - done" << endl;
395405
str = ticks_to_time(TICKS_PER_SECOND, wallclock);
396406
}catch (InvalidConnectionStateException&){

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Device.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ namespace PokemonAutomation{
1111
namespace NintendoSwitch{
1212

1313

14-
uint32_t system_clock(SwitchControllerContext& context){
14+
uint32_t system_clock(BotBaseControllerContext& context){
1515
pabb_MsgAckRequestI32 response;
1616
context.issue_request_and_wait(
1717
DeviceRequest_system_clock()
1818
).convert<PABB_MSG_ACK_REQUEST_I32>(context.controller().logger(), response);
1919
return response.data;
2020
}
21-
void set_leds(SwitchControllerContext& context, bool on){
22-
context.issue_request(DeviceRequest_set_leds(on));
21+
void set_leds(BotBaseControllerContext& context, bool on){
22+
context.issue_request_and_wait(DeviceRequest_set_leds(on));
2323
}
2424

2525

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_Device.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
#ifndef PokemonAutomation_NintendoSwitch_Commands_Device_H
88
#define PokemonAutomation_NintendoSwitch_Commands_Device_H
99

10-
#include "NintendoSwitch/Controllers/NintendoSwitch_Controller.h"
10+
#include "ClientSource/Connection/BotBase.h"
1111

1212
namespace PokemonAutomation{
1313
namespace NintendoSwitch{
1414

1515

16-
uint32_t system_clock (SwitchControllerContext& context);
17-
void set_leds (SwitchControllerContext& context, bool on);
16+
uint32_t system_clock (BotBaseControllerContext& context);
17+
void set_leds (BotBaseControllerContext& context, bool on);
1818

1919

2020

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ void pbf_mash_button(SwitchControllerContext& context, Button button, uint16_t t
9595
#endif
9696
}
9797

98+
#if 0
9899
void start_program_flash(SwitchControllerContext& context, uint16_t ticks){
99100
for (uint16_t c = 0; c < ticks; c += 50){
100101
set_leds(context, true);
@@ -103,6 +104,7 @@ void start_program_flash(SwitchControllerContext& context, uint16_t ticks){
103104
pbf_wait(context, 25);
104105
}
105106
}
107+
#endif
106108
void grip_menu_connect_go_home(SwitchControllerContext& context){
107109
pbf_press_button(context, BUTTON_L | BUTTON_R, 10, 40);
108110
pbf_press_button(context, BUTTON_A, 10, 140);
@@ -131,6 +133,8 @@ void pbf_controller_state(
131133
uint8_t right_x, uint8_t right_y,
132134
uint16_t ticks
133135
){
136+
context->send_controller_state(context, button, position, left_x, left_y, right_x, right_y, ticks);
137+
#if 0
134138
// divide the controller state into smaller chunks of 255 ticks
135139
while (ticks > 0){
136140
uint16_t curr_ticks = std::min(ticks, (uint16_t)255);
@@ -139,6 +143,7 @@ void pbf_controller_state(
139143
);
140144
ticks -= curr_ticks;
141145
} // end while loop, and function
146+
#endif
142147
}
143148

144149
static std::string button_to_string(Button button){

SerialPrograms/Source/NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void pbf_move_right_joystick (SwitchControllerContext& context, uint8_t x, ui
5757
// The buttons also include clicking joysticks: BUTTON_LCLICK, BUTTON_RCLICK.
5858
void pbf_mash_button (SwitchControllerContext& context, Button button, uint16_t ticks);
5959

60-
void start_program_flash (SwitchControllerContext& context, uint16_t ticks);
60+
//void start_program_flash (SwitchControllerContext& context, uint16_t ticks);
6161
void grip_menu_connect_go_home (SwitchControllerContext& context);
6262

6363

0 commit comments

Comments
 (0)