This is the Mexican Standoff prototype made by Francisco Martin and Andrew Smith. Please refer to the following link for instructions on hardware hookup: https://developer.mbed.org/users/fomartin/notebook/mexican-standoff-reaction-game/

Dependencies:   SDFileSystem mbed-rtos mbed wave_player 4DGL-uLCD-SE PinDetect

Committer:
fomartin
Date:
Mon Mar 14 19:14:23 2016 +0000
Revision:
2:3c1a5079243d
Parent:
0:75716bd37804
Fixed bug with player 2 pressing button during X prompt.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
fomartin 0:75716bd37804 1 #include "music.h"
fomartin 0:75716bd37804 2
fomartin 0:75716bd37804 3 //NOTE:
fomartin 0:75716bd37804 4 //starting a thread inside of a class is apparently really hard to do in RTOS
fomartin 0:75716bd37804 5 //since the function you pass to the thread should be static...
fomartin 0:75716bd37804 6 //As a workaround I simply create a static thread_helper method
fomartin 0:75716bd37804 7 //that launches the thread on behalf of the calling class.
fomartin 0:75716bd37804 8 //
fomartin 0:75716bd37804 9 //More info here: https://developer.mbed.org/forum/mbed/topic/4388/
fomartin 0:75716bd37804 10
fomartin 0:75716bd37804 11
fomartin 0:75716bd37804 12 Music::Music(wave_player &speaker_arg)
fomartin 0:75716bd37804 13 {
fomartin 0:75716bd37804 14 speaker = &speaker_arg;
fomartin 0:75716bd37804 15 }
fomartin 0:75716bd37804 16
fomartin 0:75716bd37804 17 void Music::playMainMusic()
fomartin 0:75716bd37804 18 {
fomartin 0:75716bd37804 19 main_music_thread = new Thread(thread_helper, this);
fomartin 0:75716bd37804 20 }
fomartin 0:75716bd37804 21
fomartin 0:75716bd37804 22 void Music::stopMainMusic()
fomartin 0:75716bd37804 23 {
fomartin 0:75716bd37804 24 main_music_thread->terminate();
fomartin 0:75716bd37804 25 }
fomartin 0:75716bd37804 26
fomartin 0:75716bd37804 27 void Music::main_music()
fomartin 0:75716bd37804 28 {
fomartin 0:75716bd37804 29 while(true)
fomartin 0:75716bd37804 30 {
fomartin 0:75716bd37804 31 FILE *main_music_file = fopen("/sd/titlemusic.wav", "r");
fomartin 0:75716bd37804 32
fomartin 0:75716bd37804 33 if(main_music_file == NULL)
fomartin 0:75716bd37804 34 {
fomartin 0:75716bd37804 35 while(true)
fomartin 0:75716bd37804 36 {
fomartin 0:75716bd37804 37 //display error somehow. I'm having trouble definring LED
fomartin 0:75716bd37804 38 //digital out's here, but that'd be the easiest way to display it
fomartin 0:75716bd37804 39 }
fomartin 0:75716bd37804 40 }
fomartin 0:75716bd37804 41 speaker->play(main_music_file);
fomartin 0:75716bd37804 42 fclose(main_music_file);
fomartin 0:75716bd37804 43 }
fomartin 0:75716bd37804 44 }
fomartin 0:75716bd37804 45
fomartin 0:75716bd37804 46 void Music::thread_helper(const void *arg)
fomartin 0:75716bd37804 47 {
fomartin 0:75716bd37804 48 //Cast the argument to a Music instance pointer
fomartin 0:75716bd37804 49 Music* instancePtr = (Music*)arg;
fomartin 0:75716bd37804 50
fomartin 0:75716bd37804 51 //Call the thread method for the Music instance
fomartin 0:75716bd37804 52 instancePtr->main_music();
fomartin 0:75716bd37804 53 }