Test for mike

Dependencies:   mbed DevInterfaces MCP4728 MCP4728setaddr I2Cinterfaces

Revision:
10:bf195171d850
Parent:
9:2d70aa45f16e
Child:
11:4367b8eefa6c
--- a/main.cpp	Fri Mar 22 12:48:52 2019 +0000
+++ b/main.cpp	Mon May 20 17:05:29 2019 +0000
@@ -1,3 +1,4 @@
+
 /** example program for the use of the MCP4728 class and DACInterface.h classes
  *
  *  V 1.0  : tested on the KL05z  but without the MCP4728 connected \
@@ -9,6 +10,7 @@
 
 #include "mbed.h"
 #include <string>
+#include <cstring>
 
 #if   defined (TARGET_KL25Z) || defined (TARGET_KL46Z)
   PinName const SDA = PTE25;
@@ -45,6 +47,7 @@
 
 Serial pc(USBTX, USBRX);
 
+DigitalOut CameraTrig(p29);
 
 //Pins for 4x4 Module
 
@@ -84,26 +87,105 @@
 bool Shut3 = 0;
 bool Shut4 = 0;
 
-
+string pcstr;
+string seqstr;
+Timer t;
 
 
-int DACSetChannel( int chan, MCP4728* dac)
+void trigSH( Shutter SH, int nimg )
+{
+    for(int i = 0; i<nimg; i++)
+    {
+        SH.writeShutters(1,1,1,1);//Turn on Shutters
+        
+        wait_us(92);//Wait for shutter to go high
+        wait_us(120);//Wait to trigger until middle of Shutter Opening
+        
+        CameraTrig = 1;//Trigger Camera to turn on
+        wait_us(38);//Wait for rest of 250 us
+        
+        //wait_us(16417); //DEBUG: Added extra delay to slow down trigger
+        
+        //Turn off shutters and Camera Trigger
+        SH.writeShutters(0,0,0,0);
+        
+        CameraTrig = 0;
+        
+        wait_us(16417); //Wait to run at 60 Hz
+        
+        //wait_us(16417); //DEBUG: Added extra delay to slow down trigger
+    }
+}
+ 
+
+void trigNotEyeSafe( Shutter SH, int nimg )
+{
+    for(int i = 0; i<nimg; i++)
+    {
+        //SH.writeShutters(1,1,1,1);//Turn on Shutters
+        
+        wait_us(92);//Wait for shutter to go high
+        wait_us(120);//Wait to trigger until middle of Shutter Opening
+        
+        CameraTrig = 1;//Trigger Camera to turn on
+        wait_us(38);//Wait for rest of 250 us
+        
+        //wait_us(16417);//DEBUG: Added extra delay to slow down trigger
+        
+        //Turn off shutters and Camera Trigger
+        //SH.writeShutters(0,0,0,0);
+        CameraTrig = 0;
+        
+        wait_us(16417); //Wait to run at 60 Hz
+        
+       // wait_us(16417);//DEBUG: Added extra delay to slow down trigger
+    }
+}
+  
+ 
+
+int DACSetChannel( int chan, MCP4728* dac, int counts)
 {
     int ret = 0;
-    char z;
-    int voltCount = 0;
+    int z = 0;
+    int CHcnt;
+    int voltCount = counts;
     string instr;
 
-    //printf("\n\rEnter Voltage \n\r");
-    while (ret == 0)
+    if(  voltCount > 4095  || voltCount < 0)
+    {             
+        voltCount = 4095;
+    }
+        
+    while(ret == 0 && z < 10)
     {
+        //t.start();
+        dac->update();
+        //t.stop();
+        //t.reset();
+        //pc.printf("DAC update took %f seconds \n\r",t.read());
+        (void)dac->getDACvalue(CHcnt,chan);
         
-        z = pc.getc();
+        if(CHcnt == counts)
+        {
+            ret = 1;
+        }
+        else
+        {
+            //t.start();
+            dac->setDACvalue(voltCount,chan);
+            //t.stop();
+            //pc.printf("DAC setting took %f seconds \n\r",t.read());
+            z++;
+        }    
         
         
+    }   
+    
+    /*
         if( z == 13 )
             {
-                voltCount = atoi( instr.c_str() );
+                voltCount = counts;
                 
                 if(  voltCount > 4095  || voltCount < 0)
                 {
@@ -121,62 +203,217 @@
                         {
                             //printf("\n\rfailed to readback channel info \n\r");
                         }
-                        else 
-                        {
-                                (void)dac->getDACvalue(voltCount,chan);//no need to test done with updat 
-                                //printf(" CH%d %d Counts",chan,voltCount);
-                                //printf("\n\r");
-                    
-                        }
                             
                 }
                 
-                instr.clear();
-                ret = 1;
             }
-        else
-            {
-                ////pc.printf("%c",z);
-                instr.push_back(z);
-            }
-    }
+    */
+    
     return 1;
 }
     
