Karpova Lab fork of smartWAV library

Fork of SMARTWAV by Mattias Karlsson

Committer:
mkarlsso
Date:
Tue May 19 15:43:42 2015 +0000
Revision:
1:bfb321f3d233
Parent:
0:d3cb5755b201
Child:
2:fa9a64f4935d
Initial commit of reorganized stateScript

Who changed what in which revision?

UserRevisionLine numberNew 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 void SMARTWAV::reset(){ //Reset the SMARTWAV board
emmanuelchio 0:d3cb5755b201 37 _resetPin=0; //set the pin to GND to reset
emmanuelchio 0:d3cb5755b201 38 wait_ms(500);
emmanuelchio 0:d3cb5755b201 39 _resetPin=1; //set the pin to 3.3v to end reset
emmanuelchio 0:d3cb5755b201 40 wait_ms(500);
emmanuelchio 0:d3cb5755b201 41 }
emmanuelchio 0:d3cb5755b201 42
emmanuelchio 0:d3cb5755b201 43 unsigned char SMARTWAV::sleep(){ //Send SMARTWAV to sleep mode / awake from sleep mode
emmanuelchio 0:d3cb5755b201 44 _serialSMARTWAV.putc('Z');
emmanuelchio 0:d3cb5755b201 45 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 46 }
emmanuelchio 0:d3cb5755b201 47
emmanuelchio 0:d3cb5755b201 48 unsigned char SMARTWAV::getStatus(){ //Check active status
emmanuelchio 0:d3cb5755b201 49 unsigned char status;
emmanuelchio 0:d3cb5755b201 50
emmanuelchio 0:d3cb5755b201 51 _serialSMARTWAV.putc('A');
emmanuelchio 0:d3cb5755b201 52 status = _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 53 _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 54 return status;
emmanuelchio 0:d3cb5755b201 55 }
emmanuelchio 0:d3cb5755b201 56
emmanuelchio 0:d3cb5755b201 57 unsigned char SMARTWAV::playTracks(){ //Start playing any song on current Folder/Dir
emmanuelchio 0:d3cb5755b201 58 _serialSMARTWAV.putc('T');
emmanuelchio 0:d3cb5755b201 59 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 60 }
emmanuelchio 0:d3cb5755b201 61
emmanuelchio 0:d3cb5755b201 62 unsigned char SMARTWAV::pausePlay(){ //Pause / play song
emmanuelchio 0:d3cb5755b201 63 _serialSMARTWAV.putc('P');
emmanuelchio 0:d3cb5755b201 64 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 65 }
emmanuelchio 0:d3cb5755b201 66
emmanuelchio 0:d3cb5755b201 67 unsigned char SMARTWAV::rewindTrack(){ //Rewind Track
emmanuelchio 0:d3cb5755b201 68 _serialSMARTWAV.putc('R');
emmanuelchio 0:d3cb5755b201 69 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 70 }
emmanuelchio 0:d3cb5755b201 71
emmanuelchio 0:d3cb5755b201 72 unsigned char SMARTWAV::nextTrack(){ //Next Track
emmanuelchio 0:d3cb5755b201 73 _serialSMARTWAV.putc('N');
emmanuelchio 0:d3cb5755b201 74 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 75 }
emmanuelchio 0:d3cb5755b201 76
emmanuelchio 0:d3cb5755b201 77 unsigned char SMARTWAV::playTrackName(char name[]){ //play an Audio file contained on the micro SD card with the given name.
emmanuelchio 0:d3cb5755b201 78 unsigned char counter=0;
emmanuelchio 0:d3cb5755b201 79
mkarlsso 1:bfb321f3d233 80 //if (_serialSMARTWAV.writeable()) {
emmanuelchio 0:d3cb5755b201 81 _serialSMARTWAV.putc('F');
mkarlsso 1:bfb321f3d233 82 //}
emmanuelchio 0:d3cb5755b201 83 while(1){
mkarlsso 1:bfb321f3d233 84 //if (_serialSMARTWAV.writeable()) {
mkarlsso 1:bfb321f3d233 85 _serialSMARTWAV.putc(name[counter]);
mkarlsso 1:bfb321f3d233 86 //} else {
mkarlsso 1:bfb321f3d233 87 // break;
mkarlsso 1:bfb321f3d233 88 //}
emmanuelchio 0:d3cb5755b201 89 if(name[counter]==0x00){
emmanuelchio 0:d3cb5755b201 90 break;
emmanuelchio 0:d3cb5755b201 91 }
emmanuelchio 0:d3cb5755b201 92 counter++;
emmanuelchio 0:d3cb5755b201 93 }
mkarlsso 1:bfb321f3d233 94
emmanuelchio 0:d3cb5755b201 95 return _serialSMARTWAV.getc();
mkarlsso 1:bfb321f3d233 96 //return 1;
emmanuelchio 0:d3cb5755b201 97 }
emmanuelchio 0:d3cb5755b201 98
emmanuelchio 0:d3cb5755b201 99 unsigned char SMARTWAV::stopTrack(){ //Stop playing any active song
mkarlsso 1:bfb321f3d233 100
mkarlsso 1:bfb321f3d233 101 //if (_serialSMARTWAV.writeable()) {
emmanuelchio 0:d3cb5755b201 102 _serialSMARTWAV.putc('S');
mkarlsso 1:bfb321f3d233 103 //}
emmanuelchio 0:d3cb5755b201 104 return _serialSMARTWAV.getc();
mkarlsso 1:bfb321f3d233 105 //return 1;
emmanuelchio 0:d3cb5755b201 106 }
emmanuelchio 0:d3cb5755b201 107
emmanuelchio 0:d3cb5755b201 108 unsigned char SMARTWAV::continuousPlay(unsigned char enable){ //Enable/Disable continuous play, also disabled by calling stopTrack()
emmanuelchio 0:d3cb5755b201 109 unsigned char status;
emmanuelchio 0:d3cb5755b201 110
emmanuelchio 0:d3cb5755b201 111 _serialSMARTWAV.putc('C');
emmanuelchio 0:d3cb5755b201 112 _serialSMARTWAV.putc(enable);
emmanuelchio 0:d3cb5755b201 113 status = _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 114 _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 115 return status;
emmanuelchio 0:d3cb5755b201 116 }
emmanuelchio 0:d3cb5755b201 117
emmanuelchio 0:d3cb5755b201 118 unsigned char SMARTWAV::volume(unsigned char vol){ //Set Volume 0-255
emmanuelchio 0:d3cb5755b201 119 _serialSMARTWAV.putc('V');
emmanuelchio 0:d3cb5755b201 120 _serialSMARTWAV.putc(vol);
mkarlsso 1:bfb321f3d233 121 //return _serialSMARTWAV.getc();
mkarlsso 1:bfb321f3d233 122 return 1;
emmanuelchio 0:d3cb5755b201 123 }
emmanuelchio 0:d3cb5755b201 124
emmanuelchio 0:d3cb5755b201 125 unsigned char SMARTWAV::setFolder(char name[]){ //Set/Enters inside a folder/path on the micro SD card with the given name.
emmanuelchio 0:d3cb5755b201 126 unsigned char counter=0;
emmanuelchio 0:d3cb5755b201 127
emmanuelchio 0:d3cb5755b201 128 _serialSMARTWAV.putc('D');
emmanuelchio 0:d3cb5755b201 129 while(1){
emmanuelchio 0:d3cb5755b201 130 _serialSMARTWAV.putc(name[counter]);
emmanuelchio 0:d3cb5755b201 131 if(name[counter]==0x00){
emmanuelchio 0:d3cb5755b201 132 break;
emmanuelchio 0:d3cb5755b201 133 }
emmanuelchio 0:d3cb5755b201 134 counter++;
emmanuelchio 0:d3cb5755b201 135 }
emmanuelchio 0:d3cb5755b201 136 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 137 }
emmanuelchio 0:d3cb5755b201 138
emmanuelchio 0:d3cb5755b201 139 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.
emmanuelchio 0:d3cb5755b201 140 unsigned int i=0;
emmanuelchio 0:d3cb5755b201 141
emmanuelchio 0:d3cb5755b201 142 _serialSMARTWAV.putc('I');
emmanuelchio 0:d3cb5755b201 143 _serialSMARTWAV.putc('S');
emmanuelchio 0:d3cb5755b201 144 //receive all the file name
emmanuelchio 0:d3cb5755b201 145 while(1){
emmanuelchio 0:d3cb5755b201 146 name[i]=_serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 147 if(name[i]==0x00){
emmanuelchio 0:d3cb5755b201 148 break;
emmanuelchio 0:d3cb5755b201 149 }
emmanuelchio 0:d3cb5755b201 150 i++;
emmanuelchio 0:d3cb5755b201 151 }
emmanuelchio 0:d3cb5755b201 152 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 153 }
emmanuelchio 0:d3cb5755b201 154
emmanuelchio 0:d3cb5755b201 155 unsigned char SMARTWAV::getFolderName(char name[]){ //Reads the name of the current folderDir/path name the SMARTWAV, and stores it on the name[] buffer.
emmanuelchio 0:d3cb5755b201 156 unsigned int i=0;
emmanuelchio 0:d3cb5755b201 157
emmanuelchio 0:d3cb5755b201 158 _serialSMARTWAV.putc('I');
emmanuelchio 0:d3cb5755b201 159 _serialSMARTWAV.putc('D');
emmanuelchio 0:d3cb5755b201 160 //receive all the folder/path name
emmanuelchio 0:d3cb5755b201 161 while(1){
emmanuelchio 0:d3cb5755b201 162 name[i]=_serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 163 if(name[i]==0x00){
emmanuelchio 0:d3cb5755b201 164 break;
emmanuelchio 0:d3cb5755b201 165 }
emmanuelchio 0:d3cb5755b201 166 i++;
emmanuelchio 0:d3cb5755b201 167 }
emmanuelchio 0:d3cb5755b201 168 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 169 }
emmanuelchio 0:d3cb5755b201 170
emmanuelchio 0:d3cb5755b201 171 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 ','.
emmanuelchio 0:d3cb5755b201 172 unsigned int i=0;
emmanuelchio 0:d3cb5755b201 173
emmanuelchio 0:d3cb5755b201 174 _serialSMARTWAV.putc('I');
emmanuelchio 0:d3cb5755b201 175 _serialSMARTWAV.putc('L');
emmanuelchio 0:d3cb5755b201 176 //receive all the file names
emmanuelchio 0:d3cb5755b201 177 while(1){
emmanuelchio 0:d3cb5755b201 178 list[i]=_serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 179 if(list[i]==0x00){
emmanuelchio 0:d3cb5755b201 180 break;
emmanuelchio 0:d3cb5755b201 181 }
emmanuelchio 0:d3cb5755b201 182 i++;
emmanuelchio 0:d3cb5755b201 183 }
emmanuelchio 0:d3cb5755b201 184 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 185 }
emmanuelchio 0:d3cb5755b201 186
emmanuelchio 0:d3cb5755b201 187 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 ','.
emmanuelchio 0:d3cb5755b201 188 unsigned int i=0;
emmanuelchio 0:d3cb5755b201 189
emmanuelchio 0:d3cb5755b201 190 _serialSMARTWAV.putc('I');
emmanuelchio 0:d3cb5755b201 191 _serialSMARTWAV.putc('X');
emmanuelchio 0:d3cb5755b201 192 //receive all the folder names
emmanuelchio 0:d3cb5755b201 193 while(1){
emmanuelchio 0:d3cb5755b201 194 list[i]=_serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 195 if(list[i]==0x00){
emmanuelchio 0:d3cb5755b201 196 break;
emmanuelchio 0:d3cb5755b201 197 }
emmanuelchio 0:d3cb5755b201 198 i++;
emmanuelchio 0:d3cb5755b201 199 }
emmanuelchio 0:d3cb5755b201 200 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 201 }
emmanuelchio 0:d3cb5755b201 202
emmanuelchio 0:d3cb5755b201 203 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
emmanuelchio 0:d3cb5755b201 204
emmanuelchio 0:d3cb5755b201 205 _serialSMARTWAV.putc('M');
emmanuelchio 0:d3cb5755b201 206 _serialSMARTWAV.putc(speed);
emmanuelchio 0:d3cb5755b201 207 _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 208 return _serialSMARTWAV.getc();
emmanuelchio 0:d3cb5755b201 209 }
emmanuelchio 0:d3cb5755b201 210