Karpova Lab fork of stateScript

Dependencies:   SMARTWAV SOMO_II mbed

Fork of stateScript_v2_karpova by Andy Lustig

Revision:
9:f15ad8d18881
Parent:
7:42aa1e804047
--- a/behave.cpp	Wed Jan 27 21:31:45 2016 +0000
+++ b/behave.cpp	Thu Jan 28 16:47:32 2016 +0000
@@ -2306,6 +2306,7 @@
                 //sound statement used to play wave files------------------------------------------------
                 //example: sound('soundfile')
                 //         sound(stop)
+                //         sound(s03)
             } else if (tokens[i].find("sound(") != std::string::npos) {
                 if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) {
                     textDisplay << "Error: expected a 'do' statement\r\n";
@@ -2318,17 +2319,19 @@
                     textDisplay << "Syntax error: expected a ')'\r\n";
                     lineError = true;
                 }
-
                 if (!lineError) {
                     string dispVar = tmpLine.substr(pos1,pos2-pos1);
-
                     int* tmpVar = findIntVariable(dispVar);
                     bool isText = false;
                     bool stopSignal = false;
                     bool resetSignal = false;
+                    unsigned char sendTrack = 0;
                     if (tmpVar == NULL) {
                         if ((tmpLine.compare(pos1,1,"'")==0) && (tmpLine.compare(pos2-1,1,"'")==0)) {
                             isText = true;
+//                            textDisplay <<"command= "<<tmpLine.substr(pos1+1,pos2-pos1-2)<<"\r\n";
+                        } else if (tmpLine.compare(pos1,1,"s")==0 && dispVar.length()==3) {
+                            sendTrack = (dispVar[1]-48)*10 + dispVar[2]-48;
                         } else if (dispVar.compare("stop") == 0) {
                             stopSignal = true;
                         } else if (dispVar.compare("reset") == 0) {
@@ -2355,10 +2358,14 @@
                             S->setReset();
                             S->execute();
                             delete S;
+                        } else if (sendTrack>0 && sendTrack<100){ //track number must be 1-99
+                            sSound* S = system->createNewSoundAction();
+//                            textDisplay<<"sent:"<<sendTrack;
+                            S->setFile(sendTrack);
+                            S->execute();
+                            delete S;                            
                         } else if (isText) {
-
                             if (pos2-pos1-2 <= 20) {
-
                                 sSound* S = system->createNewSoundAction();
                                 S->setFile(tmpLine.substr(pos1+1,pos2-pos1-2));
                                 S->execute();
@@ -2381,14 +2388,18 @@
                             //action* tmpAction = new action(sPtr);
                             tmpAction->set(sPtr);
                             tmpEventPtrArray.back()->addAction(tmpAction);
-                        } else if (resetSignal) {
+                        }else if (resetSignal) {
                             sSound* sPtr = system->createNewSoundAction();
                             sPtr->setReset();
                             //action* tmpAction = new action(sPtr);
                             tmpAction->set(sPtr);
                             tmpEventPtrArray.back()->addAction(tmpAction);
-                        } else if (isText) {
-
+                        }else if (sendTrack>0 && sendTrack<100){
+                            sSound* sPtr = system->createNewSoundAction();
+                            sPtr->setFile(sendTrack);
+                            tmpAction->set(sPtr);
+                            tmpEventPtrArray.back()->addAction(tmpAction);
+                        }else if (isText) {
                             if (pos2-pos1-2 <= 20) {
                                 sSound* sPtr = system->createNewSoundAction();
                                 sPtr->setFile(tmpLine.substr(pos1+1,pos2-pos1-2));
@@ -2403,8 +2414,6 @@
                             textDisplay << "Error: variable input to sound() not yet supported.  Enter a string in single quotes.\r\n";
                             lineError = true;
                         }
-
-
                     }
                 }
 
@@ -2442,13 +2451,14 @@
                         //we are not inside a block structure, so play sound now
                         if (isText) {
                             int newVolume = atoi(dispVar.data());
-                            if ((newVolume >=0)&&(newVolume <= 255)) {
+                            if ((newVolume >=0)&&(newVolume <= 255)) { // for SOMO II it should be between 0 and 30, but I'm not sure how to let this code know whether the SOMO or the smartWAV is being used
                                 sSound* S = system->createNewSoundAction();
+//                                textDisplay << "new vol=" <<newVolume;
                                 S->setVolume(newVolume);
                                 S->execute();
                                 delete S;
                             } else {
-                                textDisplay << "Error: sound volume must be between 0 and 255 .\r\n";
+                                textDisplay << "Error: sound volume must be between 0 and 255 .\r\n"; 
                                 lineError = true;
                             }
                         } else {