Example software for a Cyclic Executive
Dependencies: MCP23017 SDFileSystem WattBob_TextLCD mbed
Tasks.cpp
- Committer:
- sk398
- Date:
- 2016-02-26
- Revision:
- 4:b85bc0d810e1
- Parent:
- 3:c611b9bb5770
- Child:
- 5:250f51c80ac1
File content as of revision 4:b85bc0d810e1:
/* ##################################################################### 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() { }