Example software for a Cyclic Executive

Dependencies:   MCP23017 SDFileSystem WattBob_TextLCD mbed

main.cpp

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

File content as of revision 4:b85bc0d810e1:

/* #####################################################################
                               main.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"

#define BACK_LIGHT_ON(INTERFACE) INTERFACE->write_bit(1,BL_BIT)
#define BACK_LIGHT_OFF(INTERFACE) INTERFACE->write_bit(0,BL_BIT)

MCP23017 *par_port;
WattBob_TextLCD *lcd;

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

void updateDisplay(int task1Param,int task2Param, float task4Channel1, float task4Channel2);

int main() {
    
    par_port = new MCP23017(p9,p10,0x40);
    lcd = new WattBob_TextLCD(par_port);
    par_port -> write_bit(1,BL_BIT);

    
    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);

    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);
    
    updateDisplay(task1Frequency,task2SwitchState,channel1,channel2);
    while(1) {
        myled = 1;
        wait(0.2);
        myled = 0;
        wait(0.2);
    }
}

void 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);
}