Skip to content

Commit 8c68c10

Browse files
committed
Fix another issue with async-cancel in SBB. Fix flag pin bot for SBB.
1 parent cc9d878 commit 8c68c10

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_ProController.cpp

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,16 @@ ProController_SysbotBase::~ProController_SysbotBase(){
8282

8383

8484
void ProController_SysbotBase::wait_for_all(const Cancellable* cancellable){
85-
// cout << "ProController_SysbotBase::wait_for_all()" << endl;
85+
// cout << "ProController_SysbotBase::wait_for_all - Enter()" << endl;
8686
issue_barrier(cancellable);
8787
std::unique_lock<std::mutex> lg(m_lock);
8888
m_cv.wait(lg, [this]{
89-
return m_command_queue.empty() || m_replace_on_next.load(std::memory_order_relaxed);
89+
return m_command_queue.empty() || m_replace_on_next;
9090
});
91+
if (cancellable){
92+
cancellable->throw_if_cancelled();
93+
}
94+
// cout << "ProController_SysbotBase::wait_for_all - Exit()" << endl;
9195
}
9296
void ProController_SysbotBase::cancel_all_commands(){
9397
// cout << "ProController_SysbotBase::cancel_all_commands()" << endl;
@@ -102,11 +106,11 @@ void ProController_SysbotBase::cancel_all_commands(){
102106
this->clear_on_next();
103107
}
104108
void ProController_SysbotBase::replace_on_next_command(){
105-
// cout << "ProController_SysbotBase::replace_on_next_command()" << endl;
109+
// cout << "ProController_SysbotBase::replace_on_next_command - Enter()" << endl;
106110
{
107111
std::lock_guard<std::mutex> lg(m_lock);
108112
m_cv.notify_all();
109-
m_replace_on_next.store(true, std::memory_order_relaxed);
113+
m_replace_on_next = true;
110114
}
111115
this->clear_on_next();
112116
}
@@ -120,22 +124,38 @@ void ProController_SysbotBase::issue_controller_state(
120124
uint8_t right_x, uint8_t right_y,
121125
Milliseconds duration
122126
){
127+
#if 0
128+
// cout << "issue_controller_state(): Entering" << endl;
129+
m_logger.log(
130+
"issue_controller_state(): (" + button_to_string(button) +
131+
"), dpad(" + dpad_to_string(position) +
132+
"), LJ(" + std::to_string(left_x) + "," + std::to_string(left_y) +
133+
"), RJ(" + std::to_string(right_x) + "," + std::to_string(right_y) +
134+
")",
135+
COLOR_DARKGREEN
136+
);
137+
#endif
138+
123139
if (cancellable){
124140
cancellable->throw_if_cancelled();
125141
}
126142

127143
std::unique_lock<std::mutex> lg(m_lock);
128144

129-
if (m_replace_on_next.load(std::memory_order_acquire)){
145+
m_cv.wait(lg, [this]{
146+
return m_command_queue.size() < QUEUE_SIZE || m_replace_on_next;
147+
});
148+
149+
if (cancellable){
150+
cancellable->throw_if_cancelled();
151+
}
152+
153+
if (m_replace_on_next){
130154
m_command_queue.clear();
131155
m_is_active = false;
132-
m_replace_on_next.store(false, std::memory_order_relaxed);
156+
m_replace_on_next = false;
133157
}
134158

135-
m_cv.wait(lg, [this]{
136-
return m_command_queue.size() < QUEUE_SIZE;
137-
});
138-
139159
if (m_command_queue.empty()){
140160
m_cv.notify_all();
141161
}

SerialPrograms/Source/NintendoSwitch/Controllers/SysbotBase/SysbotBase_ProController.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class ProController_SysbotBase : public ProControllerWithScheduler{
8686
std::string m_error_string;
8787

8888
std::atomic<bool> m_stopping;
89-
std::atomic<bool> m_replace_on_next;
89+
bool m_replace_on_next;
9090

9191
struct Command{
9292
SwitchControllerState state;

SerialPrograms/Source/PokemonLA/Programs/PokemonLA_FlagNavigationAir.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ FlagNavigationAir::FlagNavigationAir(
182182
m_stream.log("Dashing Turn...");
183183
m_active_command->dispatch([this](ProControllerContext& context){
184184
// Move forward to straighten out direction.
185+
// cout << "Straight ahead = " << m_looking_straight_ahead.load(std::memory_order_acquire) << endl;
185186
if (!m_looking_straight_ahead.load(std::memory_order_acquire)){
187+
// pbf_wait(context, 1000ms);
186188
pbf_move_left_joystick(context, 128, 0, 160, 0);
187189
context.wait_for_all_requests();
188190
m_looking_straight_ahead_timestamp.store(current_time());

SerialPrograms/Source/PokemonLA/Programs/ShinyHunting/PokemonLA_ShinyHunt-FlagPin.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ ShinyHuntFlagPin_Descriptor::ShinyHuntFlagPin_Descriptor()
3333
"Repeatedly travel to a flag pin to shiny hunt " + STRING_POKEMON + " around it.",
3434
FeedbackType::VIDEO_AUDIO,
3535
AllowCommandsWhenRunning::DISABLE_COMMANDS,
36-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
36+
{ControllerFeature::NintendoSwitch_ProController},
37+
FasterIfTickPrecise::NOT_FASTER
3738
)
3839
{}
3940
class ShinyHuntFlagPin_Descriptor::Stats : public StatsTracker, public ShinyStatIncrementer{

SerialPrograms/Source/PokemonLA/Programs/TestPrograms/PokemonLA_FlagNavigationTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ FlagNavigationTest_Descriptor::FlagNavigationTest_Descriptor()
2323
"Navigate to the flag pin.",
2424
FeedbackType::REQUIRED,
2525
AllowCommandsWhenRunning::DISABLE_COMMANDS,
26-
{SerialPABotBase::OLD_NINTENDO_SWITCH_DEFAULT_REQUIREMENTS}
26+
{ControllerFeature::NintendoSwitch_ProController},
27+
FasterIfTickPrecise::NOT_FASTER
2728
)
2829
{}
2930

0 commit comments

Comments
 (0)