Steven Kay / Mbed 2 deprecated Embedded_Software_Assignment_2

Dependencies:   MCP23017 SDFileSystem WattBob_TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
sk398
Date:
Wed Feb 17 10:22:50 2016 +0000
Parent:
2:22ebabd78084
Child:
4:b85bc0d810e1
Commit message:
All 4 input processes constructed

Changed in this revision

Tasks.cpp Show annotated file Show diff for this revision Revisions of this file
Tasks.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/Tasks.cpp	Mon Feb 15 22:30:54 2016 +0000
+++ b/Tasks.cpp	Wed Feb 17 10:22:50 2016 +0000
@@ -29,17 +29,28 @@
     
 int Task1::MeasureFreq()
 {    
-        
+      return 0;  
 }
 
 
 /* ==================================== Task 2 ==================================== */
-
 Task2::Task2(PinName digitalInCheckPin)
 {
-    _digitialInCheck = new DigitalOut(digitalInCheckPin);
+    _digitalInCheck = new DigitalIn(digitalInCheckPin);
 }
-    
+
+bool Task2::digitalInState()
+{
+    if(_digitalInCheck -> read())
+    {
+        return TRUE;
+    }
+    else
+    {
+        return FALSE;
+    }
+}
+
 
 /* ==================================== Task 3 ==================================== */
 Task3::Task3(PinName WatchdogPin)
@@ -55,4 +66,32 @@
 }
 
 
-/* ==================================== Task 4 ==================================== */
\ No newline at end of file
+/* ==================================== Task 4 ==================================== */
+Task4::Task4(PinName Analog1Pin,PinName Analog2Pin)
+{
+    _AnalogIn1 = new AnalogIn(Analog1Pin);
+    _AnalogIn2 = new AnalogIn(Analog2Pin);
+}
+
+float *Task4::returnAnalogReadings()
+{
+    float readBuffer_1 = 0.0;
+    float readBuffer_2 = 0.0;
+    
+    float outputBuffer[2];
+    float *outputBufferPtr =&outputBuffer[0];
+       
+//    outputBuffer[0] = _AnalogIn1 -> read();
+//    outputBuffer[1] = _AnalogIn2 -> read();
+
+    for(int readCount = 0;readCount < NUM_ANALOG_SAMPLES; readCount++)
+    {
+        readBuffer_1 += _AnalogIn1 -> read();
+        readBuffer_2 += _AnalogIn2 -> read();  
+    }
+    
+    outputBuffer[0] = readBuffer_1/NUM_ANALOG_SAMPLES;
+    outputBuffer[1] = readBuffer_1/NUM_ANALOG_SAMPLES;
+    
+    return outputBufferPtr;    
+}
--- a/Tasks.h	Mon Feb 15 22:30:54 2016 +0000
+++ b/Tasks.h	Wed Feb 17 10:22:50 2016 +0000
@@ -19,11 +19,13 @@
 #ifndef _TASKS_H_
 #define _TASKS_H_
 
-
 // Global definitions
 #define HIGH 1
 #define LOW 0
 
+#define TRUE 1
+#define FALSE 0
+
 // Task 1 definitions
 #define WATCHDOG_PULSE_WIDTH 15
 
@@ -32,6 +34,7 @@
 // Task 3 definitions
 
 // Task 4 definitions
+#define NUM_ANALOG_SAMPLES 4
 
 // Task 5 definitions
 
@@ -49,7 +52,6 @@
     int MeasureFreq();
         
 private:
-    
     DigitalIn *_squareWaveIn;
         
 };
@@ -61,9 +63,9 @@
 {
 public:
     Task2(PinName digitalInCheckPin);
-        
+    bool digitalInState();
+    
 private:
-    
     DigitalIn *_digitalInCheck;
         
 };
@@ -87,48 +89,49 @@
 class Task4
 {
 public:
-    Task4(PinName digitalInCheckPin);
-        
-private:
+    Task4(PinName Analog1Pin,PinName Analog2Pin);
+    float *returnAnalogReadings();
     
-    DigitalIn *_digitalInCheck;
-        
-};
-
-/* ==================================== Task 5 ==================================== */
-// Display outputs to LCD
-class Task5
-{
-public:
-    Task5();
-        
 private:
-    
-        
+    AnalogIn *_AnalogIn1;
+    AnalogIn *_AnalogIn2;        
 };
 
-/* ==================================== Task 6 ==================================== */
-// Logical checks
-class Task6
-{
-public:
-    Task5();
-        
-private:
-    
-        
-};
-
-/* ==================================== Task 7 ==================================== */
-// Save data to SD Card
-class Task7
-{
-public:
-    Task7();
-        
-private:
-    
-        
-};
+//
+///* ==================================== Task 5 ==================================== */
+//// Display outputs to LCD
+//class Task5
+//{
+//public:
+//    Task5();
+//        
+//private:
+//    
+//        
+//};
+//
+///* ==================================== Task 6 ==================================== */
+//// Logical checks
+//class Task6
+//{
+//public:
+//    Task5();
+//        
+//private:
+//    
+//        
+//};
+//
+///* ==================================== Task 7 ==================================== */
+//// Save data to SD Card
+//class Task7
+//{
+//public:
+//    Task7();
+//        
+//private:
+//    
+//        
+//};
 
 #endif
--- a/main.cpp	Mon Feb 15 22:30:54 2016 +0000
+++ b/main.cpp	Wed Feb 17 10:22:50 2016 +0000
@@ -22,12 +22,19 @@
 
 DigitalOut myled(LED1);
 
-Task1 task1(p5); // Square wave Measurement
-
-Task3 task3(p6); // Watchdog Pulse
+Task1 task1(p5);                // Square wave Measurement
+Task2 task2_switch1(p6);        // Read digital Output
+Task3 task3(p7);                // Watchdog Pulse
+Task4 task4(p15,p16);           // Read analog Inputs
 
 
 int main() {
+    
+    task1.MeasureFreq();
+    int switch1State = task2_switch1.digitalInState();
+    task3.OutputWatchdogPulse();
+    float *analogReading = task4.returnAnalogReadings();
+    
     while(1) {
         myled = 1;
         wait(0.2);