Microcontroller firmware that uses a simple, yet powerful scripting language to control the timing of input and output events with high temporal resolution. Written by Mattias Karlsson

Dependencies:   SMARTWAV mbed

Revision:
8:872b843a3053
Parent:
7:5fe7329751d4
diff -r 5fe7329751d4 -r 872b843a3053 behave.cpp
--- a/behave.cpp	Tue Feb 07 18:45:25 2017 +0000
+++ b/behave.cpp	Tue Feb 07 19:40:32 2017 +0000
@@ -8,6 +8,7 @@
 using namespace std;
 
 int16_t randomSeedCounter;  //used for seeding random numbers
+VersionInfo vInfo; //Contains the version number
 
 //digitalPort* portVector[NUMPORTS+1]; //a list of pointers to the digital ports
 
@@ -81,6 +82,15 @@
     eraseBuffer();
     broadCastStateChanges = true;
 
+    //Set the version number (major.middle.minor)
+    vInfo.major = 1;
+    vInfo.middle = 1;
+    vInfo.minor = 0;
+
+    vInfo.updateDay = 7;
+    vInfo.updateMonth = 2;
+    vInfo.updateYear = 2017;
+
 
 
 //section for MBED hardware
@@ -186,6 +196,7 @@
     }
 #endif
 
+
     //Get the initial state of all input pins
     for (int i = 0; i < NUMDIGINPORTS; i++) {
 
@@ -609,8 +620,11 @@
 }
 
 void DigitalPort::write(int outVal) {
-     if (portDir == out) {
+
+    if (portDir == out) {
+
         if (outVal == -1) {
+            //'flip' command means to flip to the other state
             outVal = 1-state;
         }
         outPin->write(outVal);
@@ -3262,6 +3276,77 @@
                     displayMemoryLeft();
                 }
 
+            } else if (tokens[i].compare("version") == 0) {
+                if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) {
+                    textDisplay << "Error: expected a 'do' statement\r\n";
+                    lineError = true;
+                }
+                if ((!lineError) && (blockDepth > 0)) {
+                    textDisplay << "Error: version statement is not allowed inside a block.\r\n";
+                    lineError = true;
+                }
+                if (!lineError) {
+                    textDisplay << "StateScript firmware version " <<  vInfo.major << "." <<  vInfo.middle << "." <<  vInfo.minor << "\r\n";
+                    textDisplay << vInfo.updateMonth << "." << vInfo.updateDay << "." << vInfo.updateYear << "\r\n";
+                }
+
+            } else if (tokens[i].find("maxanalog(") != std::string::npos) {
+                if (ifBlockInit || whileBlockInit || elseFlag || expectingDoStatement) {
+                    textDisplay << "Error: expected a 'do' statement\r\n";
+                    lineError = true;
+                }
+                if ((!lineError) && (blockDepth > 0)) {
+                    textDisplay << "Error: maxanalog statement is not allowed inside a block.\r\n";
+                    lineError = true;
+                }
+                if (!lineError) {
+                    wholeLineEvaluated = true;
+                    int pos1 = tmpLine.find("maxanalog(")+10;
+                    int pos2 = tmpLine.find_first_of(")",pos1);
+                    if (pos2 == std::string::npos) {
+                        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;
+                        if (tmpVar == NULL) {
+                            if (isNumber(dispVar)) {
+                                isText = true;
+                            } else {
+                                textDisplay << "Error: variable input to maxanalog() does not exist\r\n";
+                                lineError = true;
+                            }
+                        }
+
+
+
+                        if (isText) {
+                            int newVal = atoi(dispVar.data());
+                            if ((newVal > 0)) {
+                                system->setMaxAnalogOut(newVal);
+
+                            } else {
+                                textDisplay << "Error: max analog value must be greater than 0 .\r\n";
+                                lineError = true;
+                            }
+                        } else {
+                            int newVal = *tmpVar;
+                            if ((newVal > 0)) {
+                                system->setMaxAnalogOut(newVal);
+
+                            } else {
+                                textDisplay << "Error: max analog value must be greater than 0 .\r\n";
+                                lineError = true;
+                            }
+                        }
+
+
+                    }
+                }
+
 
             //clear is used to clear things from memory---------------------------------
             //examples: clear all; clear callbacks; clear queue