Skip to content

Commit 808e732

Browse files
committed
Fix the FCE.
1 parent 44b41dc commit 808e732

19 files changed

+226
-110
lines changed

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,11 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
325325
ProControllerContext context(scope, console.pro_controller());
326326
VideoOverlaySet overlays(overlay);
327327

328+
329+
ssf_press_button(context, BUTTON_L, 0ms, 48ms, 24ms);
330+
ssf_issue_scroll(context, DPAD_LEFT, 48ms, 48ms, 24ms);
331+
332+
328333
#if 0
329334
DateReader reader;
330335
reader.make_overlays(overlays);
@@ -357,7 +362,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
357362
#endif
358363

359364

360-
#if 1
365+
#if 0
361366
DateReader reader(console);
362367
reader.make_overlays(overlays);
363368
DateTime date = reader.read_date(logger, feed.snapshot()).second;

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_Settings.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ ConsoleSettings::ConsoleSettings()
9696
LockMode::LOCK_WHILE_RUNNING,
9797
false
9898
)
99+
, SWITCH1_DIGIT_ENTRY(false)
100+
, SWITCH1_KEYBOARD_ENTRY(false)
101+
, SWITCH2_DIGIT_ENTRY(true)
102+
, SWITCH2_KEYBOARD_ENTRY(true)
99103
, KEYBOARD_SECTION("<font size=4><b>Keyboard to Controller Mappings:</b></font>")
100104
{
101105
PA_ADD_OPTION(CONTROLLER_SETTINGS);
@@ -106,8 +110,10 @@ ConsoleSettings::ConsoleSettings()
106110
PA_ADD_OPTION(TOLERATE_SYSTEM_UPDATE_MENU_SLOW);
107111
PA_ADD_OPTION(TIMING_OPTIONS);
108112
if (PreloadSettings::instance().DEVELOPER_MODE){
109-
PA_ADD_OPTION(DIGIT_ENTRY);
110-
PA_ADD_OPTION(KEYBOARD_ENTRY);
113+
PA_ADD_OPTION(SWITCH1_DIGIT_ENTRY);
114+
PA_ADD_OPTION(SWITCH1_KEYBOARD_ENTRY);
115+
PA_ADD_OPTION(SWITCH2_DIGIT_ENTRY);
116+
PA_ADD_OPTION(SWITCH2_KEYBOARD_ENTRY);
111117
}
112118
PA_ADD_STATIC(KEYBOARD_SECTION);
113119
PA_ADD_OPTION(KEYBOARD_MAPPINGS);

SerialPrograms/Source/NintendoSwitch/NintendoSwitch_Settings.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@ class ConsoleSettings : public BatchOption{
5050

5151
TimingOptions TIMING_OPTIONS;
5252

53-
DigitEntryTimingsOption DIGIT_ENTRY;
54-
KeyboardEntryTimingsOption KEYBOARD_ENTRY;
53+
DigitEntryTimingsOption SWITCH1_DIGIT_ENTRY;
54+
KeyboardEntryTimingsOption SWITCH1_KEYBOARD_ENTRY;
55+
DigitEntryTimingsOption SWITCH2_DIGIT_ENTRY;
56+
KeyboardEntryTimingsOption SWITCH2_KEYBOARD_ENTRY;
5557

5658
SectionDividerOption KEYBOARD_SECTION;
5759
KeyboardMappingOption KEYBOARD_MAPPINGS;

SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_CodeEntrySettingsOption.cpp

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,15 @@ CodeEntrySkipPlusOption::CodeEntrySkipPlusOption()
4747

4848

4949

50-
DigitEntryTimingsOption::DigitEntryTimingsOption()
50+
DigitEntryTimingsOption::DigitEntryTimingsOption(bool switch2)
5151
: GroupOption(
52-
"Digit Entry Timings",
52+
switch2
53+
? "Switch 2 Digit Entry Timings"
54+
: "Switch 1 Digit Entry Timings",
5355
LockMode::UNLOCK_WHILE_RUNNING,
5456
GroupOption::EnableMode::ALWAYS_ENABLED, true
5557
)
56-
, DIGIT_REORDERING(
58+
, REORDERING(
5759
"<b>Digit Reordering:</b><br>Allow digits to be entered out of order.",
5860
LockMode::UNLOCK_WHILE_RUNNING,
5961
true
@@ -62,35 +64,69 @@ DigitEntryTimingsOption::DigitEntryTimingsOption()
6264
"<b>Time Unit:</b><br>Timesteps should increment in multiples of this unit.<br>"
6365
"<font color=\"red\">Controller timing variation will be added to this number.</font>",
6466
LockMode::UNLOCK_WHILE_RUNNING,
67+
switch2
68+
? "48ms"
69+
: PreloadSettings::instance().DEVELOPER_MODE ? "24 ms" : "40ms"
70+
)
71+
, HOLD(
72+
"<b>Hold:</b><br>Duration to hold each button press down.<br>"
73+
"<font color=\"red\">Controller timing variation will be added to this number.</font>",
74+
LockMode::UNLOCK_WHILE_RUNNING,
75+
PreloadSettings::instance().DEVELOPER_MODE ? "48 ms" : "80ms"
76+
)
77+
, COOLDOWN(
78+
"<b>Hold:</b><br>Do not reuse a button until this long after it is reused.<br>"
79+
"<font color=\"red\">Controller timing variation will be added to this number.</font>",
80+
LockMode::UNLOCK_WHILE_RUNNING,
6581
PreloadSettings::instance().DEVELOPER_MODE ? "24 ms" : "40ms"
6682
)
6783
{
68-
PA_ADD_OPTION(DIGIT_REORDERING);
84+
PA_ADD_OPTION(REORDERING);
6985
PA_ADD_OPTION(TIME_UNIT);
86+
PA_ADD_OPTION(HOLD);
87+
PA_ADD_OPTION(COOLDOWN);
7088
}
7189

7290

7391

74-
KeyboardEntryTimingsOption::KeyboardEntryTimingsOption()
92+
KeyboardEntryTimingsOption::KeyboardEntryTimingsOption(bool switch2)
7593
: GroupOption(
76-
"Keyboard Entry Timings",
94+
switch2
95+
? "Switch 2 Keyboard Entry Timings"
96+
: "Switch 1 Keyboard Entry Timings",
7797
LockMode::UNLOCK_WHILE_RUNNING,
7898
GroupOption::EnableMode::ALWAYS_ENABLED, true
7999
)
80-
, DIGIT_REORDERING(
81-
"<b>Digit Reordering:</b><br>Allow digits to be entered out of order.",
100+
, REORDERING(
101+
"<b>Character Reordering:</b><br>Allow characters to be entered out of order.",
82102
LockMode::UNLOCK_WHILE_RUNNING,
83103
PreloadSettings::instance().DEVELOPER_MODE
84104
)
85105
, TIME_UNIT(
86106
"<b>Time Unit:</b><br>Timesteps should increment in multiples of this unit.<br>"
87107
"<font color=\"red\">Controller timing variation will be added to this number.</font>",
88108
LockMode::UNLOCK_WHILE_RUNNING,
109+
switch2
110+
? "48ms"
111+
: PreloadSettings::instance().DEVELOPER_MODE ? "24 ms" : "40ms"
112+
)
113+
, HOLD(
114+
"<b>Hold:</b><br>Duration to hold each button press down.<br>"
115+
"<font color=\"red\">Controller timing variation will be added to this number.</font>",
116+
LockMode::UNLOCK_WHILE_RUNNING,
117+
PreloadSettings::instance().DEVELOPER_MODE ? "48 ms" : "80ms"
118+
)
119+
, COOLDOWN(
120+
"<b>Hold:</b><br>Do not reuse a button until this long after it is reused.<br>"
121+
"<font color=\"red\">Controller timing variation will be added to this number.</font>",
122+
LockMode::UNLOCK_WHILE_RUNNING,
89123
PreloadSettings::instance().DEVELOPER_MODE ? "24 ms" : "40ms"
90124
)
91125
{
92-
PA_ADD_OPTION(DIGIT_REORDERING);
126+
PA_ADD_OPTION(REORDERING);
93127
PA_ADD_OPTION(TIME_UNIT);
128+
PA_ADD_OPTION(HOLD);
129+
PA_ADD_OPTION(COOLDOWN);
94130
}
95131

96132

SerialPrograms/Source/NintendoSwitch/Options/NintendoSwitch_CodeEntrySettingsOption.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,24 @@ class CodeEntrySkipPlusOption : public BooleanCheckBoxOption{
3838

3939
class DigitEntryTimingsOption : public GroupOption{
4040
public:
41-
DigitEntryTimingsOption();
41+
DigitEntryTimingsOption(bool switch2);
4242

4343
public:
44-
BooleanCheckBoxOption DIGIT_REORDERING;
44+
BooleanCheckBoxOption REORDERING;
4545
MillisecondsOption TIME_UNIT;
46+
MillisecondsOption HOLD;
47+
MillisecondsOption COOLDOWN;
4648
};
4749

4850
class KeyboardEntryTimingsOption : public GroupOption{
4951
public:
50-
KeyboardEntryTimingsOption();
52+
KeyboardEntryTimingsOption(bool switch2);
5153

5254
public:
53-
BooleanCheckBoxOption DIGIT_REORDERING;
55+
BooleanCheckBoxOption REORDERING;
5456
MillisecondsOption TIME_UNIT;
57+
MillisecondsOption HOLD;
58+
MillisecondsOption COOLDOWN;
5559
};
5660

5761

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_FriendCodeAdder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void FriendCodeAdder::program(SingleSwitchProgramEnvironment& env, ProController
8383
first = false;
8484

8585
ssf_press_button_ptv(context, BUTTON_A, OPEN_CODE_PAD_DELAY0);
86-
numberpad_enter_code(env.logger(), context, code, true);
86+
numberpad_enter_code(env.console, context, code, true);
8787

8888
pbf_wait(context, SEARCH_TIME0);
8989
ssf_press_button(context, BUTTON_A, TOGGLE_BEST_STATUS_DELAY0);

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_KeyboardCodeEntry.cpp

Lines changed: 61 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ std::vector<std::vector<KeyboardEntryAction>> keyboard_get_all_paths(
285285

286286

287287
// Given a path, optimize it and fully populate the delays.
288-
Milliseconds keyboard_populate_delays(
288+
void keyboard_populate_delays(
289289
std::vector<KeyboardEntryActionWithDelay>& path_with_delays,
290290
const std::vector<KeyboardEntryAction>& path,
291291
const KeyboardEntryDelays& delays,
@@ -313,32 +313,29 @@ Milliseconds keyboard_populate_delays(
313313
}
314314

315315
// Optimize
316-
if (optimize){
317-
for (size_t c = 1; c < path_with_delays.size(); c++){
318-
// Zero the delay for any L press.
319-
KeyboardEntryActionWithDelay& current = path_with_delays[c];
320-
if (current.action == KeyboardEntryAction::SCROLL_LEFT){
321-
current.delay = 0ms;
322-
continue;
323-
}
324316

325-
// Zero the delay for any scroll immediately preceding an A press.
326-
KeyboardEntryActionWithDelay& previous = path_with_delays[c - 1];
327-
if (current.action == KeyboardEntryAction::ENTER_CHAR &&
328-
previous.action != KeyboardEntryAction::ENTER_CHAR &&
329-
previous.action != KeyboardEntryAction::SCROLL_LEFT
330-
){
331-
previous.delay = 0ms;
332-
}
333-
}
317+
if (!optimize || path_with_delays.empty()){
318+
return;
334319
}
335320

336-
Milliseconds total = 0ms;
337-
for (KeyboardEntryActionWithDelay& action : path_with_delays){
338-
total += action.delay;
339-
}
321+
// These only work on the Switch 1.
322+
for (size_t c = 1; c < path_with_delays.size(); c++){
323+
// Zero the delay for any L press.
324+
KeyboardEntryActionWithDelay& current = path_with_delays[c];
325+
if (current.action == KeyboardEntryAction::SCROLL_LEFT){
326+
current.delay = 0ms;
327+
continue;
328+
}
340329

341-
return total;
330+
// Zero the delay for any scroll immediately preceding an A press.
331+
KeyboardEntryActionWithDelay& previous = path_with_delays[c - 1];
332+
if (current.action == KeyboardEntryAction::ENTER_CHAR &&
333+
previous.action != KeyboardEntryAction::ENTER_CHAR &&
334+
previous.action != KeyboardEntryAction::SCROLL_LEFT
335+
){
336+
previous.delay = 0ms;
337+
}
338+
}
342339
}
343340

344341

@@ -353,7 +350,11 @@ std::vector<KeyboardEntryActionWithDelay> keyboard_get_best_path(
353350
Milliseconds best_time = Milliseconds::max();
354351
for (const std::vector<KeyboardEntryAction>& path : paths){
355352
std::vector<KeyboardEntryActionWithDelay> current_path;
356-
Milliseconds current_time = keyboard_populate_delays(current_path, path, delays, optimize);
353+
keyboard_populate_delays(current_path, path, delays, optimize);
354+
Milliseconds current_time = 0ms;
355+
for (KeyboardEntryActionWithDelay& action : current_path){
356+
current_time += action.delay;
357+
}
357358
if (best_time > current_time){
358359
best_time = current_time;
359360
best_path = std::move(current_path);
@@ -391,7 +392,7 @@ void keyboard_execute_path(
391392

392393

393394
void keyboard_enter_code(
394-
Logger& logger, ProControllerContext& context,
395+
ConsoleHandle& console, ProControllerContext& context,
395396
KeyboardLayout keyboard_layout, const std::string& code,
396397
bool include_plus
397398
){
@@ -413,23 +414,52 @@ void keyboard_enter_code(
413414
auto iter = POSITION_MAP.find(ch);
414415
if (iter == POSITION_MAP.end()){
415416
throw_and_log<OperationFailedException>(
416-
logger, ErrorReport::NO_ERROR_REPORT,
417+
console, ErrorReport::NO_ERROR_REPORT,
417418
"Invalid code character."
418419
);
419420
}
420421
positions.emplace_back(iter->second);
421422
}
422423

423424

425+
ConsoleType console_type = console.state().console_type();
426+
bool switch2;
427+
if (console_type == ConsoleType::Switch1){
428+
switch2 = false;
429+
}else if (is_switch2(console_type)){
430+
switch2 = true;
431+
}else{
432+
throw UserSetupError(
433+
console,
434+
"Please select a valid Switch console type."
435+
);
436+
}
437+
438+
424439
// Compute the delays.
425440

426-
Milliseconds unit = ConsoleSettings::instance().KEYBOARD_ENTRY.TIME_UNIT;
441+
Milliseconds unit;
442+
Milliseconds hold;
443+
Milliseconds cool;
444+
bool reordering;
445+
if (switch2){
446+
unit = ConsoleSettings::instance().SWITCH2_KEYBOARD_ENTRY.TIME_UNIT;
447+
hold = ConsoleSettings::instance().SWITCH2_KEYBOARD_ENTRY.HOLD;
448+
cool = ConsoleSettings::instance().SWITCH2_KEYBOARD_ENTRY.COOLDOWN;
449+
reordering = ConsoleSettings::instance().SWITCH2_KEYBOARD_ENTRY.REORDERING;
450+
}else{
451+
unit = ConsoleSettings::instance().SWITCH1_KEYBOARD_ENTRY.TIME_UNIT;
452+
hold = ConsoleSettings::instance().SWITCH1_KEYBOARD_ENTRY.HOLD;
453+
cool = ConsoleSettings::instance().SWITCH1_KEYBOARD_ENTRY.COOLDOWN;
454+
reordering = ConsoleSettings::instance().SWITCH1_KEYBOARD_ENTRY.REORDERING;
455+
}
456+
427457
Milliseconds tv = context->timing_variation();
428458
unit += tv;
429459

430460
KeyboardEntryDelays delays{
431-
.hold = 2*unit,
432-
.cool = unit,
461+
.hold = hold,
462+
.cool = cool,
433463
.press_delay = unit,
434464
.move_delay = unit,
435465
.wrap_delay = 2*unit,
@@ -439,14 +469,14 @@ void keyboard_enter_code(
439469
std::vector<std::vector<KeyboardEntryAction>> all_paths = keyboard_get_all_paths(
440470
{0, 0},
441471
positions.data(), positions.size(),
442-
ConsoleSettings::instance().KEYBOARD_ENTRY.DIGIT_REORDERING
472+
reordering
443473
);
444474

445475
// Pick the best path.
446476
std::vector<KeyboardEntryActionWithDelay> best_path = keyboard_get_best_path(
447477
all_paths,
448478
delays,
449-
context->atomic_multibutton()
479+
!switch2 && context->atomic_multibutton()
450480
);
451481

452482
keyboard_execute_path(context, delays, best_path);

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_KeyboardCodeEntry.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include <string>
1111
#include "NintendoSwitch/Options/NintendoSwitch_CodeEntrySettingsOption.h"
1212
#include "NintendoSwitch/Controllers/NintendoSwitch_ProController.h"
13+
#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h"
1314

1415
namespace PokemonAutomation{
1516
class Logger;
@@ -18,7 +19,7 @@ namespace NintendoSwitch{
1819

1920

2021
void keyboard_enter_code(
21-
Logger& logger, ProControllerContext& context,
22+
ConsoleHandle& console, ProControllerContext& context,
2223
KeyboardLayout keyboard_layout, const std::string& code,
2324
bool include_plus
2425
);

0 commit comments

Comments
 (0)