Skip to content

Commit fd743a8

Browse files
committed
Slight refactor of controller timings. Give ESP32 a non-zero variation.
1 parent 7a73134 commit fd743a8

18 files changed

+143
-126
lines changed

SerialPrograms/Source/Controllers/Controller.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ class AbstractController{
6060
// Zero means "tick precise".
6161
virtual Milliseconds timing_variation() const = 0;
6262

63+
// If the controller can atomically press/release multiple buttons
64+
// return true. This means that if the program presses A and B
65+
// simultaneously, the console will never see an intermediate state where
66+
// either A or B is pressed by itself before the other is pressed as well.
67+
virtual bool atomic_multibutton() const = 0;
68+
6369

6470
public:
6571
// Status

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#define PokemonAutomation_NintendoSwitch_SerialPABotBase_PokkenController_H
99

1010
#include "Controllers/ControllerCapability.h"
11+
#include "NintendoSwitch/NintendoSwitch_Settings.h"
1112
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
1213
#include "NintendoSwitch_SerialPABotBase_Controller.h"
1314

@@ -60,7 +61,10 @@ class SerialPABotBase_PokkenController final :
6061
return Milliseconds(8);
6162
}
6263
virtual Milliseconds timing_variation() const override{
63-
return Milliseconds::zero();
64+
return ConsoleSettings::instance().TIMING_OPTIONS.WIRED_MICROCONTROLLER;
65+
}
66+
virtual bool atomic_multibutton() const override{
67+
return true;
6468
}
6569

6670

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "Common/Cpp/Concurrency/ReverseLockGuard.h"
99
#include "CommonFramework/Options/Environment/ThemeSelectorOption.h"
1010
#include "Controllers/SerialPABotBase/SerialPABotBase_Routines_ESP32.h"
11+
#include "NintendoSwitch/NintendoSwitch_Settings.h"
1112
#include "NintendoSwitch_SerialPABotBase_WirelessController.h"
1213

1314
//#include <iostream>
@@ -36,6 +37,7 @@ SerialPABotBase_WirelessController::SerialPABotBase_WirelessController(
3637
connection
3738
)
3839
, m_controller_type(controller_type)
40+
, m_timing_variation(ConsoleSettings::instance().TIMING_OPTIONS.WIRELESS_ESP32)
3941
, m_stopping(false)
4042
, m_status_thread(&SerialPABotBase_WirelessController::status_thread, this)
4143
{}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class SerialPABotBase_WirelessController : public SerialPABotBase_Controller{
4040
return Milliseconds(15);
4141
}
4242
Milliseconds timing_variation() const{
43-
return Milliseconds(0);
43+
return m_timing_variation;
4444
}
4545

4646

@@ -116,6 +116,7 @@ class SerialPABotBase_WirelessController : public SerialPABotBase_Controller{
116116

117117
protected:
118118
const ControllerType m_controller_type;
119+
Milliseconds m_timing_variation;
119120
private:
120121
CancellableHolder<CancellableScope> m_scope;
121122
std::atomic<bool> m_stopping;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ class SerialPABotBase_WirelessJoycon final :
6161
virtual Milliseconds timing_variation() const override{
6262
return SerialPABotBase_WirelessController::timing_variation();
6363
}
64+
virtual bool atomic_multibutton() const override{
65+
return true;
66+
}
6467

6568

6669
public:

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ class SerialPABotBase_WirelessProController final :
6060
virtual Milliseconds timing_variation() const override{
6161
return SerialPABotBase_WirelessController::timing_variation();
6262
}
63+
virtual bool atomic_multibutton() const override{
64+
return true;
65+
}
6366

6467

6568
public:

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
#include <condition_variable>
1212
#include "Common/Cpp/Containers/CircularBuffer.h"
13+
#include "NintendoSwitch/NintendoSwitch_Settings.h"
1314
#include "NintendoSwitch/Controllers/NintendoSwitch_VirtualControllerState.h"
1415
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
1516
#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerWithScheduler.h"
@@ -55,7 +56,10 @@ class ProController_SysbotBase final :
5556
return Milliseconds(150);
5657
}
5758
virtual Milliseconds timing_variation() const override{
58-
return Milliseconds(150);
59+
return ConsoleSettings::instance().TIMING_OPTIONS.SYSBOTBASE;
60+
}
61+
virtual bool atomic_multibutton() const override{
62+
return false;
5963
}
6064

6165

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -385,28 +385,37 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
385385
#endif
386386

387387

