Example software for a Cyclic Executive

Dependencies:   MCP23017 SDFileSystem WattBob_TextLCD mbed

Tasks.cpp

Committer:
sk398
Date:
2016-02-17
Revision:
3:c611b9bb5770
Parent:
2:22ebabd78084
Child:
4:b85bc0d810e1

File content as of revision 3:c611b9bb5770:

/* ###############################################################################
#
#
#
#
#
#
#
#
#
#
#
#
#
#
#
############################################################################### */

#include "mbed.h"
#include "Tasks.h"


/* ==================================== Task 1 ==================================== */
Task1::Task1(PinName squareWaveInPin)
{
    Timer Task1Timer;
    _squareWaveIn = new DigitalIn(squareWaveInPin);
}
    
int Task1::MeasureFreq()
{    
      return 0;  
}


/* ==================================== Task 2 ==================================== */
Task2::Task2(PinName digitalInCheckPin)
{
    _digitalInCheck = new DigitalIn(digitalInCheckPin);
}

bool Task2::digitalInState()
{
    if(_digitalInCheck -> read())
    {
        return TRUE;
    }
    else
    {
        return FALSE;
    }
}


/* ==================================== Task 3 ==================================== */
Task3::Task3(PinName WatchdogPin)
{
    _Watchdog = new DigitalOut(WatchdogPin);
}
    
void Task3::OutputWatchdogPulse()
{
    _Watchdog -> write(HIGH);
    wait_ms(WATCHDOG_PULSE_WIDTH);
    _Watchdog -> write(LOW);
}


/* ==================================== 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;    
}