Skip to content

Commit 88320e3

Browse files
committed
Remove the LED-setting automation feature
Remove the feature that allows setting the RX/TX LEDs after an automation sequence. Calling set_leds at the start of the next automation sequence (or before a call to pause_automation) provides the same feature and is less confusing.
1 parent a1f787d commit 88320e3

File tree

5 files changed

+72
-85
lines changed

5 files changed

+72
-85
lines changed

src/lib/automation-utils.c

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,21 @@
66

77

88
/* Perform controller switching */
9-
void switch_controller(enum switch_mode mode, enum led_state end_led_state)
9+
void switch_controller(enum switch_mode mode)
1010
{
1111
if (mode == REAL_TO_VIRT) {
12-
SEND_BUTTON_SEQUENCE(KEEP_LEDS,
12+
SEND_BUTTON_SEQUENCE(
1313
{ BT_L, DP_NEUTRAL, SEQ_HOLD, 1 }, /* Reconnect the controller */
1414
{ BT_NONE, DP_NEUTRAL, SEQ_HOLD, 10 }, /* Wait for reconnection */
1515
);
1616
} else {
17-
go_to_main_menu(KEEP_LEDS);
17+
go_to_main_menu();
1818
}
1919

2020
/* In both cases, the controller is now connected, the main menu is shown, and the
2121
cursor is on the game icon */
2222

23-
SEND_BUTTON_SEQUENCE((mode == REAL_TO_VIRT) ? KEEP_LEDS : end_led_state,
23+
SEND_BUTTON_SEQUENCE(
2424
{ BT_NONE, DP_BOTTOM, SEQ_HOLD, 1 }, /* News button */
2525
{ BT_NONE, DP_RIGHT, SEQ_MASH, 3 }, /* Controllers button */
2626
{ BT_A, DP_NEUTRAL, SEQ_HOLD, 1 }, /* Enter controllers settings */
@@ -32,47 +32,47 @@ void switch_controller(enum switch_mode mode, enum led_state end_led_state)
3232
);
3333

3434
if (mode == REAL_TO_VIRT) {
35-
SEND_BUTTON_SEQUENCE(KEEP_LEDS,
35+
SEND_BUTTON_SEQUENCE(
3636
{ BT_A, DP_NEUTRAL, SEQ_HOLD, 1 }, /* Register as controller 1 */
3737
{ BT_NONE, DP_NEUTRAL, SEQ_HOLD, 15 }, /* Wait for registration */
3838

3939
{ BT_H, DP_NEUTRAL, SEQ_HOLD, 2 }, /* Return to the main menu */
4040
{ BT_NONE, DP_NEUTRAL, SEQ_HOLD, 25 }, /* Wait for the main menu */
4141
);
4242

43-
go_to_game(end_led_state);
43+
go_to_game();
4444
}
4545
}
4646

4747

4848
/* Go to the main menu, from the currently playing game or menu. */
49-
void go_to_main_menu(enum led_state end_led_state)
49+
void go_to_main_menu(void)
5050
{
51-
SEND_BUTTON_SEQUENCE(KEEP_LEDS,
51+
SEND_BUTTON_SEQUENCE(
5252
{ BT_H, DP_NEUTRAL, SEQ_HOLD, 2 }, /* Go to main menu */
5353
{ BT_NONE, DP_NEUTRAL, SEQ_HOLD, 25 }, /* Wait for the main menu */
5454
);
5555
}
5656

5757

5858
/* Go back to the game, from the main menu. */
59-
void go_to_game(enum led_state end_led_state)
59+
void go_to_game(void)
6060
{
61-
SEND_BUTTON_SEQUENCE(end_led_state,
61+
SEND_BUTTON_SEQUENCE(
6262
{ BT_H, DP_NEUTRAL, SEQ_HOLD, 2 }, /* Go back to the game */
6363
{ BT_NONE, DP_NEUTRAL, SEQ_HOLD, 40 }, /* Wait for the game */
6464
);
6565
}
6666

6767

6868
/* Configure the Switch’s clock to manual mode */
69-
void set_clock_to_manual_from_any(bool in_game, enum led_state end_led_state)
69+
void set_clock_to_manual_from_any(bool in_game)
7070
{
7171
if (in_game) {
72-
go_to_main_menu(KEEP_LEDS);
72+
go_to_main_menu();
7373
}
7474

75-
SEND_BUTTON_SEQUENCE(KEEP_LEDS,
75+
SEND_BUTTON_SEQUENCE(
7676
{ BT_NONE, DP_BOTTOM, SEQ_HOLD, 1 }, /* News button */
7777
{ BT_NONE, DP_RIGHT, SEQ_MASH, 4 }, /* Settings button */
7878
{ BT_A, DP_NEUTRAL, SEQ_HOLD, 1 }, /* Enter settings */
@@ -90,22 +90,22 @@ void set_clock_to_manual_from_any(bool in_game, enum led_state end_led_state)
9090
{ BT_NONE, DP_NEUTRAL, SEQ_HOLD, 2 }, /* Wait for menu */
9191
);
9292

93-
go_to_main_menu(in_game ? KEEP_LEDS : end_led_state);
93+
go_to_main_menu();
9494

9595
if (in_game) {
96-
go_to_game(end_led_state);
96+
go_to_game();
9797
}
9898
}
9999

100100

101101
/* Configure the Switch’s clock to automatic mode */
102-
void set_clock_to_auto_from_manual(bool in_game, enum led_state end_led_state)
102+
void set_clock_to_auto_from_manual(bool in_game)
103103
{
104104
if (in_game) {
105-
go_to_main_menu(KEEP_LEDS);
105+
go_to_main_menu();
106106
}
107107

108-
SEND_BUTTON_SEQUENCE(NO_LEDS,
108+
SEND_BUTTON_SEQUENCE(
109109
{ BT_NONE, DP_BOTTOM, SEQ_HOLD, 1 }, /* News button */
110110
{ BT_NONE, DP_RIGHT, SEQ_MASH, 4 }, /* Settings button */
111111
{ BT_A, DP_NEUTRAL, SEQ_HOLD, 1 }, /* Enter settings */
@@ -119,16 +119,16 @@ void set_clock_to_auto_from_manual(bool in_game, enum led_state end_led_state)
119119
{ BT_A, DP_NEUTRAL, SEQ_MASH, 1 }, /* Set to automatic */
120120
);
121121

122-
go_to_main_menu(in_game ? KEEP_LEDS : end_led_state);
122+
go_to_main_menu();
123123

124124
if (in_game) {
125-
go_to_game(end_led_state);
125+
go_to_game();
126126
}
127127
}
128128

129129

130130
/* Apply an offset to the Switch’s clock’s year. */
131-
void change_clock_year(bool in_game, int8_t offset, enum led_state end_led_state)
131+
void change_clock_year(bool in_game, int8_t offset)
132132
{
133133
uint8_t button;
134134
uint8_t num;
@@ -144,10 +144,10 @@ void change_clock_year(bool in_game, int8_t offset, enum led_state end_led_state
144144
}
145145

146146
if (in_game) {
147-
go_to_main_menu(KEEP_LEDS);
147+
go_to_main_menu();
148148
}
149149

150-
SEND_BUTTON_SEQUENCE(BOTH_LEDS,
150+
SEND_BUTTON_SEQUENCE(
151151
{ BT_NONE, DP_BOTTOM, SEQ_HOLD, 1 }, /* News button */
152152
{ BT_NONE, DP_RIGHT, SEQ_MASH, 4 }, /* Settings button */
153153
{ BT_A, DP_NEUTRAL, SEQ_HOLD, 1 }, /* Enter settings */
@@ -168,9 +168,9 @@ void change_clock_year(bool in_game, int8_t offset, enum led_state end_led_state
168168
{ BT_NONE, DP_NEUTRAL, SEQ_HOLD, 2 }, /* Wait for menu */
169169
);
170170

171-
go_to_main_menu(in_game ? KEEP_LEDS : end_led_state);
171+
go_to_main_menu();
172172

173173
if (in_game) {
174-
go_to_game(end_led_state);
174+
go_to_game();
175175
}
176176
}

src/lib/automation-utils.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,18 @@ enum switch_mode {
2828
* currently playing game”. The virtual controller will (re-)connect (as controller 2),
2929
* activate the controller setup menu, validate it to become back controller 1, and
3030
* go back to the game.
31-
*
32-
* The second parameter allows setting the RX/TX LEDs once the operation completes.
3331
*/
34-
void switch_controller(enum switch_mode mode, enum led_state end_led_state);
32+
void switch_controller(enum switch_mode mode);
3533

3634
/*
3735
* Go to the main menu, from the currently playing game or menu.
3836
*/
39-
void go_to_main_menu(enum led_state end_led_state);
37+
void go_to_main_menu(void);
4038

4139
/*
4240
* Go back to the game, from the main menu.
4341
*/
44-
void go_to_game(enum led_state end_led_state);
42+
void go_to_game(void);
4543

4644
/*
4745
* Configure the Switch’s clock to manual mode, starting from the game or the
@@ -51,9 +49,8 @@ void go_to_game(enum led_state end_led_state);
5149
*
5250
* The first parameter indicates that the operations starts in-game (and will end
5351
* in-game)
54-
* The second parameter allows setting the RX/TX LEDs once the operation completes.
5552
*/
56-
void set_clock_to_manual_from_any(bool in_game, enum led_state end_led_state);
53+
void set_clock_to_manual_from_any(bool in_game);
5754

5855
/*
5956
* Configure the Switch’s clock to automatic mode, starting from the game or the
@@ -63,9 +60,8 @@ void set_clock_to_manual_from_any(bool in_game, enum led_state end_led_state);
6360
*
6461
* The first parameter indicates that the operations starts in-game (and will end
6562
* in-game)
66-
* The second parameter allows setting the RX/TX LEDs once the operation completes.
6763
*/
68-
void set_clock_to_auto_from_manual(bool in_game, enum led_state end_led_state);
64+
void set_clock_to_auto_from_manual(bool in_game);
6965

7066
/*
7167
* Apply an offset to the Switch’s clock’s year.
@@ -77,6 +73,6 @@ void set_clock_to_auto_from_manual(bool in_game, enum led_state end_led_state);
7773
* The second parameter is the year offset to apply (-1: substract a year, 1: add a year)
7874
* The third parameter allows setting the RX/TX LEDs once the operation completes.
7975
*/
80-
void change_clock_year(bool in_game, int8_t offset, enum led_state end_led_state);
76+
void change_clock_year(bool in_game, int8_t offset);
8177

8278
#endif

src/lib/automation.c

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,6 @@ bool init_automation(void)
9898
/* Set the LED state to be sent in the next request */
9999
void set_leds(enum led_state leds)
100100
{
101-
if (leds == KEEP_LEDS) {
102-
return;
103-
}
104-
105101
if (leds & TX_LED) {
106102
sent_data.magic_and_leds |= MAGIC_TX_STATE;
107103
} else {
@@ -130,11 +126,10 @@ void send_update(enum button_state buttons, enum d_pad_state d_pad,
130126

131127
/* Send a button sequence */
132128
void send_button_sequence(const struct button_d_pad_state sequence[],
133-
size_t sequence_length, enum led_state end_leds)
129+
size_t sequence_length)
134130
{
135131
for (size_t pos = 0 ; pos < sequence_length ; pos += 1) {
136132
const struct button_d_pad_state* cur = &sequence[pos];
137-
bool is_last = (pos == (sequence_length - 1));
138133

139134
uint16_t repeat_count = cur->repeat_count;
140135
enum seq_mode mode = cur->mode;
@@ -143,10 +138,6 @@ void send_button_sequence(const struct button_d_pad_state sequence[],
143138
sent_data.buttons = cur->buttons;
144139
sent_data.d_pad = cur->d_pad;
145140

146-
if (is_last && repeat_count == 1) {
147-
set_leds(end_leds);
148-
}
149-
150141
send_current();
151142

152143
if (mode == SEQ_MASH) {

src/lib/automation.h

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ enum led_state {
2828
TX_LED = 0x01, /* Turn on TX LED */
2929
RX_LED = 0x02, /* Turn on RX LED */
3030
BOTH_LEDS = 0x03, /* Turn on RX and TX LEDs */
31-
KEEP_LEDS = 0x04, /* Do not change the LEDs state */
3231
};
3332

3433
/* Stick coordinates */
@@ -120,22 +119,21 @@ void send_update(enum button_state buttons, enum d_pad_state d_pad,
120119
* Send a button sequence.
121120
* The first parameter is a pointer to an array of states to run in sequence.
122121
* The second parameter is the number of entries in the array.
123-
* The third parameter is the led state to set at the end of the sequence.
124122
*/
125123
void send_button_sequence(const struct button_d_pad_state sequence[],
126-
size_t sequence_length, enum led_state end_leds);
124+
size_t sequence_length);
127125

128126
/*
129127
* Macro to simplify the use of send_button_sequence.
130128
*
131-
* Example usage: SEND_BUTTON_SEQUENCE(NO_LEDS, { BUTTON_A, DP_NEUTRAL, SEQ_HOLD, 5},
129+
* Example usage: SEND_BUTTON_SEQUENCE({ BUTTON_A, DP_NEUTRAL, SEQ_HOLD, 5},
132130
* { NO_BUTTONS, DP_TOP, SEQ_HOLD, 1 });
133131
*/
134-
#define SEND_BUTTON_SEQUENCE(END_LEDS, FIRST_STATE, ...) \
132+
#define SEND_BUTTON_SEQUENCE(FIRST_STATE, ...) \
135133
send_button_sequence((struct button_d_pad_state[]){ \
136134
FIRST_STATE, __VA_ARGS__ }, sizeof((struct button_d_pad_state[]){ \
137135
FIRST_STATE, __VA_ARGS__ }) / \
138-
sizeof(struct button_d_pad_state), END_LEDS);
136+
sizeof(struct button_d_pad_state));
139137

140138
/*
141139
* Send an update that reset the button/controller state to a neutral state

0 commit comments

Comments
 (0)