388+
numberpad_enter_code(logger, context, "708538991006", false);
389+
390+
391+
388392
#if 0
389393
for (size_t i = 0; i < 100; i++){
390-
for (size_t c = 0; c < 2; c++){
391-
ssf_issue_scroll(context, DPAD_RIGHT, 32ms);
394+
for (size_t c = 0; c < 7; c++){
395+
ssf_issue_scroll(context, DPAD_RIGHT, 40ms);
392396
}
393-
for (size_t c = 0; c < 2; c++){
394-
ssf_issue_scroll(context, DPAD_LEFT, 32ms);
397+
for (size_t c = 0; c < 7; c++){
398+
ssf_issue_scroll(context, DPAD_LEFT, 40ms);
395399
}
396400
}
401+
#endif
397402

398403

399404

400-
for (size_t c = 0; c < 60; c++){
401-
ssf_issue_scroll(context, DPAD_DOWN, 20ms);
402-
}
403-
ssf_do_nothing(context, 1000ms);
404-
for (size_t c = 0; c < 60; c++){
405-
ssf_issue_scroll(context, DPAD_UP, 20ms);
405+
#if 0
406+
while (true){
407+
for (size_t c = 0; c < 60; c++){
408+
ssf_issue_scroll(context, DPAD_DOWN, 24ms);
409+
}
410+
ssf_do_nothing(context, 1000ms);
411+
for (size_t c = 0; c < 60; c++){
412+
ssf_issue_scroll(context, DPAD_UP, 24ms);
413+
}
414+
ssf_do_nothing(context, 1000ms);
406415
}
407416
#endif
408417

409-
pbf_move_left_joystick(context, 38, 38, 10000, 0);
418+
// pbf_move_left_joystick(context, 38, 38, 10000, 0);
410419

411420

412421
// ssf_issue_scroll(context, DPAD_LEFT, 0);

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_Settings.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,51 @@
1414
namespace PokemonAutomation{
1515
namespace NintendoSwitch{
1616

17+
using namespace std::chrono_literals;
18+
1719

1820
const Resolution DEFAULT_RESOLUTION(1920, 1080);
1921

2022

23+
24+
TimingOptions::TimingOptions()
25+
: GroupOption(
26+
"Timing Options",
27+
LockMode::UNLOCK_WHILE_RUNNING,
28+
EnableMode::ALWAYS_ENABLED,
29+
true
30+
)
31+
, WIRED_MICROCONTROLLER(
32+
"<b>Wired Microcontroller Timing Variation:</b><br>"
33+
"Assume that wired microcontrollers have a timing variation of no greater than this. "
34+
"This is used to adjust button delays to ensure they go through correctly.",
35+
LockMode::LOCK_WHILE_RUNNING,
36+
0ms, 200ms, "0 ms"
37+
)
38+
, WIRELESS_ESP32(
39+
"<b>Wireless ESP32 Timing Variation:</b><br>"
40+
"Assume that wireless ESP32 controllers have a timing variation of no greater than this. "
41+
"This is used to adjust button delays to ensure they go through correctly.",
42+
LockMode::LOCK_WHILE_RUNNING,
43+
0ms, 200ms, "10 ms"
44+
)
45+
, SYSBOTBASE(
46+
"<b>sys-botbase Timing Variation:</b><br>"
47+
"Assume that sys-botbase controllers have a timing variation of no greater than this. "
48+
"This is used to adjust button delays to ensure they go through correctly.",
49+
LockMode::LOCK_WHILE_RUNNING,
50+
0ms, 200ms, "150 ms"
51+
)
52+
{
53+
PA_ADD_OPTION(WIRED_MICROCONTROLLER);
54+
PA_ADD_OPTION(WIRELESS_ESP32);
55+
PA_ADD_OPTION(SYSBOTBASE);
56+
}
57+
58+
59+
60+
61+
2162
ConsoleSettings& ConsoleSettings::instance(){
2263
static ConsoleSettings settings;
2364
return settings;
@@ -63,6 +104,7 @@ ConsoleSettings::ConsoleSettings()
63104
PA_ADD_OPTION(START_GAME_INTERNET_CHECK_DELAY0);
64105
PA_ADD_OPTION(TOLERATE_SYSTEM_UPDATE_MENU_FAST);
65106
PA_ADD_OPTION(TOLERATE_SYSTEM_UPDATE_MENU_SLOW);
107+
PA_ADD_OPTION(TIMING_OPTIONS);
66108
if (PreloadSettings::instance().DEVELOPER_MODE){
67109
PA_ADD_OPTION(DIGIT_ENTRY);
68110
PA_ADD_OPTION(KEYBOARD_ENTRY);

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_Settings.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ namespace NintendoSwitch{
2323
extern const Resolution DEFAULT_RESOLUTION;
2424

2525

26+
class TimingOptions : public GroupOption{
27+
public:
28+
TimingOptions();
29+
30+
public:
31+
MillisecondsOption WIRED_MICROCONTROLLER;
32+
MillisecondsOption WIRELESS_ESP32;
33+
MillisecondsOption SYSBOTBASE;
34+
};
35+
2636

2737
class ConsoleSettings : public BatchOption{
2838
ConsoleSettings();
@@ -38,6 +48,8 @@ class ConsoleSettings : public BatchOption{
3848
BooleanCheckBoxOption TOLERATE_SYSTEM_UPDATE_MENU_FAST;
3949
BooleanCheckBoxOption TOLERATE_SYSTEM_UPDATE_MENU_SLOW;
4050

51+
TimingOptions TIMING_OPTIONS;
52+
4153
DigitEntryTimingsOption DIGIT_ENTRY;
4254
KeyboardEntryTimingsOption KEYBOARD_ENTRY;
4355

0 commit comments

Comments
 (0)