application: add secret techno and kanguru modes

This commit is contained in:
King Kévin 2021-04-23 14:59:41 +02:00
parent 51f78852e5
commit 2758b5d4c4
1 changed files with 37 additions and 2 deletions

View File

@ -142,6 +142,8 @@ static enum playing_state_t {
PLAYING_STATE_TIMER_OUTRO, /**< playing the timer announcement closing word */
PLAYING_STATE_TALK, /**< playing any talk track */
PLAYING_STATE_EXIT, /**< playing any exit message */
PLAYING_STATE_TECHNO, /**< continuously play techno songs (use secret open/close sequence to enter modus) */
PLAYING_STATE_KANGURU, /**< continuously play kanguru sketches (use secret open/close/open/close sequence to enter modus) */
} playing_state = PLAYING_STATE_OFF; /**< which song group we are currently playing */
/** RTC timestamps when the last MP3 response track finished has been received */
@ -155,6 +157,10 @@ static uint32_t last_finished = 0;
#define EXIT_TRACKS 19
/** number of possible talk tracks */
#define TALK_TRACKS 29
/** number of possible techno music tracks */
#define TECHNO_TRACKS 237
/** number of possible kanguru */
#define KANGURU_TRACKS 81
/** folder number for welcome tracks */
#define WELCOME_FOLDER 1
@ -166,6 +172,13 @@ static uint32_t last_finished = 0;
#define TALK_FOLDER 3
/** folder number for time number announcement tracks */
#define TIME_FOLDER 5
/** folder number for techno music tracks */
#define TECHNO_FOLDER 6
/** folder number for kanguru tracks */
#define KANGURU_FOLDER 7
/** RTC timestamps when the door has previously been closed (even index, oldest first) or opened (odd index, oldest first) */
static uint32_t door_timestamps[4] = {0};
size_t putc(char c)
{
@ -369,6 +382,12 @@ static bool mp3_response(void)
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;
case PLAYING_STATE_TECHNO: // techno song completed, play the next one
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (TECHNO_FOLDER << 8) + (rtc_get_counter_val() % TECHNO_TRACKS) + 1); // play random techno music track
break;
case PLAYING_STATE_KANGURU: // kanguru sketch completed, play the next one
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (KANGURU_FOLDER << 8) + (rtc_get_counter_val() % KANGURU_TRACKS) + 1); // play random techno music track
break;
default:
playing_state = PLAYING_STATE_OFF; // we won't play anything else
break;
@ -809,6 +828,7 @@ void main(void)
sleep_ms(100); // wait a bit to de-noise before we check the door lock state
const bool closed = (0 == gpio_get(GPIO_PORT(DOOR_PIN), GPIO_PIN(DOOR_PIN))); // get door lock state
door_flag = false; // clear flag
const uint32_t door_timestamp = rtc_get_counter_val(); // save when the door has been open/closed
action = true; // action has been performed
if (closed && 0 == timer_door_closed) { // door has been closed
puts("door closed\n");
@ -816,8 +836,21 @@ 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, (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
// depending on the open/close sequence, enter secret mode
if ((door_timestamp - door_timestamps[3]) < (2 * RTC_TICKS_SECOND) && (door_timestamps[3] - door_timestamps[2]) < (2 * RTC_TICKS_SECOND) && (door_timestamps[2] - door_timestamps[1]) < (2 * RTC_TICKS_SECOND) && (door_timestamps[1] - door_timestamps[0]) < (2 * RTC_TICKS_SECOND)) { // sequence detected CLOSED->OPENED->CLOSED->OPEN->CLOSED, each within 2 seconds, then enter secret mode 2
puts("entering secret kanguru mode\n");
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (KANGURU_FOLDER << 8) + (rtc_get_counter_val() % KANGURU_TRACKS) + 1); // play random kanguru sketch track
playing_state = PLAYING_STATE_KANGURU; // remember we are playing kanguru sketches
} else if ((door_timestamp - door_timestamps[3]) < (2 * RTC_TICKS_SECOND) && (door_timestamps[3] - door_timestamps[2]) < (2 * RTC_TICKS_SECOND)) { // sequence detected CLOSED->OPENED->CLOSED, each within 2 seconds, then enter secret mode 1
puts("entering secret techno mode\n");
mp3_command(MP3_CMD_PLAY_FOLDER_FILE, (TECHNO_FOLDER << 8) + (rtc_get_counter_val() % TECHNO_TRACKS) + 1); // play random techno music track
playing_state = PLAYING_STATE_TECHNO; // remember we are playing techno music
} else { // no secret mode sequence detected
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
}
door_timestamps[0] = door_timestamps[2]; // backup previous closed time stamp
door_timestamps[2] = door_timestamp; // backup closed time stamp
} else if (!closed && timer_door_closed) { // door has been opened
puts("door opened\n");
timer_door_closed = 0; // remember door is now open
@ -825,6 +858,8 @@ void main(void)
led_tm1637_off(); // stop showing time
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
door_timestamps[1] = door_timestamps[3]; // backup previous opened time stamp
door_timestamps[3] = door_timestamp; // backup opened time stamp
}
}
if (mp3_rx_flag) { // data from MP3 player received