Skip to content

Commit d1fd6f8

Browse files
committed
Fix FCE when wrapping the keyboard.
1 parent 9735480 commit d1fd6f8

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed

SerialPrograms/Source/NintendoSwitch/DevPrograms/TestProgramSwitch.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,16 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
318318

319319
// std::terminate();
320320

321+
Milliseconds unit = 24ms;
321322

323+
ssf_issue_scroll(context, DPAD_DOWN, 2*unit, 2*unit, unit);
324+
ssf_issue_scroll(context, DPAD_LEFT, unit, 2*unit, unit);
325+
ssf_issue_scroll(context, DPAD_LEFT, unit, 2*unit, unit);
326+
ssf_issue_scroll(context, DPAD_LEFT, unit, 2*unit, unit);
322327

328+
329+
330+
#if 0
323331
ImageRGB32 image("20250430-043221293730.png");
324332

325333
#if 1
@@ -329,7 +337,7 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
329337
results.log(logger, 110);
330338
}
331339
#endif
332-
340+
#endif
333341

334342

335343

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_KeyboardCodeEntry.cpp

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,41 @@ enum class KeyboardEntryAction : uint8_t{
123123
WRAP_MOVE_DOWN = 0x80 | (uint8_t)DpadPosition::DPAD_DOWN,
124124
WRAP_MOVE_LEFT = 0x80 | (uint8_t)DpadPosition::DPAD_LEFT,
125125
};
126+
bool is_button_press(KeyboardEntryAction action){
127+
switch (action){
128+
case KeyboardEntryAction::ENTER_CHAR:
129+
case KeyboardEntryAction::SCROLL_LEFT:
130+
return true;
131+
default:
132+
return false;
133+
}
134+
}
135+
bool is_move(KeyboardEntryAction action){
136+
switch (action){
137+
case KeyboardEntryAction::NORM_MOVE_UP:
138+
case KeyboardEntryAction::NORM_MOVE_RIGHT:
139+
case KeyboardEntryAction::NORM_MOVE_DOWN:
140+
case KeyboardEntryAction::NORM_MOVE_LEFT:
141+
case KeyboardEntryAction::WRAP_MOVE_UP:
142+
case KeyboardEntryAction::WRAP_MOVE_RIGHT:
143+
case KeyboardEntryAction::WRAP_MOVE_DOWN:
144+
case KeyboardEntryAction::WRAP_MOVE_LEFT:
145+
return true;
146+
default:
147+
return false;
148+
}
149+
}
150+
bool is_wrap(KeyboardEntryAction action){
151+
switch (action){
152+
case KeyboardEntryAction::WRAP_MOVE_UP:
153+
case KeyboardEntryAction::WRAP_MOVE_RIGHT:
154+
case KeyboardEntryAction::WRAP_MOVE_DOWN:
155+
case KeyboardEntryAction::WRAP_MOVE_LEFT:
156+
return true;
157+
default:
158+
return false;
159+
}
160+
}
126161

127162
struct KeyboardEntryActionWithDelay{
128163
KeyboardEntryAction action;
@@ -260,11 +295,18 @@ Milliseconds keyboard_populate_delays(
260295
path_with_delays.resize(path.size());
261296
for (size_t c = 0; c < path_with_delays.size(); c++){
262297
KeyboardEntryAction action = path[c];
263-
Milliseconds delay = (uint8_t)action >= (uint8_t)KeyboardEntryAction::ENTER_CHAR
298+
Milliseconds delay = is_button_press(action)
264299
? delays.press_delay
265-
: (uint8_t)action & 0x80
266-
? delays.wrap_delay
267-
: delays.move_delay;
300+
: delays.move_delay;
301+
302+
// If we are wrapping and the previous action is a move, then we can't
303+
// overlap.
304+
if (is_wrap(action) && c != 0){
305+
KeyboardEntryActionWithDelay& previous = path_with_delays[c - 1];
306+
if (is_move(previous.action)){
307+
previous.delay = delays.hold;
308+
}
309+
}
268310

269311
path_with_delays[c].action = action;
270312
path_with_delays[c].delay = delay;

SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_NumberCodeEntry.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ enum class NumberEntryAction : uint8_t{
6060
MOVE_DOWN = (uint8_t)DpadPosition::DPAD_DOWN,
6161
MOVE_LEFT = (uint8_t)DpadPosition::DPAD_LEFT,
6262
};
63+
bool is_button_press(NumberEntryAction action){
64+
switch (action){
65+
case NumberEntryAction::ENTER_CHAR:
66+
case NumberEntryAction::SCROLL_LEFT:
67+
return true;
68+
default:
69+
return false;
70+
}
71+
}
6372

6473
struct NumberEntryActionWithDelay{
6574
NumberEntryAction action;
@@ -169,7 +178,7 @@ Milliseconds numberpad_populate_delays(
169178
path_with_delays.resize(path.size());
170179
for (size_t c = 0; c < path_with_delays.size(); c++){
171180
NumberEntryAction action = path[c];
172-
Milliseconds delay = (uint8_t)action >= (uint8_t)NumberEntryAction::ENTER_CHAR
181+
Milliseconds delay = is_button_press(action)
173182
? delays.press_delay
174183
: delays.move_delay;
175184

0 commit comments

Comments
 (0)