+void set4x4Piping(DigitalOut** Arr_4x4, char z1, char z2, char z3, char z4, char z5)
+{
+            /*
+            //Get 5 1's or 0's for binary number
+            int count = 0;
+            char c;
+            ////pc.printf("4x4 Control: Enter 5 digit binary number\n\r");
+            while ( count < 5 )
+            {
+                c = pc.getc();
+                
+                if( c == '1' || c=='0' )
+                {
+                    *Arr_4x4[count] = atoi(&c);
+                    count++;
+                }
+            }
+            */
+            
+            *Arr_4x4[0] = atoi(&z1);
+            *Arr_4x4[1] = atoi(&z2);
+            *Arr_4x4[2] = atoi(&z3);
+            *Arr_4x4[3] = atoi(&z4);
+            *Arr_4x4[4] = atoi(&z5);
+            
+            for( int k = 0; k<2; k++) //Trigger clocking to change values
+            {
+                m4x4CLK = 1;
+                wait_us(200); 
+                m4x4CLK = 0;
+            }
+            
+            //pc.printf("Optical Path set to : %d%d%d%d%d\n\r", m4x4TTL1.read(), m4x4TTL2.read(), m4x4TTL3.read(), m4x4TTL4.read(), m4x4TTL5.read() ); //Confirm the correct output is set
+}
 
-
+void set4x5Piping(DigitalOut** Arr_4x5, char z1, char z2, char z3, char z4, char z5)
+{
+     /*
+     //Get 5 1's or 0's for binary number
+            int count = 0;
+            char c;
+            ////pc.printf("4x5 Control: Enter 5 digit binary number\n\r");
+            while ( count < 5 )
+            {
+                c = pc.getc();
+                
+                if( c == '1' || c=='0' )
+                {
+                    *Arr_4x5[count] = atoi(&c);
+                    count++;
+                }
+            }
+            */
+            
+            *Arr_4x5[0] = atoi(&z1);
+            *Arr_4x5[1] = atoi(&z2);
+            *Arr_4x5[2] = atoi(&z3);
+            *Arr_4x5[3] = atoi(&z4);
+            *Arr_4x5[4] = atoi(&z5);
+            
+            for( int k = 0; k<2; k++) //Trigger clocking to change values
+            {
+                m4x5CLK = 1;
+                wait_us(200);  
+                m4x5CLK = 0;
+            }
+            
+            //pc.printf("Optical Path set to : %d%d%d%d%d\n\r", m4x5TTL1.read(), m4x5TTL2.read(), m4x5TTL3.read(), m4x5TTL4.read(), m4x5TTL5.read() ); //Confirm the correct output is set
+}
 
 
 
