Part 2 of our ECE 4180 Final Project
Dependencies: 4DGL-uLCD-SE MODSERIAL USBHost wave_player
Revision 0:25c861ee0c38, committed 2015-05-01
- Comitter:
- mohit1234
- Date:
- Fri May 01 18:10:34 2015 +0000
- Commit message:
- ;
Changed in this revision
diff -r 000000000000 -r 25c861ee0c38 4DGL-uLCD-SE.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/4DGL-uLCD-SE.lib Fri May 01 18:10:34 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/Mkuchnik3/code/4DGL-uLCD-SE/#a2da7a7c517b
diff -r 000000000000 -r 25c861ee0c38 MODSERIAL.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MODSERIAL.lib Fri May 01 18:10:34 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/AjK/code/MODSERIAL/#ae0408ebdd68
diff -r 000000000000 -r 25c861ee0c38 Speaker.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Speaker.h Fri May 01 18:10:34 2015 +0000 @@ -0,0 +1,19 @@ +#include "mbed.h" +// new class to play a note on Speaker based on PwmOut class +class Speaker +{ +public: + Speaker(PinName pin) : _pin(pin) { +// _pin(pin) means pass pin to the Speaker Constructor + } +// class method to play a note based on PwmOut class + void PlayNote(float frequency, float duration, float volume) { + _pin.period(1.0/frequency); + _pin = volume/2.0; + wait(duration); + _pin = 0.0; + } + +private: + PwmOut _pin; +}; \ No newline at end of file
diff -r 000000000000 -r 25c861ee0c38 USBHost.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USBHost.lib Fri May 01 18:10:34 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/mohit1234/code/USBHost/#8c5913017860
diff -r 000000000000 -r 25c861ee0c38 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri May 01 18:10:34 2015 +0000 @@ -0,0 +1,171 @@ +#include <vector> +#include <string> +#include "mbed.h" +#include "wave_player.h" +#include "Speaker.h" +#include "uLCD_4DGL.h" +#include "USBHostMSD.h" +#include "rtos.h" + +#define MODSERIAL_DEFAULT_RX_BUFFER_SIZE 512 +#define MODSERIAL_DEFAULT_TX_BUFFER_SIZE 1024 + +#include "MODSERIAL.h" + +using namespace std; + +MODSERIAL device(p13,p14); +MODSERIAL pc(USBTX, USBRX); + +AnalogOut DACout(p18); +wave_player waver(&DACout); + +uLCD_4DGL screen1(p28, p27, p11); +uLCD_4DGL screen2(p9, p10, p11); + +Mutex mutex; + +volatile bool playAlarm = false; + +void musicThread(void const*); + +void getDate() +{ + //mutex.lock(); + device.printf("date\n"); + //pc.printf("Requesting date\n"); + //mutex.unlock(); +} + +void getTime() +{ + //mutex.lock(); + device.printf("time\n"); + //pc.printf("Requesting time\n"); + //mutex.unlock(); +} + +void getAlarm() +{ + //mutex.lock(); + device.printf("alarm\n"); + //pc.printf("Requesting Alarm\n"); + //mutex.unlock(); +} + +string date; +string t; +volatile bool playingMusic = false; + +void printDate() +{ + // TODO - IMPLEMENT THIS SHIT +} + +void printTime() +{ + // TODO - IMPLEMENT THIS SHIT +} + +/*void playAlarm() +{ + //if (playingMusic) return; + //Thread music(musicThread, NULL, osPriorityNormal, 1024 * 4); + +}*/ + +void timeThread(void const* args) +{ + //screen1.locate(0,5); + //screen1.color(WHITE); + //screen1.textbackground_color(RED); + //screen1.printf("I AM IN THE THREAD\n"); + + getDate(); + while (!device.readable()); + char buffer[80]; + device.scanf("%s", buffer); + date = string(buffer); + char buffer2[80]; + device.scanf("%s", buffer2); + date += (" " + string(buffer2)); + char buffer3[80]; + device.scanf("%s", buffer3); + date += (" " + string(buffer3)); + + printDate(); + + while (1) { + getTime(); + while (!device.readable()); + char buffert[80]; + device.scanf("%s", buffert); + t = string(buffert); + + printTime(); + + getAlarm(); + while (!device.readable()); + char buffera[20]; + device.scanf("%s", buffera); + if (buffera[0] == '1') { + playAlarm = true; + } + + Thread::wait(6000); + } +} + +void musicThread(void const *args) +{ + if (playingMusic) return; + USBHostMSD msd("usb"); + while (1) { + while (!playAlarm); + + playingMusic = true; + //pc.printf("Playing\n"); + + //pc.printf("USB\n"); + // try to connect a MSD device + while(!msd.connect()) { + Thread::wait(500); + } + //pc.printf("Connected\n"); + FILE * fp = fopen("/usb/sample.wav", "r"); + + if (fp != NULL) { + waver.play(fp); + fclose(fp); + } else { + } + + playAlarm = false; + playingMusic = false; + } +} + + +void setupScreens() +{ + screen1.baudrate(3000000); + screen1.cls(); + screen2.baudrate(3000000); + screen2.cls(); +} + + +int main() +{ + setupScreens(); + + screen1.locate(0,5); + screen1.color(WHITE); + screen1.textbackground_color(RED); + screen1.printf("Song Playing\n"); + + Thread thread(musicThread, NULL, osPriorityNormal, 1024 * 4); + Thread tThread(timeThread); + + while (1); +} \ No newline at end of file
diff -r 000000000000 -r 25c861ee0c38 wave_player.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/wave_player.lib Fri May 01 18:10:34 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/sravet/code/wave_player/#acc3e18e77ad