Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SoftSerial SDFileSystem mbed wave_player
Revision 29:c2d95d88ee0b, committed 2017-05-17
- Comitter:
- Desertification
- Date:
- Wed May 17 09:43:38 2017 +0000
- Parent:
- 28:0ed7ea895f75
- Commit message:
- DONE (for now)
Changed in this revision
--- a/Client.cpp Wed May 17 00:24:13 2017 +0000 +++ b/Client.cpp Wed May 17 09:43:38 2017 +0000 @@ -5,13 +5,14 @@ #include "Client.h" Client::Client(PinName rx_luart, int baudrate_luart) : - aout(p18), fileSystem(p5, p6, p7, p8, "sd"), player(&aout), softSerial(NC, rx_luart), - spi_amp(p11, p12, p13, p14) { + aout(p18), dout(p14), fileSystem(p5, p6, p7, p8, "sd"), player(&aout), softSerial(NC, rx_luart), + spi_amp(p11, p12, p13, NC) { softSerial.baud(baudrate_luart); spi_amp.format(8, 0); + dout = 1; spi_amp.frequency(1000000); fileSystem.disk_initialize(); - wave_file = fopen("/sd/receive.wav", "w+"); + wave_file = fopen("/sd/receive.wav", "r+"); if (wave_file == NULL) { error("Could not open file for w+\n"); } @@ -29,9 +30,11 @@ void Client::set_volume() { while (!softSerial.readable()); int value = softSerial.getc(); - + dout = 0; + wait(0.001); spi_amp.write(0); - spi_amp.write(int((value / 100.0) * 255.0)); + spi_amp.write(value); + dout = 1; printf("volume set to %i\r\n", value); } @@ -52,12 +55,15 @@ case SEND_FILE: send_file(); break; + case PLAY_LAST: + play_file(); default: break; } } void Client::send_file() { + freopen("/sd/receive.wav", "w+", wave_file); printf("starting file write\r\n"); // get file size int size = 0; @@ -75,7 +81,7 @@ // get max 64 bytes int k = 0; - for (k; k < 64; ++k) { + for (k; k < 512; ++k) { if (j == size) { break; } @@ -87,7 +93,8 @@ // store max 64 bytes fwrite(buffer, sizeof(char), (size_t) k, wave_file); - //printf("wrote %i:%i bytes\r\n",k,j); + fflush(wave_file); + printf("wrote %i:%i bytes\r\n",k,j); } play_file();
--- a/Client.h Wed May 17 00:24:13 2017 +0000 +++ b/Client.h Wed May 17 09:43:38 2017 +0000 @@ -21,13 +21,15 @@ MySoftSerial softSerial; SDFileSystem fileSystem; AnalogOut aout; + DigitalOut dout; wave_player player; FILE *wave_file; static const int SEND_FILE = 0b00001111; static const int SET_VOLUME = 0b00110011; static const int ACK = 0b11111111; - char buffer[64]; + static const int PLAY_LAST = 0b10001011; + char buffer[512]; void set_volume();
--- a/Relay.cpp Wed May 17 00:24:13 2017 +0000 +++ b/Relay.cpp Wed May 17 09:43:38 2017 +0000 @@ -16,6 +16,10 @@ } } +void Relay::play_last(){ + +} + void Relay::set_volume(){ while (!usb.readable()); int volume = usb.getc(); @@ -35,6 +39,8 @@ int b = usb.getc(); while(!softSerial.writeable()); softSerial.putc(b); + while (!usb.writeable()); + usb.putc(ACK); size |= b << ((3-i) << 3); } @@ -44,7 +50,7 @@ // get max 64 bytes int k = 0; - for (k; k < 64; ++k) { + for (k; k < 512; ++k) { if(j == size){ break; }
--- a/Relay.h Wed May 17 00:24:13 2017 +0000 +++ b/Relay.h Wed May 17 09:43:38 2017 +0000 @@ -20,14 +20,17 @@ static const int SEND_FILE = 0b00001111; static const int SET_VOLUME = 0b00110011; + static const int PLAY_LAST = 0b10001011; static const int ACK = 0b11111111; - int buffer[64]; + int buffer[512]; void handle_type(); void set_volume(); void send_file(); + + void play_last(); };