-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcharacter_selection.c
159 lines (100 loc) · 3.49 KB
/
character_selection.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/*
* character_selection.c
*
* Allows the user to choose the character of his choice.
* Displays LEDs of 2 different colors and a short tune for each
* character.
*/
#include <audio/play_sound_file.h>
#include <audio/audio_thread.h>
#include <fat.h>
#include "hal.h"
#include <leds.h>
#include <sdio.h>
#include <selector.h>
#include "spi_comm.h"
#include "usbcfg.h"
#include <character_selection.h>
static THD_WORKING_AREA(waCharacterSelection, 256);
static THD_FUNCTION(CharacterSelection, arg) {
chRegSetThreadName(__FUNCTION__);
(void)arg;
systime_t time;
sdio_connect();
int old_status = 0; // shows the previous status of the selector
playSoundFile("Son_MK8DX/choose_character.wav", SF_FORCE_CHANGE); // asking the user to choose a character
chThdSleepMilliseconds(SONG_IGNORING_TIME); // waits until the audio finishes
while(1){
int status = get_selector();
time = chVTGetSystemTime();
if (status != old_status){ // checks if the selector was moved to another position
old_status = status;
switch(status){
case MARIO:
playSoundFile("Son_MK8DX/itsame_mario.wav", SF_FORCE_CHANGE);
set_rgb_led(LED2, 100,0,0); // red
set_rgb_led(LED4, 0,0,100); // blue
set_rgb_led(LED6, 100,0,0);
set_rgb_led(LED8, 0,0,100);
break;
case LUIGI:
playSoundFile("Son_MK8DX/luigi_ohyeahluigi.wav", SF_FORCE_CHANGE);
set_rgb_led(LED2, 0,100,0); // green
set_rgb_led(LED4, 8,13,100); // blue
set_rgb_led(LED6, 0,100,0);
set_rgb_led(LED8, 8,13,100);
break;
case PEACH:
playSoundFile("Son_MK8DX/peach_peach.wav", SF_FORCE_CHANGE);
set_rgb_led(LED2, 94,57,74); // white
set_rgb_led(LED4, 33,73,82); // pink
set_rgb_led(LED6, 94,57,74);
set_rgb_led(LED8, 33,73,82);
break;
case DAISY:
playSoundFile("Son_MK8DX/daisy_yeahdaisy.wav", SF_FORCE_CHANGE);
set_rgb_led(LED2, 100,100,20); // white
set_rgb_led(LED4, 80,40,0); // yellow
set_rgb_led(LED6, 100,100,20);
set_rgb_led(LED8, 80,40,0);
break;
case TOAD:
playSoundFile("Son_MK8DX/toad.wav", SF_FORCE_CHANGE);
set_rgb_led(LED2, 95,14,6); // red
set_rgb_led(LED4, 97,97,97); // white
set_rgb_led(LED6, 95,14,6);
set_rgb_led(LED8, 97,97,97);
break;
case YOSHI:
playSoundFile("Son_MK8DX/yoshi.wav", SF_FORCE_CHANGE);
set_rgb_led(LED2, 1,86,0); // green
set_rgb_led(LED4, 96,96,96); // white
set_rgb_led(LED6, 1,86,0);
set_rgb_led(LED8, 96,96,96);
break;
case WARIO:
playSoundFile("Son_MK8DX/wario_wariotime.wav", SF_FORCE_CHANGE);
set_rgb_led(LED2, 100,100,0); // yellow
set_rgb_led(LED4, 61,13,98); // purple
set_rgb_led(LED6, 100,100,0);
set_rgb_led(LED8, 61,13,98);
break;
case WALUIGI:
playSoundFile("Son_MK8DX/waluigi_waluigi.wav", SF_FORCE_CHANGE);
set_rgb_led(LED2, 61,13,98); // purple
set_rgb_led(LED4, 0,0,25); // dark blue
set_rgb_led(LED6, 61,13,98);
set_rgb_led(LED8, 0,0,25);
break;
default: // if none of the 8 characters are chosen
playSoundFile("Son_MK8DX/choose_character.wav", SF_FORCE_CHANGE);
clear_leds();
break;
}
}
chThdSleepUntilWindowed(time, time + MS2ST(10));
}
}
void character_selection_start(void){
chThdCreateStatic(waCharacterSelection, sizeof(waCharacterSelection), NORMALPRIO, CharacterSelection, NULL);
}