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

Files at this revision

API Documentation at this revision

Comitter:
mkarlsso
Date:
Tue Feb 07 19:40:32 2017 +0000
Parent:
7:5fe7329751d4
Commit message:
Added "version command"

Changed in this revision

behave.cpp Show annotated file Show diff for this revision Revisions of this file
behave.h Show annotated file Show diff for this revision Revisions of this file
hardwareInterface.cpp Show annotated file Show diff for this revision Revisions of this file
hardwareInterface.h Show annotated file Show diff for this revision Revisions of this file
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
diff -r 5fe7329751d4 -r 872b843a3053 behave.h
--- a/behave.h	Tue Feb 07 18:45:25 2017 +0000
+++ b/behave.h	Tue Feb 07 19:40:32 2017 +0000
@@ -56,6 +56,16 @@
     bool triggered;
 };*/
 
+struct VersionInfo {
+    int major;
+    int middle;
+    int minor;
+
+    int updateDay;
+    int updateMonth;
+    int updateYear;
+};
+
 class AbstractPort {
 
 public:
diff -r 5fe7329751d4 -r 872b843a3053 hardwareInterface.cpp
--- a/hardwareInterface.cpp	Tue Feb 07 18:45:25 2017 +0000
+++ b/hardwareInterface.cpp	Tue Feb 07 19:40:32 2017 +0000
@@ -69,6 +69,10 @@
 
 }
 
+void sSystem::setMaxAnalogOut(int value) {
+
+}
+
 void sSystem::resumeInterrupts() {
 
 }
diff -r 5fe7329751d4 -r 872b843a3053 hardwareInterface.h
--- a/hardwareInterface.h	Tue Feb 07 18:45:25 2017 +0000
+++ b/hardwareInterface.h	Tue Feb 07 19:40:32 2017 +0000
@@ -138,6 +138,7 @@
     virtual void pauseInterrupts();
     virtual void resumeInterrupts();
     virtual void reset();
+    virtual void setMaxAnalogOut(int value);
     virtual int getPendingFunctionTriggers(uint16_t *bufferPtr); //Returns the number of pending shortcut triggers
     virtual uint32_t getDigitalOutputChangeFlags();
     virtual uint32_t getDigitalInputChangeFlags();