application: define at one location the folder for the different track types

This commit is contained in:
King Kévin 2021-04-22 21:28:24 +02:00
parent 08134e0d88
commit f81ec06f93
1 changed files with 24 additions and 13 deletions

View File

@ -156,6 +156,17 @@ static uint32_t last_finished = 0;
/** number of possible talk tracks */
#define TALK_TRACKS 29
/** folder number for welcome tracks */
#define WELCOME_FOLDER 1
/** folder number for music tracks */
#define MUSIC_FOLDER 2
/** folder number for exit messages tracks */
#define EXIT_FOLDER 4
/** folder number for talk tracks */
#define TALK_FOLDER 3
/** folder number for time number announcement tracks */
#define TIME_FOLDER 5
size_t putc(char c)
{
size_t length = 0; // number of characters printed
@ -319,43 +330,43 @@ static bool mp3_response(void)
const uint16_t time_passed = (rtc_get_counter_val() - timer_door_closed) / RTC_TICKS_SECOND; // how many seconds have passed since door has been closed
switch (playing_state) {
case PLAYING_STATE_INTRO: // the welcome message finished
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (2 << 8) + (rtc_get_counter_val() % MUSIC_TRACKS) + 1); // play random music track
playing_state = PLAYING_STATE_SONG; // remember we are playong a song (for the first time)
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (MUSIC_FOLDER << 8) + (rtc_get_counter_val() % MUSIC_TRACKS) + 1); // play random music track
playing_state = PLAYING_STATE_SONG; // remember we are playing a song (for the first time)
break;
case PLAYING_STATE_SONG: // the song finished
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (5 << 8) + 65); // play time announcement
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (TIME_FOLDER << 8) + 65); // play time announcement
playing_state = PLAYING_STATE_TIMER_INTRO; // remember we are playing the timer announcement
break;
case PLAYING_STATE_TIMER_INTRO: // the time intro finished
if (0 == (time_passed / 60)) {
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (5 << 8) + 60); // play number of minutes announcement
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (TIME_FOLDER << 8) + 60); // play number of minutes announcement
} else {
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (5 << 8) + (time_passed / 60)); // play number of minutes announcement
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (TIME_FOLDER << 8) + (time_passed / 60)); // play number of minutes announcement
}
playing_state = PLAYING_STATE_TIMER_MINUTES; // remember we are playing the number of minutes
break;
case PLAYING_STATE_TIMER_MINUTES: // the minutes announcement finished
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (5 << 8) + 62); // play minute announcement
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (TIME_FOLDER << 8) + 62); // play minute announcement
playing_state = PLAYING_STATE_TIMER_MINUTE; // remember we are playing the minute announcement
break;
case PLAYING_STATE_TIMER_MINUTE: // the minute announcement finished
if (0 == (time_passed % 60)) {
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (5 << 8) + 60); // play number of seconds announcement
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (TIME_FOLDER << 8) + 60); // play number of seconds announcement
} else {
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (5 << 8) + (time_passed % 60)); // play number of seconds announcement
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (TIME_FOLDER << 8) + (time_passed % 60)); // play number of seconds announcement
}
playing_state = PLAYING_STATE_TIMER_SECONDS; // remember we are playing the number of seconds
break;
case PLAYING_STATE_TIMER_SECONDS: // the number of seconds finished
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (5 << 8) + 64); // play time outro announcement
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (TIME_FOLDER << 8) + 64); // play time outro announcement
playing_state = PLAYING_STATE_TIMER_OUTRO; // remember we are playing the timer outro announcement
break;
case PLAYING_STATE_TIMER_OUTRO: // the timer outro announcement finished
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (3 << 8) + (rtc_get_counter_val() % TALK_TRACKS) + 1); // play random talk track
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (TALK_FOLDER << 8) + (rtc_get_counter_val() % TALK_TRACKS) + 1); // play random talk track
playing_state = PLAYING_STATE_TALK; // remember we are playing the talk track
break;
case PLAYING_STATE_TALK: // the talk track finished
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (2 << 8) + (rtc_get_counter_val() % MUSIC_TRACKS) + 1); // play random music track
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (MUSIC_FOLDER << 8) + (rtc_get_counter_val() % MUSIC_TRACKS) + 1); // play random music track
playing_state = PLAYING_STATE_SONG; // remember we are playing a song (again)
break;
default:
@ -805,14 +816,14 @@ void main(void)
leds_sign(true); // show on the sign that the toilet is occupied
led_tm1637_time(0, 0); // start showing time on display
led_tm1637_on(); // ensure the display is on
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (1 << 8) + (rtc_get_counter_val() % WELCOME_TRACKS) + 1); // play random welcome track
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (WELCOME_FOLDER << 8) + (rtc_get_counter_val() % WELCOME_TRACKS) + 1); // play random welcome track
playing_state = PLAYING_STATE_INTRO; // remember we are playing the welcome message
} else if (!closed && timer_door_closed) { // door has been opened
puts("door opened\n");
timer_door_closed = 0; // remember door is now open
leds_sign(false); // show on sign the toilet is free
led_tm1637_off(); // stop showing time
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (4 << 8) + (rtc_get_counter_val() % EXIT_TRACKS) + 1); // play random exit message track
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (EXIT_FOLDER << 8) + (rtc_get_counter_val() % EXIT_TRACKS) + 1); // play random exit message track
playing_state = PLAYING_STATE_EXIT; // we are playing the exit track
}
}