Example software for a Cyclic Executive

Dependencies:   MCP23017 SDFileSystem WattBob_TextLCD mbed

Revision:
6:ceda53939eb8
Parent:
5:250f51c80ac1
Child:
7:2973bf297f3d
diff -r 250f51c80ac1 -r ceda53939eb8 main.cpp
--- a/main.cpp	Fri Feb 26 10:44:38 2016 +0000
+++ b/main.cpp	Mon Feb 29 11:20:48 2016 +0000
@@ -32,29 +32,57 @@
 
 DigitalOut myled(LED1);
 
-Task1 task1(p11);                   // Square wave Measurement
-Task2 task2_switch1(p12);           // Read digital Output
-Task3 task3(p13);                   // Watchdog Pulse
-Task4 task4(p15,p16);               // Read analog Inputs
-Task5 task5(p9,p10,0x40);           // Output to LCD Display
+Task1 task1(p11);                               // Square wave Measurement
+Task2 task2_switch1(p12);                       // Read digital Output
+Task3 task3(p13);                               // Watchdog Pulse
+Task4 task4(p15,p16);                           // Read analog Inputs
+Task5 task5(p9,p10,0x40);                       // Output to LCD Display
+Task6 task6;                                    // Logical checks
+Task7 task7(p5,p6,p7,p8,"SD","/SD/A2");         // SD Card Write
 
 int main() {
-
-    int task1Frequency = task1.ReadFrequency();
-    printf("Task 1 Frequency %d Hz\r\n",task1Frequency);
     
-    int task2SwitchState = task2_switch1.digitalInState();
-    printf("Switch 1 State: %d\r\n",task2SwitchState);
+    volatile int task1Frequency;
+    volatile int task2SwitchState;
+    volatile float task4AnalogChannels[2];
+    volatile int errorState;
+    char logData[50];
+    
+    task1Frequency = task1.ReadFrequency();
+//    printf("Task 1 Frequency %d Hz\r\n",task1Frequency);
+    
+    task2SwitchState = task2_switch1.digitalInState();
+//    printf("Switch 1 State: %d\r\n",task2SwitchState);
 
     task3.OutputWatchdogPulse();
     
     float *analogReading = task4.returnAnalogReadings();
-    float channel1 = *(analogReading);
-    float channel2 = *(analogReading+1);
-    printf("Analog Readings:\r\nChannel 1-%f\r\nChannel 2-%f\r\n",channel1,channel2);
+    task4AnalogChannels[0] = *(analogReading);
+    task4AnalogChannels[1]= *(analogReading+1);
+//    printf("Analog Readings:\r\nChannel 1-%f\r\nChannel 2-%f\r\n",task4AnalogChannels[0],task4AnalogChannels[1]);
+    
+    errorState = task6.updateErrorCode( task2SwitchState,
+                                        task4AnalogChannels[0],
+                                        task4AnalogChannels[1]  );
     
-    task5.updateDisplay(task1Frequency,task2SwitchState,channel1,channel2);
-    
+    task5.updateDisplay(task1Frequency,
+                        task2SwitchState,
+                        errorState,
+                        task4AnalogChannels[0],
+                        task4AnalogChannels[1]  );
+
+    if(task7.openFile("/SD/A2/test.csv","a"))
+    {
+        printf("File not opened");
+    }
+    else
+    {
+        int a = sprintf(logData,"Freq=%d,SW1=%d,A1=%1.3f,A2=%1.3f\n",task1Frequency,
+                        task2SwitchState,task4AnalogChannels[0],task4AnalogChannels[1]);
+        task7.writeData(logData);
+        task7.closeFile();
+    }
+
     while(1) {
         myled = 1;
         wait(0.2);