Karpova Lab fork of smartWAV library
Fork of SMARTWAV by
SMARTWAV.cpp@2:fa9a64f4935d, 2016-01-28 (annotated)
- Committer:
- alustig3
- Date:
- Thu Jan 28 16:37:49 2016 +0000
- Revision:
- 2:fa9a64f4935d
- Parent:
- 1:bfb321f3d233
Added playTrackNum function to match SOMO library, therefore making sound modules interchangeable. Commented out all of the functions not being used by stateScript
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
emmanuelchio | 0:d3cb5755b201 | 1 | /********************************************************* |
emmanuelchio | 0:d3cb5755b201 | 2 | VIZIC TECHNOLOGIES. COPYRIGHT 2012. |
emmanuelchio | 0:d3cb5755b201 | 3 | THE DATASHEETS, SOFTWARE AND LIBRARIES ARE PROVIDED "AS IS." |
emmanuelchio | 0:d3cb5755b201 | 4 | VIZIC EXPRESSLY DISCLAIM ANY WARRANTY OF ANY KIND, WHETHER |
emmanuelchio | 0:d3cb5755b201 | 5 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, THE IMPLIED |
emmanuelchio | 0:d3cb5755b201 | 6 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, |
emmanuelchio | 0:d3cb5755b201 | 7 | OR NONINFRINGEMENT. IN NO EVENT SHALL VIZIC BE LIABLE FOR |
emmanuelchio | 0:d3cb5755b201 | 8 | ANY INCIDENTAL, SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, |
emmanuelchio | 0:d3cb5755b201 | 9 | LOST PROFITS OR LOST DATA, HARM TO YOUR EQUIPMENT, COST OF |
emmanuelchio | 0:d3cb5755b201 | 10 | PROCUREMENT OF SUBSTITUTE GOODS, TECHNOLOGY OR SERVICES, |
emmanuelchio | 0:d3cb5755b201 | 11 | ANY CLAIMS BY THIRD PARTIES (INCLUDING BUT NOT LIMITED TO |
emmanuelchio | 0:d3cb5755b201 | 12 | ANY DEFENCE THEREOF), ANY CLAIMS FOR INDEMNITY OR CONTRIBUTION, |
emmanuelchio | 0:d3cb5755b201 | 13 | OR OTHER SIMILAR COSTS. |
emmanuelchio | 0:d3cb5755b201 | 14 | *********************************************************/ |
emmanuelchio | 0:d3cb5755b201 | 15 | |
emmanuelchio | 0:d3cb5755b201 | 16 | /******************************************************** |
emmanuelchio | 0:d3cb5755b201 | 17 | IMPORTANT : This library is created for the mbed Microcontroller Software IDE |
emmanuelchio | 0:d3cb5755b201 | 18 | ********************************************************/ |
emmanuelchio | 0:d3cb5755b201 | 19 | |
emmanuelchio | 0:d3cb5755b201 | 20 | |
emmanuelchio | 0:d3cb5755b201 | 21 | #include "mbed.h" |
emmanuelchio | 0:d3cb5755b201 | 22 | #include "SMARTWAV.h" |
emmanuelchio | 0:d3cb5755b201 | 23 | |
emmanuelchio | 0:d3cb5755b201 | 24 | // SMART WAV DEFAULT BAUD RATE: 9600bps |
emmanuelchio | 0:d3cb5755b201 | 25 | //It shoud be used like this : SMARTWAV audio(p13,p14,p15); for serial communication with SMARTWAV |
emmanuelchio | 0:d3cb5755b201 | 26 | SMARTWAV::SMARTWAV(PinName TXPin, PinName RXPin, PinName resetPin): _serialSMARTWAV(TXPin,RXPin), _resetPin(resetPin){ |
emmanuelchio | 0:d3cb5755b201 | 27 | init(); |
emmanuelchio | 0:d3cb5755b201 | 28 | } |
emmanuelchio | 0:d3cb5755b201 | 29 | |
emmanuelchio | 0:d3cb5755b201 | 30 | /********** high level commands, for the user! */ |
emmanuelchio | 0:d3cb5755b201 | 31 | void SMARTWAV::init(){ //configure the mbed for SMARTWAV board |
emmanuelchio | 0:d3cb5755b201 | 32 | _serialSMARTWAV.baud(9600); |
emmanuelchio | 0:d3cb5755b201 | 33 | _resetPin=1; //set the pin to 3.3v to avoid reset |
emmanuelchio | 0:d3cb5755b201 | 34 | } |
emmanuelchio | 0:d3cb5755b201 | 35 | |
emmanuelchio | 0:d3cb5755b201 | 36 | unsigned char SMARTWAV::playTrackName(char name[]){ //play an Audio file contained on the micro SD card with the given name. |
alustig3 | 2:fa9a64f4935d | 37 | unsigned char counter=0; |
mkarlsso | 1:bfb321f3d233 | 38 | //if (_serialSMARTWAV.writeable()) { |
emmanuelchio | 0:d3cb5755b201 | 39 | _serialSMARTWAV.putc('F'); |
mkarlsso | 1:bfb321f3d233 | 40 | //} |
emmanuelchio | 0:d3cb5755b201 | 41 | while(1){ |
mkarlsso | 1:bfb321f3d233 | 42 | //if (_serialSMARTWAV.writeable()) { |
mkarlsso | 1:bfb321f3d233 | 43 | _serialSMARTWAV.putc(name[counter]); |
mkarlsso | 1:bfb321f3d233 | 44 | //} else { |
mkarlsso | 1:bfb321f3d233 | 45 | // break; |
mkarlsso | 1:bfb321f3d233 | 46 | //} |
emmanuelchio | 0:d3cb5755b201 | 47 | if(name[counter]==0x00){ |
emmanuelchio | 0:d3cb5755b201 | 48 | break; |
emmanuelchio | 0:d3cb5755b201 | 49 | } |
emmanuelchio | 0:d3cb5755b201 | 50 | counter++; |
alustig3 | 2:fa9a64f4935d | 51 | } |
emmanuelchio | 0:d3cb5755b201 | 52 | return _serialSMARTWAV.getc(); |
mkarlsso | 1:bfb321f3d233 | 53 | //return 1; |
emmanuelchio | 0:d3cb5755b201 | 54 | } |
emmanuelchio | 0:d3cb5755b201 | 55 | |
alustig3 | 2:fa9a64f4935d | 56 | void SMARTWAV::playTrackNum(unsigned char trackNum){ //added so SOMO and smartWAV have same functions and can therefore be used interchangeably |
alustig3 | 2:fa9a64f4935d | 57 | } |
alustig3 | 2:fa9a64f4935d | 58 | |
emmanuelchio | 0:d3cb5755b201 | 59 | unsigned char SMARTWAV::stopTrack(){ //Stop playing any active song |
mkarlsso | 1:bfb321f3d233 | 60 | //if (_serialSMARTWAV.writeable()) { |
emmanuelchio | 0:d3cb5755b201 | 61 | _serialSMARTWAV.putc('S'); |
mkarlsso | 1:bfb321f3d233 | 62 | //} |
emmanuelchio | 0:d3cb5755b201 | 63 | return _serialSMARTWAV.getc(); |
mkarlsso | 1:bfb321f3d233 | 64 | //return 1; |
emmanuelchio | 0:d3cb5755b201 | 65 | } |
emmanuelchio | 0:d3cb5755b201 | 66 | |
emmanuelchio | 0:d3cb5755b201 | 67 | unsigned char SMARTWAV::volume(unsigned char vol){ //Set Volume 0-255 |
emmanuelchio | 0:d3cb5755b201 | 68 | _serialSMARTWAV.putc('V'); |
emmanuelchio | 0:d3cb5755b201 | 69 | _serialSMARTWAV.putc(vol); |
mkarlsso | 1:bfb321f3d233 | 70 | //return _serialSMARTWAV.getc(); |
mkarlsso | 1:bfb321f3d233 | 71 | return 1; |
emmanuelchio | 0:d3cb5755b201 | 72 | } |
emmanuelchio | 0:d3cb5755b201 | 73 | |
alustig3 | 2:fa9a64f4935d | 74 | void SMARTWAV::reset(){ //Reset the SMARTWAV board |
alustig3 | 2:fa9a64f4935d | 75 | _resetPin=0; //set the pin to GND to reset |
alustig3 | 2:fa9a64f4935d | 76 | wait_ms(500); |
alustig3 | 2:fa9a64f4935d | 77 | _resetPin=1; //set the pin to 3.3v to end reset |
alustig3 | 2:fa9a64f4935d | 78 | wait_ms(500); |
emmanuelchio | 0:d3cb5755b201 | 79 | } |
emmanuelchio | 0:d3cb5755b201 | 80 | |
emmanuelchio | 0:d3cb5755b201 | 81 | |
alustig3 | 2:fa9a64f4935d | 82 | ////------------------------Below Functions aren't used in stateScript-----------------------------------------// |
alustig3 | 2:fa9a64f4935d | 83 | //unsigned char SMARTWAV::sleep(){ //Send SMARTWAV to sleep mode / awake from sleep mode |
alustig3 | 2:fa9a64f4935d | 84 | // _serialSMARTWAV.putc('Z'); |
alustig3 | 2:fa9a64f4935d | 85 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 86 | //} |
alustig3 | 2:fa9a64f4935d | 87 | // |
alustig3 | 2:fa9a64f4935d | 88 | //unsigned char SMARTWAV::getStatus(){ //Check active status |
alustig3 | 2:fa9a64f4935d | 89 | // unsigned char status; |
alustig3 | 2:fa9a64f4935d | 90 | // |
alustig3 | 2:fa9a64f4935d | 91 | // _serialSMARTWAV.putc('A'); |
alustig3 | 2:fa9a64f4935d | 92 | // status = _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 93 | // _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 94 | // return status; |
alustig3 | 2:fa9a64f4935d | 95 | //} |
alustig3 | 2:fa9a64f4935d | 96 | // |
alustig3 | 2:fa9a64f4935d | 97 | //unsigned char SMARTWAV::playTracks(){ //Start playing any song on current Folder/Dir |
alustig3 | 2:fa9a64f4935d | 98 | // _serialSMARTWAV.putc('T'); |
alustig3 | 2:fa9a64f4935d | 99 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 100 | //} |
alustig3 | 2:fa9a64f4935d | 101 | // |
alustig3 | 2:fa9a64f4935d | 102 | //unsigned char SMARTWAV::pausePlay(){ //Pause / play song |
alustig3 | 2:fa9a64f4935d | 103 | // _serialSMARTWAV.putc('P'); |
alustig3 | 2:fa9a64f4935d | 104 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 105 | //} |
alustig3 | 2:fa9a64f4935d | 106 | // |
alustig3 | 2:fa9a64f4935d | 107 | //unsigned char SMARTWAV::rewindTrack(){ //Rewind Track |
alustig3 | 2:fa9a64f4935d | 108 | // _serialSMARTWAV.putc('R'); |
alustig3 | 2:fa9a64f4935d | 109 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 110 | //} |
alustig3 | 2:fa9a64f4935d | 111 | // |
alustig3 | 2:fa9a64f4935d | 112 | //unsigned char SMARTWAV::nextTrack(){ //Next Track |
alustig3 | 2:fa9a64f4935d | 113 | // _serialSMARTWAV.putc('N'); |
alustig3 | 2:fa9a64f4935d | 114 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 115 | //} |
alustig3 | 2:fa9a64f4935d | 116 | // |
alustig3 | 2:fa9a64f4935d | 117 | //unsigned char SMARTWAV::continuousPlay(unsigned char enable){ //Enable/Disable continuous play, also disabled by calling stopTrack() |
alustig3 | 2:fa9a64f4935d | 118 | // unsigned char status; |
alustig3 | 2:fa9a64f4935d | 119 | // |
alustig3 | 2:fa9a64f4935d | 120 | // _serialSMARTWAV.putc('C'); |
alustig3 | 2:fa9a64f4935d | 121 | // _serialSMARTWAV.putc(enable); |
alustig3 | 2:fa9a64f4935d | 122 | // status = _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 123 | // _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 124 | // return status; |
alustig3 | 2:fa9a64f4935d | 125 | //} |
alustig3 | 2:fa9a64f4935d | 126 | // |
alustig3 | 2:fa9a64f4935d | 127 | // |
alustig3 | 2:fa9a64f4935d | 128 | // |
alustig3 | 2:fa9a64f4935d | 129 | //unsigned char SMARTWAV::setFolder(char name[]){ //Set/Enters inside a folder/path on the micro SD card with the given name. |
alustig3 | 2:fa9a64f4935d | 130 | // unsigned char counter=0; |
alustig3 | 2:fa9a64f4935d | 131 | // |
alustig3 | 2:fa9a64f4935d | 132 | // _serialSMARTWAV.putc('D'); |
alustig3 | 2:fa9a64f4935d | 133 | // while(1){ |
alustig3 | 2:fa9a64f4935d | 134 | // _serialSMARTWAV.putc(name[counter]); |
alustig3 | 2:fa9a64f4935d | 135 | // if(name[counter]==0x00){ |
alustig3 | 2:fa9a64f4935d | 136 | // break; |
alustig3 | 2:fa9a64f4935d | 137 | // } |
alustig3 | 2:fa9a64f4935d | 138 | // counter++; |
alustig3 | 2:fa9a64f4935d | 139 | // } |
alustig3 | 2:fa9a64f4935d | 140 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 141 | //} |
alustig3 | 2:fa9a64f4935d | 142 | // |
alustig3 | 2:fa9a64f4935d | 143 | //unsigned char SMARTWAV::getFileName(char name[]){ //Reads the name of the current/ last audio file being played on the SMARTWAV, and stores it on the name[] buffer. |
alustig3 | 2:fa9a64f4935d | 144 | // unsigned int i=0; |
alustig3 | 2:fa9a64f4935d | 145 | // |
alustig3 | 2:fa9a64f4935d | 146 | // _serialSMARTWAV.putc('I'); |
alustig3 | 2:fa9a64f4935d | 147 | // _serialSMARTWAV.putc('S'); |
alustig3 | 2:fa9a64f4935d | 148 | // //receive all the file name |
alustig3 | 2:fa9a64f4935d | 149 | // while(1){ |
alustig3 | 2:fa9a64f4935d | 150 | // name[i]=_serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 151 | // if(name[i]==0x00){ |
alustig3 | 2:fa9a64f4935d | 152 | // break; |
alustig3 | 2:fa9a64f4935d | 153 | // } |
alustig3 | 2:fa9a64f4935d | 154 | // i++; |
alustig3 | 2:fa9a64f4935d | 155 | // } |
alustig3 | 2:fa9a64f4935d | 156 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 157 | //} |
alustig3 | 2:fa9a64f4935d | 158 | // |
alustig3 | 2:fa9a64f4935d | 159 | //unsigned char SMARTWAV::getFolderName(char name[]){ //Reads the name of the current folderDir/path name the SMARTWAV, and stores it on the name[] buffer. |
alustig3 | 2:fa9a64f4935d | 160 | // unsigned int i=0; |
alustig3 | 2:fa9a64f4935d | 161 | // |
alustig3 | 2:fa9a64f4935d | 162 | // _serialSMARTWAV.putc('I'); |
alustig3 | 2:fa9a64f4935d | 163 | // _serialSMARTWAV.putc('D'); |
alustig3 | 2:fa9a64f4935d | 164 | // //receive all the folder/path name |
alustig3 | 2:fa9a64f4935d | 165 | // while(1){ |
alustig3 | 2:fa9a64f4935d | 166 | // name[i]=_serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 167 | // if(name[i]==0x00){ |
alustig3 | 2:fa9a64f4935d | 168 | // break; |
alustig3 | 2:fa9a64f4935d | 169 | // } |
alustig3 | 2:fa9a64f4935d | 170 | // i++; |
alustig3 | 2:fa9a64f4935d | 171 | // } |
alustig3 | 2:fa9a64f4935d | 172 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 173 | //} |
alustig3 | 2:fa9a64f4935d | 174 | // |
alustig3 | 2:fa9a64f4935d | 175 | //unsigned char SMARTWAV::getFileList(char list[]){ //Reads all the names of the .WAV files on the current folder/dir on the SMARTWAV, and stores it on the list[] buffer separated by comma ','. |
alustig3 | 2:fa9a64f4935d | 176 | // unsigned int i=0; |
alustig3 | 2:fa9a64f4935d | 177 | // |
alustig3 | 2:fa9a64f4935d | 178 | // _serialSMARTWAV.putc('I'); |
alustig3 | 2:fa9a64f4935d | 179 | // _serialSMARTWAV.putc('L'); |
alustig3 | 2:fa9a64f4935d | 180 | // //receive all the file names |
alustig3 | 2:fa9a64f4935d | 181 | // while(1){ |
alustig3 | 2:fa9a64f4935d | 182 | // list[i]=_serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 183 | // if(list[i]==0x00){ |
alustig3 | 2:fa9a64f4935d | 184 | // break; |
alustig3 | 2:fa9a64f4935d | 185 | // } |
alustig3 | 2:fa9a64f4935d | 186 | // i++; |
alustig3 | 2:fa9a64f4935d | 187 | // } |
alustig3 | 2:fa9a64f4935d | 188 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 189 | //} |
alustig3 | 2:fa9a64f4935d | 190 | // |
alustig3 | 2:fa9a64f4935d | 191 | //unsigned char SMARTWAV::getFolderList(char list[]){ //Reads all the folders on the current folder/dir on the SMARTWAV, and stores it on the list[] buffer separated by comma ','. |
alustig3 | 2:fa9a64f4935d | 192 | // unsigned int i=0; |
alustig3 | 2:fa9a64f4935d | 193 | // |
alustig3 | 2:fa9a64f4935d | 194 | // _serialSMARTWAV.putc('I'); |
alustig3 | 2:fa9a64f4935d | 195 | // _serialSMARTWAV.putc('X'); |
alustig3 | 2:fa9a64f4935d | 196 | // //receive all the folder names |
alustig3 | 2:fa9a64f4935d | 197 | // while(1){ |
alustig3 | 2:fa9a64f4935d | 198 | // list[i]=_serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 199 | // if(list[i]==0x00){ |
alustig3 | 2:fa9a64f4935d | 200 | // break; |
alustig3 | 2:fa9a64f4935d | 201 | // } |
alustig3 | 2:fa9a64f4935d | 202 | // i++; |
alustig3 | 2:fa9a64f4935d | 203 | // } |
alustig3 | 2:fa9a64f4935d | 204 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 205 | //} |
alustig3 | 2:fa9a64f4935d | 206 | // |
alustig3 | 2:fa9a64f4935d | 207 | //unsigned char SMARTWAV::playSpeed(unsigned char speed){ //Change current Play Speed: X0.5, X1, X1.5, X2, if track ends, play speed returns to 1.0X |
alustig3 | 2:fa9a64f4935d | 208 | // |
alustig3 | 2:fa9a64f4935d | 209 | // _serialSMARTWAV.putc('M'); |
alustig3 | 2:fa9a64f4935d | 210 | // _serialSMARTWAV.putc(speed); |
alustig3 | 2:fa9a64f4935d | 211 | // _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 212 | // return _serialSMARTWAV.getc(); |
alustig3 | 2:fa9a64f4935d | 213 | //} |
emmanuelchio | 0:d3cb5755b201 | 214 |