Skip to content

Commit 40f93b2

Browse files
committed
Migrate Switch options to TimeDurationOption.
1 parent 482661d commit 40f93b2

File tree

9 files changed

+87
-89
lines changed

9 files changed

+87
-89
lines changed

SerialPrograms/Source/CommonFramework/Globals.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ namespace PokemonAutomation{
2525
const bool IS_BETA_VERSION = true;
2626
const int PROGRAM_VERSION_MAJOR = 0;
2727
const int PROGRAM_VERSION_MINOR = 51;
28-
const int PROGRAM_VERSION_PATCH = 3;
28+
const int PROGRAM_VERSION_PATCH = 5;
2929

3030
const std::string PROGRAM_VERSION_BASE =
3131
"v" + std::to_string(PROGRAM_VERSION_MAJOR) +

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_FastCodeEntry.cpp

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -51,28 +51,24 @@ FastCodeEntrySettingsOption::FastCodeEntrySettingsOption(LockMode lock_while_pro
5151
LockMode::UNLOCK_WHILE_RUNNING,
5252
PreloadSettings::instance().DEVELOPER_MODE
5353
)
54-
, SCROLL_DELAY(
54+
, SCROLL_DELAY0(
5555
"<b>Scroll Delay:</b><br>Delay to scroll between adjacent keys.",
5656
LockMode::UNLOCK_WHILE_RUNNING,
57-
TICKS_PER_SECOND,
58-
3, 15,
59-
PreloadSettings::instance().DEVELOPER_MODE ? "5" : "6"
57+
PreloadSettings::instance().DEVELOPER_MODE ? "40 ms" : "48 ms"
6058
)
61-
, WRAP_DELAY(
59+
, WRAP_DELAY0(
6260
"<b>Wrap Delay:</b><br>Delay to wrap between left/right edges.",
6361
LockMode::UNLOCK_WHILE_RUNNING,
64-
TICKS_PER_SECOND,
65-
3, 15,
66-
"6"
62+
"48 ms"
6763
)
6864
{
6965
PA_ADD_OPTION(KEYBOARD_LAYOUT);
7066
PA_ADD_OPTION(SKIP_PLUS);
7167
if (PreloadSettings::instance().DEVELOPER_MODE){
7268
PA_ADD_OPTION(m_advanced_options);
7369
PA_ADD_OPTION(DIGIT_REORDERING);
74-
PA_ADD_OPTION(SCROLL_DELAY);
75-
PA_ADD_OPTION(WRAP_DELAY);
70+
PA_ADD_OPTION(SCROLL_DELAY0);
71+
PA_ADD_OPTION(WRAP_DELAY0);
7672
}
7773
}
7874

@@ -168,7 +164,8 @@ const std::map<char, CodeboardPosition>& CODEBOARD_POSITIONS_AZERTY(){
168164

169165
DigitPath get_codeboard_digit_path(
170166
CodeboardPosition source, CodeboardPosition destination,
171-
uint8_t scroll_delay, uint8_t wrap_delay
167+
Milliseconds scroll_delay,
168+
Milliseconds wrap_delay
172169
){
173170
// cout << (size_t)scroll_delay << ", " << (size_t)wrap_delay << endl;
174171
DigitPath path;
@@ -215,7 +212,7 @@ DigitPath get_codeboard_digit_path(
215212
}
216213
}
217214

218-
uint8_t delay = scroll_delay;
215+
Milliseconds delay = scroll_delay;
219216
if (col == (uint8_t)-1){
220217
col = 11;
221218
delay = wrap_delay;
@@ -236,21 +233,21 @@ DigitPath get_codeboard_digit_path(
236233

237234
return path;
238235
}
239-
size_t get_codeboard_path_cost(const DigitPath& path){
240-
size_t total_cost = 0;
236+
Milliseconds get_codeboard_path_cost(const DigitPath& path){
237+
Milliseconds total_cost = 0ms;
241238
for (uint8_t c = 0; c < path.length; c++){
242239
total_cost += path.path[c].delay;
243240
}
244241
return total_cost;
245242
}
246-
size_t get_codeboard_path_cost(const std::vector<DigitPath>& path){
247-
size_t total_cost = 0;
243+
Milliseconds get_codeboard_path_cost(const std::vector<DigitPath>& path){
244+
Milliseconds total_cost = 0ms;
248245
for (const DigitPath& digit : path){
249-
size_t cost = get_codeboard_path_cost(digit);
246+
Milliseconds cost = get_codeboard_path_cost(digit);
250247
if (digit.left_cursor){
251248
cost++;
252249
}
253-
cost = std::max<size_t>(cost, 8);
250+
cost = std::max<Milliseconds>(cost, 64ms);
254251
total_cost += cost;
255252
}
256253
return total_cost;
@@ -260,7 +257,9 @@ std::vector<DigitPath> get_codeboard_path(
260257
KeyboardLayout keyboard_layout,
261258
const std::vector<CodeboardPosition>& positions, size_t s, size_t e,
262259
CodeboardPosition start,
263-
uint8_t scroll_delay, uint8_t wrap_delay, bool reordering
260+
Milliseconds scroll_delay,
261+
Milliseconds wrap_delay,
262+
bool reordering
264263
){
265264
if (e - s == 1){
266265
return {get_codeboard_digit_path(start, positions[s], scroll_delay, wrap_delay)};
@@ -305,7 +304,9 @@ std::vector<DigitPath> get_codeboard_path(
305304
std::vector<DigitPath> get_codeboard_path(
306305
Logger& logger,
307306
KeyboardLayout keyboard_layout, const std::string& code,
308-
uint8_t scroll_delay, uint8_t wrap_delay, bool reordering,
307+
Milliseconds scroll_delay,
308+
Milliseconds wrap_delay,
309+
bool reordering,
309310
CodeboardPosition start = {0, 0}
310311
){
311312
auto get_keyboard_layout = [](KeyboardLayout keyboard_layout){
@@ -334,28 +335,30 @@ std::vector<DigitPath> get_codeboard_path(
334335
keyboard_layout,
335336
positions, 0, positions.size(),
336337
start,
337-
scroll_delay, wrap_delay, reordering
338+
scroll_delay,
339+
wrap_delay,
340+
reordering
338341
);
339342
}
340343

341344

342345
void move_codeboard(SwitchControllerContext& context, const DigitPath& path){
343-
uint16_t delay = 3;
346+
Milliseconds delay = 24ms;
344347
if (path.length > 0){
345348
size_t last = (size_t)path.length - 1;
346349
for (size_t c = 0; c < last; c++){
347350
ssf_issue_scroll(
348351
context,
349352
path.path[c].direction,
350353
path.path[c].delay,
351-
6
354+
48ms
352355
);
353356
}
354357
ssf_issue_scroll(
355358
context,
356359
path.path[last].direction,
357-
0,
358-
6
360+
0ms,
361+
48ms
359362
);
360363
delay = path.path[last].delay;
361364
}
@@ -376,8 +379,8 @@ void run_codeboard_path(SwitchControllerContext& context, const std::vector<Digi
376379
FastCodeEntrySettings::FastCodeEntrySettings(const FastCodeEntrySettingsOption& option)
377380
: keyboard_layout(option.KEYBOARD_LAYOUT)
378381
, include_plus(!option.SKIP_PLUS)
379-
, scroll_delay(option.SCROLL_DELAY)
380-
, wrap_delay(option.WRAP_DELAY)
382+
, scroll_delay(option.SCROLL_DELAY0)
383+
, wrap_delay(option.WRAP_DELAY0)
381384
, digit_reordering(option.DIGIT_REORDERING)
382385
{}
383386

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_FastCodeEntry.h

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "Common/Cpp/Options/GroupOption.h"
1313
#include "Common/Cpp/Options/StaticTextOption.h"
1414
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
15-
#include "Common/Cpp/Options/TimeExpressionOption.h"
15+
#include "Common/Cpp/Options/TimeDurationOption.h"
1616
#include "Common/Cpp/Options/EnumDropdownOption.h"
1717
#include "NintendoSwitch/Controllers/NintendoSwitch_Controller.h"
1818

@@ -21,6 +21,9 @@ namespace PokemonAutomation{
2121
namespace NintendoSwitch{
2222

2323

24+
using namespace std::chrono_literals;
25+
26+
2427

2528
enum class KeyboardLayout{
2629
QWERTY,
@@ -37,8 +40,8 @@ class FastCodeEntrySettingsOption : public GroupOption{
3740

3841
SectionDividerOption m_advanced_options;
3942
BooleanCheckBoxOption DIGIT_REORDERING;
40-
TimeExpressionOption<uint8_t> SCROLL_DELAY;
41-
TimeExpressionOption<uint8_t> WRAP_DELAY;
43+
MillisecondsOption SCROLL_DELAY0;
44+
MillisecondsOption WRAP_DELAY0;
4245
};
4346

4447

@@ -52,7 +55,7 @@ struct CodeboardPosition{
5255
};
5356
struct CodeboardScroll{
5457
DpadPosition direction;
55-
uint8_t delay;
58+
Milliseconds delay;
5659
};
5760
//static_assert(sizeof(CodeboardScroll) == sizeof(uint8_t));
5861
struct DigitPath{
@@ -73,8 +76,8 @@ void move_codeboard(SwitchControllerContext& context, const DigitPath& path);
7376
struct FastCodeEntrySettings{
7477
KeyboardLayout keyboard_layout = KeyboardLayout::QWERTY;
7578
bool include_plus = true;
76-
uint8_t scroll_delay = 8;
77-
uint8_t wrap_delay = 8;
79+
Milliseconds scroll_delay = 64ms;
80+
Milliseconds wrap_delay = 64ms;
7881
bool digit_reordering = false;
7982

8083
FastCodeEntrySettings() = default;

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_FriendCodeAdder.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,28 @@ FriendCodeAdder::FriendCodeAdder()
4444
, m_advanced_options(
4545
"<font size=4><b>Advanced Options:</b> You should not need to touch anything below here.</font>"
4646
)
47-
, OPEN_CODE_PAD_DELAY(
47+
, OPEN_CODE_PAD_DELAY0(
4848
"<b>Open Code Pad Delay</b>",
4949
LockMode::LOCK_WHILE_RUNNING,
50-
TICKS_PER_SECOND,
51-
"1 * TICKS_PER_SECOND"
50+
"1000 ms"
5251
)
53-
, SEARCH_TIME(
52+
, SEARCH_TIME0(
5453
"<b>Search Time:</b><br>Wait this long after initiating search.",
5554
LockMode::LOCK_WHILE_RUNNING,
56-
TICKS_PER_SECOND,
57-
"3 * TICKS_PER_SECOND"
55+
"3000 ms"
5856
)
59-
, TOGGLE_BEST_STATUS_DELAY(
57+
, TOGGLE_BEST_STATUS_DELAY0(
6058
"<b>Toggle Best Delay:</b><br>Time needed to toggle the best friend status.",
6159
LockMode::LOCK_WHILE_RUNNING,
62-
TICKS_PER_SECOND,
63-
"1 * TICKS_PER_SECOND"
60+
"1000 ms"
6461
)
6562
{
6663
PA_ADD_OPTION(USER_SLOT);
6764
PA_ADD_OPTION(FRIEND_CODES);
6865
PA_ADD_STATIC(m_advanced_options);
69-
PA_ADD_OPTION(OPEN_CODE_PAD_DELAY);
70-
PA_ADD_OPTION(SEARCH_TIME);
71-
PA_ADD_OPTION(TOGGLE_BEST_STATUS_DELAY);
66+
PA_ADD_OPTION(OPEN_CODE_PAD_DELAY0);
67+
PA_ADD_OPTION(SEARCH_TIME0);
68+
PA_ADD_OPTION(TOGGLE_BEST_STATUS_DELAY0);
7269
}
7370

7471
void FriendCodeAdder::program(SingleSwitchProgramEnvironment& env, SwitchControllerContext& context){
@@ -84,12 +81,12 @@ void FriendCodeAdder::program(SingleSwitchProgramEnvironment& env, SwitchControl
8481
PokemonSwSh::home_to_add_friends(context, USER_SLOT - 1, 3, first);
8582
first = false;
8683

87-
ssf_press_button1(context, BUTTON_A, OPEN_CODE_PAD_DELAY);
84+
ssf_press_button(context, BUTTON_A, OPEN_CODE_PAD_DELAY0);
8885
enter_digits(context, 12, &code[0]);
8986

90-
pbf_wait(context, SEARCH_TIME);
91-
ssf_press_button1(context, BUTTON_A, TOGGLE_BEST_STATUS_DELAY);
92-
ssf_press_button1(context, BUTTON_A, TOGGLE_BEST_STATUS_DELAY);
87+
pbf_wait(context, SEARCH_TIME0);
88+
ssf_press_button(context, BUTTON_A, TOGGLE_BEST_STATUS_DELAY0);
89+
ssf_press_button(context, BUTTON_A, TOGGLE_BEST_STATUS_DELAY0);
9390
pbf_press_button(context, BUTTON_HOME, 80ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0);
9491
}
9592
}

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_FriendCodeAdder.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "Common/Cpp/Options/StaticTextOption.h"
1111
#include "Common/Cpp/Options/SimpleIntegerOption.h"
12-
#include "Common/Cpp/Options/TimeExpressionOption.h"
12+
#include "Common/Cpp/Options/TimeDurationOption.h"
1313
#include "NintendoSwitch/Options/NintendoSwitch_FriendCodeListOption.h"
1414
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1515

@@ -33,9 +33,9 @@ class FriendCodeAdder : public SingleSwitchProgramInstance{
3333
SimpleIntegerOption<uint8_t> USER_SLOT;
3434
FriendCodeListOption FRIEND_CODES;
3535
SectionDividerOption m_advanced_options;
36-
TimeExpressionOption<uint16_t> OPEN_CODE_PAD_DELAY;
37-
TimeExpressionOption<uint16_t> SEARCH_TIME;
38-
TimeExpressionOption<uint16_t> TOGGLE_BEST_STATUS_DELAY;
36+
MillisecondsOption OPEN_CODE_PAD_DELAY0;
37+
MillisecondsOption SEARCH_TIME0;
38+
MillisecondsOption TOGGLE_BEST_STATUS_DELAY0;
3939
};
4040

4141

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_FriendDelete.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,47 +36,44 @@ FriendDelete::FriendDelete()
3636
LockMode::LOCK_WHILE_RUNNING,
3737
false
3838
)
39-
, VIEW_FRIEND_DELAY(
39+
, VIEW_FRIEND_DELAY0(
4040
"<b>View Friend Delay:</b><br>Delay from opening a friend to when you can press buttons.",
4141
LockMode::LOCK_WHILE_RUNNING,
42-
TICKS_PER_SECOND,
43-
"2 * TICKS_PER_SECOND"
42+
"2000 ms"
4443
)
45-
, DELETE_FRIEND_DELAY(
44+
, DELETE_FRIEND_DELAY0(
4645
"<b>Delete Friend Delay:</b><br>Delay to delete the friend.",
4746
LockMode::LOCK_WHILE_RUNNING,
48-
TICKS_PER_SECOND,
49-
"8 * TICKS_PER_SECOND"
47+
"8000 ms"
5048
)
51-
, FINISH_DELETE_DELAY(
49+
, FINISH_DELETE_DELAY0(
5250
"<b>Finish Delete Delay:</b><br>Delay after deleting a friend.",
5351
LockMode::LOCK_WHILE_RUNNING,
54-
TICKS_PER_SECOND,
55-
"2 * TICKS_PER_SECOND"
52+
"2000 ms"
5653
)
5754
{
5855
PA_ADD_OPTION(FRIENDS_TO_DELETE);
5956
PA_ADD_OPTION(BLOCK_FRIENDS);
60-
PA_ADD_OPTION(VIEW_FRIEND_DELAY);
61-
PA_ADD_OPTION(DELETE_FRIEND_DELAY);
62-
PA_ADD_OPTION(FINISH_DELETE_DELAY);
57+
PA_ADD_OPTION(VIEW_FRIEND_DELAY0);
58+
PA_ADD_OPTION(DELETE_FRIEND_DELAY0);
59+
PA_ADD_OPTION(FINISH_DELETE_DELAY0);
6360
}
6461
void FriendDelete::program(SingleSwitchProgramEnvironment& env, SwitchControllerContext& context){
6562
pbf_press_button(context, BUTTON_A, 5, 5);
6663

6764
for (uint16_t c = 0; c < FRIENDS_TO_DELETE; c++){
68-
pbf_press_button(context, BUTTON_A, 5, VIEW_FRIEND_DELAY); // View friend
65+
pbf_press_button(context, BUTTON_A, 40ms, VIEW_FRIEND_DELAY0); // View friend
6966
pbf_press_dpad(context, DPAD_DOWN, 5, 5);
70-
pbf_press_button(context, BUTTON_A, 10, 90); // Click on Options
67+
pbf_press_button(context, BUTTON_A, 10, 90); // Click on Options
7168
if (BLOCK_FRIENDS){
7269
pbf_press_dpad(context, DPAD_DOWN, 5, 5);
7370
}
74-
pbf_press_button(context, BUTTON_A, 10, 90); // Click on Remove/Block Friend
71+
pbf_press_button(context, BUTTON_A, 10, 90); // Click on Remove/Block Friend
7572
if (BLOCK_FRIENDS){
76-
pbf_press_button(context, BUTTON_A, 5, VIEW_FRIEND_DELAY); // Confirm
73+
pbf_press_button(context, BUTTON_A, 40ms, VIEW_FRIEND_DELAY0); // Confirm
7774
}
78-
pbf_press_button(context, BUTTON_A, 5, DELETE_FRIEND_DELAY); // Confirm
79-
pbf_press_button(context, BUTTON_A, 5, FINISH_DELETE_DELAY); // Finish delete friend.
75+
pbf_press_button(context, BUTTON_A, 40ms, DELETE_FRIEND_DELAY0); // Confirm
76+
pbf_press_button(context, BUTTON_A, 40ms, FINISH_DELETE_DELAY0); // Finish delete friend.
8077
}
8178
}
8279

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_FriendDelete.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#include "Common/Cpp/Options/BooleanCheckBoxOption.h"
1111
#include "Common/Cpp/Options/SimpleIntegerOption.h"
12-
#include "Common/Cpp/Options/TimeExpressionOption.h"
12+
#include "Common/Cpp/Options/TimeDurationOption.h"
1313
#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h"
1414

1515
namespace PokemonAutomation{
@@ -31,9 +31,9 @@ class FriendDelete : public SingleSwitchProgramInstance{
3131
private:
3232
SimpleIntegerOption<uint16_t> FRIENDS_TO_DELETE;
3333
BooleanCheckBoxOption BLOCK_FRIENDS;
34-
TimeExpressionOption<uint16_t> VIEW_FRIEND_DELAY;
35-
TimeExpressionOption<uint16_t> DELETE_FRIEND_DELAY;
36-
TimeExpressionOption<uint16_t> FINISH_DELETE_DELAY;
34+
MillisecondsOption VIEW_FRIEND_DELAY0;
35+
MillisecondsOption DELETE_FRIEND_DELAY0;
36+
MillisecondsOption FINISH_DELETE_DELAY0;
3737
};
3838

3939

0 commit comments

Comments
 (0)