+void toggleShut1(Shutter SH)
+{
+    Shut1 = !Shut1;
+    SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
+}
+
+
+void toggleShut2(Shutter SH)
+{
+    Shut2 = !Shut2;
+    SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
+}
+
+
+void toggleShut3(Shutter SH)
+{
+    Shut3 = !Shut3;
+    SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
+}
+
+
+void toggleShut4(Shutter SH)
+{
+    Shut4 = !Shut4;
+    SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
+}
+
+void closeRef()
+{
+    mRefShutters = 0;
+}
+
+void openRef()
+{
+    mRefShutters = 1;
+}
+
+void openAllHP(Shutter SH)
+{
+    Shut1 = 1;
+    Shut2 = 1;
+    Shut3 = 1;
+    Shut4 = 1;
+    SH.writeShutters(1,1,1,1);
+}
+
+void closeAllHP(Shutter SH)
+{
+    Shut1 = 0;
+    Shut2 = 0;
+    Shut3 = 0;
+    Shut4 = 0;
+    SH.writeShutters(0,0,0,0);
+}
+
+void setAllShutters(Shutter SH,char z1, char z2, char z3, char z4)
+{
+    /*
+    //Writes to all 4x5 shutters a specific state
+            int inarr[4];
+            for(int i=0; i<4; i++)
+            {
+                char z = pc.getc();
+                if( z == '1')
+                {
+                    inarr[i] = 1;
+                }
+                else if( z == '0')
+                {
+                    inarr[i] = 0;
+                }
+                else
+                {
+                    inarr[i] = 0;
+                }
+            }
+            */
+            Shut1 = atoi(&z1);
+            Shut2 = atoi(&z2);
+            Shut3 = atoi(&z3);
+            Shut4 = atoi(&z4);
+            SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
+}
+
+void queryDAC(MCP4728* dac)
+{
+    int CH1cnt;
+    int CH2cnt;
+    int CH3cnt;
+    int CH4cnt;
+    //Print State of DAC
+    if( dac->update() == 0)
+    {
+        (void)dac->getDACvalue(CH1cnt,0);
+        (void)dac->getDACvalue(CH2cnt,1);
+        (void)dac->getDACvalue(CH3cnt,2);
+        (void)dac->getDACvalue(CH4cnt,3);
+        pc.printf("CH1:%4d CH2:%4d CH3:%4d CH4:%4d\n\r",CH1cnt,CH2cnt,CH3cnt,CH4cnt);
+    }
+            
+    else
+    {
+        pc.printf("Error: No readback from DAC\n\r");
+    }
+}
+
+void queryShutters()
+{
+    //Print State of Shutters
+    pc.printf("SH1:%d SH2:%d SH3:%d SH4:%d SHRef:%d\n\r",Shut1,Shut2,Shut3,Shut4,mRefShutters.read());
+}
+
 int main(void) {
   
-   // get the version of getVersion 
-   getVersion gv;
-   int addr;
-
-  addr = 0;
-   MCP4728  dac( i2cdev ,addr, Vdd);  // assuming the address  of the MCP4728 is set to 0 factory default 
-   //printf("\n\raddr %d MCP4728 :%s\n\r",addr,dac.getversioninfo());
-   wait(1);
-
-   int cnt=0;
+    //get the version of getVersion 
+    getVersion gv;
+    int addr;
+    //Timer m;
+    addr = 0;
+    MCP4728  dac( i2cdev ,addr, Vdd);  // assuming the address  of the MCP4728 is set to 0 factory default 
+   
+    wait(1);
 
-   mRefShutters = 1;
-
-
-
-//pc.printf("Agiltron Serial Control Program\n\r");
-//pc.printf("'[' 4x4 Swtiching \n\r");
-//pc.printf("']' 4x5 Swtiching\n\r");
-//pc.printf("1, 2, 3, 4 Toggle Single Shutters\n\r");
-//pc.printf("'o' Opens all Shutters\n\r");
-//pc.printf("'r' Closes all Shutters \n\r");
-//pc.printf("',' 4 Channel DAC Control \n\r");
-//pc.printf("'.' Single Channel DAC Control \n\r");
+    int cnt=0;
+    pc.baud(921600);
+    mRefShutters = 1;
 
 //Set up dac for external voltage
-dac.setRefExtern();
-dac.update();
+    dac.setRefExtern();
+    dac.update();
 
 //Intialize shutters
     Shutter SH;
@@ -192,287 +429,397 @@
     
     //Set straight pipes initial state
     m4x5TTL1 = 1;
+    m4x4TTL1 = 1;
     
-    m4x4TTL1 = 1;
     float voltage = 0;
     int voltCount = 0;
     string instr;
-
+    
+    seqstr  = "d010c010r010i010";
+    
+    pcstr.resize(200);
+    
 while(1) 
 {
-         char c = pc.getc();
+        //m.stop();
+        //pc.printf("Main loop took %f seconds \n\r",m.read());
+        pc.scanf("%s", pcstr.c_str() );
+        //m.reset();
+        //m.start();
+        //DEBUG
+        //pc.printf( "String Entered: %s   String Size:%d\n\r",pcstr.c_str(),pcstr.size() );
+        
+        
+        
+        int indexArr[100];
+        int indexSize = 0;
+        
+        
+        //Find all commas in string
+        /*
+        for(int i = 0; i < pcstr.size(); i++)
+        {
+            if( pcstr[i] == ',')
+            {
+                indexArr[indexSize] = i;
+                indexSize++;
+            }
+            
+        }
+        */
+        
+        //had to change as string does not resize
+        int i =0;
+        while( pcstr.c_str()[i] != 0 && pcstr.c_str()[i] != ' ' && pcstr.c_str()[i] != '\0')
+        {
+            if( pcstr[i] == ',')
+            {
+                indexArr[indexSize] = i;
+                indexSize++;
+            }
+            i++;
+        }
+        
+        //DEBUG
+        //pc.printf( "Commas Found %d\n\r",indexSize );
+        
+        
+        
+    //Interpret commands
+    for(int i =0; i<indexSize; i++)
+    {
+        //DEBUG
+        //pc.printf( "Loop #%d of %d\n\r",i,indexSize-1 );
+        
+        char c;
+        //command must begin with a comma
+        c = pcstr.c_str()[ indexArr[i] +1 ];
+            
+             
+        
+        
+        //DEBUG
+        //pc.printf( "Cmd is %c\n\r",c );
+        
         
         if( c == '1') //Toggle Shutter 1
         {
-            Shut1 = !Shut1;
+            char z1 = pcstr[ indexArr[i] +2 ];
+            Shut1 = atoi(&z1);
             SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
-            if(Shut1)
-            {
-                ////pc.printf("Shutter 1 Closed\n\r");
-            }
-            else
-            {
-                ////pc.printf("Shutter 1 Opened\n\r");
-            }
         }
         
         else if( c == '2') //Toggle Shutter 2
         {
-            Shut2 = !Shut2;
+            char z1 = pcstr[ indexArr[i] +2 ];
+            Shut2 = atoi(&z1);
             SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
-            if(Shut2)
-            {
-                ////pc.printf("Shutter 2 Closed\n\r");
-            }
-            else
-            {
-                ////pc.printf("Shutter 2 Opened\n\r");
-            }
         }
         
         else if( c == '3') //Toggle Shutter 3
         {
-            Shut3 = !Shut3;
+            char z1 = pcstr[ indexArr[i] +2 ];
+            Shut3 = atoi(&z1);
             SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
-            if(Shut3)
-            {
-                ////pc.printf("Shutter 3 Closed\n\r");
-            }
-            else
-            {
-                ////pc.printf("Shutter 3 Opened\n\r");
-            }
         }
         
         else if( c == '4') //Toggle Shutter 4
         {
-            Shut4 = !Shut4;
+            char z1 = pcstr[ indexArr[i] +2 ];
+            Shut4 = atoi(&z1);
             SH.writeShutters(Shut1,Shut2,Shut3,Shut4);
-            if(Shut4)
-            {
-                ////pc.printf("Shutter 4 Closed\n\r");
-            }
-            else
-            {
-                ////pc.printf("Shutter 4 Opened\n\r");
-            }
         }
         
         else if( c == 'u')
         {
-            mRefShutters = 0;
-            ////pc.printf("Referenced Shutters Opened\n\r");
+            closeRef();
         }
         
         else if( c == 'y')
         {
-            mRefShutters = 1;
-            ////pc.printf("Reference Shutters Closed\n\r");
+            openRef();
         }
         
         else if(c == 'o')  //Open All Shutters
         {
-            Shut1 = 1;
-            Shut2 = 1;
-            Shut3 = 1;
-            Shut4 = 1;
-            SH.writeShutters(1,1,1,1);
-            ////pc.printf("All Shutters Opened\n\r");
+            openAllHP(SH);
         }
         
         else if(c == 'r')  //Close All Shutters
         {
-            Shut1 = 0;
-            Shut2 = 0;
-            Shut3 = 0;
-            Shut4 = 0;
-            SH.writeShutters(0,0,0,0);
-            ////pc.printf("All Shutters Closed\n\r");
+            closeAllHP(SH);
+        }
+        
+        else if( c == 'm')
+        {
+            //string sub = pcstr.substr( indexArr[i]+2 , 4 );//Used for DAC
+            char z1 = pcstr[ indexArr[i] +2 ];
+            char z2 = pcstr[ indexArr[i] +3 ];
+            char z3 = pcstr[ indexArr[i] +4 ];
+            char z4 = pcstr[ indexArr[i] +5 ]; 
+            setAllShutters(SH,z1,z2,z3,z4);
         }
         
         else if( c == 91 ) //Left square bracket [ 4x4 Control
         {
-            //Get 5 1's or 0's for binary number
-            int count = 0;
-            ////pc.printf("4x4 Control: Enter 5 digit binary number\n\r");
-            while ( count < 5 )
-            {
-                c = pc.getc();
-                
-                if( c == '1' || c=='0' )
-                {
-                    *Arr_4x4[count] = atoi(&c);
-                    count++;
-                }
-            }
-            
-            for( int k = 0; k<5; k++) //Trigger clocking to change values
-            {
-                m4x4CLK = 1;
-                wait(0.1); 
-                m4x4CLK = 0;
-            }
-            
-            pc.printf("Optical Path set to : %d%d%d%d%d\n\r", m4x4TTL1.read(), m4x4TTL2.read(), m4x4TTL3.read(), m4x4TTL4.read(), m4x4TTL5.read() ); //Confirm the correct output is set
+            //get inputs for 4x4
+            char z1 = pcstr[ indexArr[i] +2 ];
+            char z2 = pcstr[ indexArr[i] +3 ];
+            char z3 = pcstr[ indexArr[i] +4 ];
+            char z4 = pcstr[ indexArr[i] +5 ];
+            char z5 = pcstr[ indexArr[i] +6 ];
+            set4x4Piping(Arr_4x4,z1,z2,z3,z4,z5);
         }
         
         
-        
         else if( c == 93 ) //Right square bracket ] 4x5 Control
         {
-            //Get 5 1's or 0's for binary number
-            int count = 0;
-            ////pc.printf("4x5 Control: Enter 5 digit binary number\n\r");
-            while ( count < 5 )
-            {
-                c = pc.getc();
-                
-                if( c == '1' || c=='0' )
-                {
-                    *Arr_4x5[count] = atoi(&c);
-                    count++;
-                }
-            }
-            
-            for( int k = 0; k<5; k++) //Trigger clocking to change values
-            {
-                m4x5CLK = 1;
-                wait(0.1); 
-                m4x5CLK = 0;
-            }
-            
-            pc.printf("Optical Path set to : %d%d%d%d%d\n\r", m4x5TTL1.read(), m4x5TTL2.read(), m4x5TTL3.read(), m4x5TTL4.read(), m4x5TTL5.read() ); //Confirm the correct output is set
+            char z1 = pcstr[ indexArr[i] +2 ];
+            char z2 = pcstr[ indexArr[i] +3 ];
+            char z3 = pcstr[ indexArr[i] +4 ];
+            char z4 = pcstr[ indexArr[i] +5 ];
+            char z5 = pcstr[ indexArr[i] +6 ];
+            set4x5Piping(Arr_4x5,z1,z2,z3,z4,z5);
         }
         
         
         else if( c == 'd')
         {
-            int CH1cnt;
-            int CH2cnt;
-            int CH3cnt;
-            int CH4cnt;
-            //Print State of DAC
-            if( dac.update() == 0)
-            {
-                (void)dac.getDACvalue(CH1cnt,0);
-                (void)dac.getDACvalue(CH2cnt,1);
-                (void)dac.getDACvalue(CH3cnt,2);
-                (void)dac.getDACvalue(CH4cnt,3);
-                pc.printf("CH1:%4d CH2:%4d CH3:%4d CH4:%4d\n\r",CH1cnt,CH2cnt,CH3cnt,CH4cnt);
-            }
-            
-            else
-            {
-                pc.printf("Error: No readback from DAC\n\r");
-            }
+            queryDAC(&dac);
         }
         
         else if( c == 'a')
         {
-            //Print State of Shutters
-            pc.printf("SH1:%d SH2:%d SH3:%d SH4:%d SHRef:%d\n\r",Shut1,Shut2,Shut3,Shut4,mRefShutters.read());
+            queryShutters();
         }    
         
-        else if( c == ',' ) //4 Channel DAC Control
-        {
-            ////pc.printf("4 Channel DAC Control Enter voltage and Press Enter\n\r");
-            int ret = 0;
-            int chan = 0;
-            while( ret ==0 && chan < 4)
-            {
-                char z = pc.getc();
-                if( z == 13 )
-                {
-                    voltCount = atoi( instr.c_str() );
-                    
-                    if( voltCount < 0 || voltCount > 4095 )
-                    {
-                        //////pc.printf("ERROR\n\r");
-                    }
-                    else
-                    {
-                            if ( dac.setDACvalue(voltCount,chan) )
-                            { 
-                                //printf("failed to set dac value %d for channel %d\n\r",voltCount,chan);
-                            }
-                            //////////pc.printf("Voltage set to %3fV\n\r", voltage);
-                            chan++;
-                            /*
-                            if( dac.update() )
-                            {
-                                printf("\n\rfailed to readback channel info \n\r");
-                            }
-                            else 
-                            {
-                                    (void)dac.getVoltage(voltage,chan);//no need to test done with updat 
-                                    printf(" CH%d %f[V]",chan,voltage);
-                                    printf("\n\r");
-                                    chan++;
-                            }
-                            */
-                                
-                    }
-                    if( chan == 4)
-                            {
-                                ret = 1;
-                                wait_ms(100);
-                            } 
-                    instr.clear();
-    
-                }
-                
-                else if( z == ']')//Sets all channels to full voltage
-                {
-                    for ( int cc =0 ; cc <4 ; cc++) 
-                    { 
-                        if ( dac.setDACvalue(3333,cc) )
-                        {
-                            //printf("failed to set dac value %d for channel %d\n\r",cnt,cc);
-                        }
-                    }
-                        //printf("All Channels Set to 5V \n\r");
-                        ret = 1;
-                }
-                
-                
-                else if( z == '[')//Sets all channels to 0 voltage
-                {
-                    for ( int cc =0 ; cc <4 ; cc++) 
-                    { 
-                        if ( dac.setDACvalue(1000,cc) )
-                        {
-                           // printf("failed to set dac value %d for channel %d\n\r",cnt,cc);
-                        }
-                    }
-                        //printf("All Channels Set to 0V \n\r");
-                        ret = 1;
-                }
-                
-                else
-                {
-                    //////pc.printf("%c",z);
-                    instr.push_back(z);
-                }
-    }
-}
-
-
         else if( c == '.' ) //Single Channel DAC Control
         {
             ////pc.printf("Single Channel DAC Control Press Channel Number\n\r");
-            char z = pc.getc();
-    
-            if( z == '1' || z== '2' || z == '3' || z == '0' )
+            
+            
+            char achan =  pcstr[ indexArr[i] + 2 ];
+            int ichan = atoi(&achan);
+            
+            char acount[5];
+            acount[0] = pcstr[ indexArr[i] + 3 ];
+            acount[1] = pcstr[ indexArr[i] + 4 ];
+            acount[2] = pcstr[ indexArr[i] + 5 ];
+            acount[3] = pcstr[ indexArr[i] + 6 ];
+            acount[4] = '\0';
+            int icount = atoi(acount);//Get 4 digit Count
+            //icount = icount / 10;
+            //DEBUG
+            //pc.printf("DAC Channel: %d    DAC Counts: %d   Acount:\n\r",ichan,icount);     
+             
+             
+            if( achan == '1' || achan== '2' || achan == '3' || achan == '0' )
             {
                 //////////pc.printf("Channel %c Selected",z);
-                DACSetChannel( atoi(&z) , &dac);
+                DACSetChannel( ichan , &dac, icount);
             }   
             else
             {
                 ////pc.printf("ERROR");
             }
         }
+        
+        else if( c == 't')
+        {
+            /*
+            //Contours Hologran
+            DACSetChannel( 0 , &dac, 0);
+            DACSetChannel( 1 , &dac, 0);
+            DACSetChannel( 2 , &dac, 0);
+            DACSetChannel( 3 , &dac, 0);
+            wait_ms(100);
+            trigSH( SH, 1 );
+            wait_ms(100);
+            
+            
+            //Illums
+            DACSetChannel( 0 , &dac, 4095);
+            DACSetChannel( 1 , &dac, 4095);
+            DACSetChannel( 2 , &dac, 4095);
+            DACSetChannel( 3 , &dac, 4095);
+            SH.writeShutters(1,1,1,1);
+            wait_ms(100);
+            trigSH( SH, 10 );
+            wait_ms(100);
+            
+            
+            //Reference
+            DACSetChannel( 0 , &dac, 0);
+            DACSetChannel( 1 , &dac, 0);
+            DACSetChannel( 2 , &dac, 0);
+            DACSetChannel( 3 , &dac, 0);
+            SH.writeShutters(0,0,0,0);
+            wait_ms(100);
+            trigNotEyeSafe( SH, 10 );
+            wait_ms(100);
+            
+            //Darks
+            SH.writeShutters(0,0,0,0);
+            DACSetChannel( 0 , &dac, 4095);
+            DACSetChannel( 1 , &dac, 4095);
+            DACSetChannel( 2 , &dac, 4095);
+            DACSetChannel( 3 , &dac, 4095);
+            
+            wait_ms(100);
+            trigNotEyeSafe( SH, 10 );
+            wait_ms(100);
+            */
+            
+            int i;
+            int nimgs = 0;
+            for(i = 0; i<seqstr.size(); i++)
+            {
+                //Find characters and then grab next three digits as the number of times to trigger
+                
+                if( seqstr[i] == 'i')
+                {
+                    nimgs = atoi( seqstr.substr(i+1, i+3).c_str() );
+                    DACSetChannel( 0 , &dac, 4095);
+                    DACSetChannel( 1 , &dac, 4095);
+                    DACSetChannel( 2 , &dac, 4095);
+                    DACSetChannel( 3 , &dac, 4095);
+                    trigSH( SH, nimgs );
+                    //pc.printf("Num Illums: %d\n",nimgs);
+                }
+                else if( seqstr[i] == 'd')
+                {
+                    nimgs = atoi( seqstr.substr(i+1, i+3).c_str() );
+                    SH.writeShutters(0,0,0,0);
+                    DACSetChannel( 0 , &dac, 4095);
+                    DACSetChannel( 1 , &dac, 4095);
+                    DACSetChannel( 2 , &dac, 4095);
+                    DACSetChannel( 3 , &dac, 4095);
+                    trigNotEyeSafe( SH, nimgs );
+                    //pc.printf("Num Darks: %d\n",nimgs);
+                }
+                else if( seqstr[i] == 'c')
+                {
+                    nimgs = atoi( seqstr.substr(i+1, i+3).c_str() );
+                    DACSetChannel( 0 , &dac, 0);
+                    DACSetChannel( 1 , &dac, 0);
+                    DACSetChannel( 2 , &dac, 0);
+                    DACSetChannel( 3 , &dac, 0);
+                    trigSH( SH, nimgs );
+                    
+                    //pc.printf("Num Contours: %d\n",nimgs);
+                }
+                else if( seqstr[i] == 'r')
+                {
+                    nimgs = atoi( seqstr.substr(i+1, i+3).c_str() );
+                    DACSetChannel( 0 , &dac, 0);
+                    DACSetChannel( 1 , &dac, 0);
+                    DACSetChannel( 2 , &dac, 0);
+                    DACSetChannel( 3 , &dac, 0);
+                    SH.writeShutters(0,0,0,0);
+                    trigNotEyeSafe( SH, nimgs );
+                    //pc.printf("Num Refs: %d\n",nimgs);
+                }
 
+            }
+            
+        }
+        
+        else if( c == 's' )
+        {
+            seqstr = pcstr.substr( indexArr[i] +2, indexArr[i+1] -1 );
+            pc.printf("String is %s \n",seqstr.c_str());
+        }
+        
+        
+        else if( c == ';')
+        {
+            //Dumb states of everything out
+            //All on one line
+            
+            //Shutters
+            pc.printf("SH1:%d SH2:%d SH3:%d SH4:%d SHRef:%d",Shut1,Shut2,Shut3,Shut4,mRefShutters.read());
+            
+            //DAC
+            int CH1cnt;
+            int CH2cnt;
+            int CH3cnt;
+            int CH4cnt;
+            
+            //Print State of DAC
+            int sts = dac.update();
+            int updatecnt = 0;
+            
+            
+            while( sts != 0 && updatecnt < 5)
+            { 
+                if(sts != 0)
+                {
+                    sts = dac.update();
+                    updatecnt++;
+                    
+                }
+            }
+            
+            if( updatecnt >= 5)
+            {
+                pc.printf("CH1:xxxx CH2:xxxx CH3:xxxx CH4:xxxx");
+            }
+            else
+            {
+                (void)dac.getDACvalue(CH1cnt,0);
+                (void)dac.getDACvalue(CH2cnt,1);
+                (void)dac.getDACvalue(CH3cnt,2);
+                (void)dac.getDACvalue(CH4cnt,3);
+                pc.printf("CH1:%4d CH2:%4d CH3:%4d CH4:%4d",CH1cnt,CH2cnt,CH3cnt,CH4cnt);
+            }
+            
+            //Piping
+            pc.printf("4x4:%d%d%d%d%d", m4x4TTL1.read(), m4x4TTL2.read(), m4x4TTL3.read(), m4x4TTL4.read(), m4x4TTL5.read() );
+            pc.printf("4x5:%d%d%d%d%d\n", m4x5TTL1.read(), m4x5TTL2.read(), m4x5TTL3.read(), m4x5TTL4.read(), m4x5TTL5.read() );
+        }
+        
+        else if( c == '+' )
+        {
+            pc.printf(",[%d%d%d%d%d,]%d%d%d%d%d", m4x4TTL1.read(), m4x4TTL2.read(), m4x4TTL3.read(), m4x4TTL4.read(), m4x4TTL5.read(), m4x5TTL1.read(), m4x5TTL2.read(), m4x5TTL3.read(), m4x5TTL4.read(), m4x5TTL5.read() );
+            pc.printf(",m%d%d%d%d",Shut1,Shut2,Shut3,Shut4);
+            int CH1cnt;
+            int CH2cnt;
+            int CH3cnt;
+            int CH4cnt;
+            
+            int sts = dac.update();
+            int updatecnt = 0;
+            
+            
+            while( sts != 0 && updatecnt < 5)
+            {
+                
+                if(sts != 0)
+                {
+                    sts = dac.update();
+                    updatecnt++;
+                    
+                }
+                
+            }
+            if( updatecnt >= 5 && sts != 0)
+            {
+                pc.printf(",.0xxxx,.1xxxx,.2xxxx,.3xxxx\n");
+            }
+            else
+            {
+                (void)dac.getDACvalue(CH1cnt,0);
+                (void)dac.getDACvalue(CH2cnt,1);
+                (void)dac.getDACvalue(CH3cnt,2);
+                (void)dac.getDACvalue(CH4cnt,3);
+                pc.printf(",.0%04d,.1%04d,.2%04d,.3%04d\n",CH1cnt,CH2cnt,CH3cnt,CH4cnt);
+            }
+            
+        }
+        
+        
+    }
+        
 }
     //Never Reach This
     return 1;