Example software for a Cyclic Executive

Dependencies:   MCP23017 SDFileSystem WattBob_TextLCD mbed

Tasks.cpp

Committer:
sk398
Date:
2016-02-26
Revision:
5:250f51c80ac1
Parent:
4:b85bc0d810e1
Child:
6:ceda53939eb8

File content as of revision 5:250f51c80ac1:

/* #####################################################################
                               Tasks.cpp
                               ---------
                
                     Embedded Software - Assignment 2
                     --------------------------------
 
 Written by:        Steven Kay
 
 Date:              February 2016
 
 Function:          This 
 
 Version:           1.0
 
 Version History
 ---------------
 
 1.1                rgdfgdfgdfggdfgdg
 
 1.0                gdgddfdddgd
    
 ##################################################################### */

#include "mbed.h"
#include "Tasks.h"
#include "MCP23017.h"
#include "WattBob_TextLCD.h"

/* ==================================== Task 1 ==================================== */
Task1::Task1(PinName squareWaveInPin)
{
    _squareWaveIn = new InterruptIn(squareWaveInPin);
}
    
void Task1::MeasureFrequency()
{
    _Task1Timer.start();
    _squareWaveIn -> rise(this,&Task1::StopCounter);    
}

void Task1::StopCounter()
{
    _Task1Timer.stop();
    measuredFrequency = _Task1Timer.read_us();
    _Task1Timer.reset();
}

int Task1::ReadFrequency()
{
    _squareWaveIn -> rise(this,&Task1::MeasureFrequency);
    
    return measuredFrequency;
}

/* ==================================== 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];
       
//    outputBuffer[0] = _AnalogIn1 -> read();
//    outputBuffer[1] = _AnalogIn2 -> read();

    for(int readCount = 0;readCount < NUM_ANALOG_SAMPLES; readCount++)
    {
        readBuffer_1 += ((_AnalogIn1 -> read())*3.3);
//        printf("Buffer 1 %f\r\n",readBuffer_1);
        readBuffer_2 += ((_AnalogIn2 -> read())*3.3); 
//        printf("Buffer 2 %f\r\n",readBuffer_2); 
    }
    
    outputBuffer[0] = readBuffer_1/NUM_ANALOG_SAMPLES;
//    printf("outputBuffer[0] %f\r\n",outputBuffer[0]);
    outputBuffer[1] = readBuffer_2/NUM_ANALOG_SAMPLES;
//    printf("outputBuffer[1] %f\r\n",outputBuffer[1]);
    
    float *outputBufferPtr =&outputBuffer[0];
        
    return outputBufferPtr;    
}

/* ==================================== Task 5 ==================================== */
Task5::Task5(PinName sda, PinName scl, int address)
{
    _par_port = new MCP23017(sda,scl,address);
    _lcd = new WattBob_TextLCD(_par_port);
    _par_port -> write_bit(1,BL_BIT);
}

void Task5::updateDisplay(int task1Param,int task2Param, float task4Channel1, float task4Channel2)
{
    _lcd -> cls();
    _lcd -> locate(0,0);
    _lcd -> printf("F-%4dHz S1-%d ",task1Param,task2Param);
    _lcd -> locate(1,0);
    _lcd -> printf("C1-%1.2f C2-%1.2f ",task4Channel1,task4Channel2);
}