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
music.cpp
00001 #include "music.h" 00002 00003 //NOTE: 00004 //starting a thread inside of a class is apparently really hard to do in RTOS 00005 //since the function you pass to the thread should be static... 00006 //As a workaround I simply create a static thread_helper method 00007 //that launches the thread on behalf of the calling class. 00008 // 00009 //More info here: https://developer.mbed.org/forum/mbed/topic/4388/ 00010 00011 00012 Music::Music(wave_player &speaker_arg) 00013 { 00014 speaker = &speaker_arg; 00015 } 00016 00017 void Music::playMainMusic() 00018 { 00019 main_music_thread = new Thread(thread_helper, this); 00020 } 00021 00022 void Music::stopMainMusic() 00023 { 00024 main_music_thread->terminate(); 00025 } 00026 00027 void Music::main_music() 00028 { 00029 while(true) 00030 { 00031 FILE *main_music_file = fopen("/sd/titlemusic.wav", "r"); 00032 00033 if(main_music_file == NULL) 00034 { 00035 while(true) 00036 { 00037 //display error somehow. I'm having trouble definring LED 00038 //digital out's here, but that'd be the easiest way to display it 00039 } 00040 } 00041 speaker->play(main_music_file); 00042 fclose(main_music_file); 00043 } 00044 } 00045 00046 void Music::thread_helper(const void *arg) 00047 { 00048 //Cast the argument to a Music instance pointer 00049 Music* instancePtr = (Music*)arg; 00050 00051 //Call the thread method for the Music instance 00052 instancePtr->main_music(); 00053 }
Generated on Fri Jul 22 2022 05:53:26 by 1.7.2