Latest
Dependencies: serial_terminal sample_hardware PLL_Config SDCard BMP280 Networkbits TextLCD SDBlockDevice
main.cpp
- Committer:
- Swabey89
- Date:
- 2018-11-30
- Revision:
- 18:3edfb9152b05
- Parent:
- 17:ead43c1b729d
- Child:
- 19:88d8359306a4
File content as of revision 18:3edfb9152b05:
#include "mbed.h" #include "sample_hardware.hpp" #include "Networkbits.hpp" #include "serial_terminal.hpp" #include "SDCard.hpp" #include "rtos.h" #include "events/mbed_events.h" #include "LCDdisplay.hpp" //Signals #define TAKE_SAMPLE 1 //Global variables float sample_rate = 15; FILE* fp; FATFileSystem* fs; //Shared mutable variables struct tm* timeData; char cmdBuffer[256]; RawSerial* pc; //Queues EventQueue SDqueue(32*EVENTS_EVENT_SIZE); EventQueue LCDqueue(32*EVENTS_EVENT_SIZE); EventQueue serialqueue(32*EVENTS_EVENT_SIZE); //Threads Thread sample_thread(osPriorityHigh); Thread serialthread(osPriorityAboveNormal); Thread SDqueue_thread; Thread LCDqueue_thread; //Timers Ticker sample; //Function prototypes void sampleISR(void); void takesample(void); void samples(void); void serialISR(void); void serialiser(void); int main() { timeData = new tm; pc = new RawSerial(USBTX, USBRX); //Initialisations SDcard(); //Power on self test post(); //Start threads SDqueue_thread.start(callback(&SDqueue, &EventQueue::dispatch_forever)); LCDqueue_thread.start(callback(&LCDqueue, &EventQueue::dispatch_forever)); serialthread.start(callback(&serialqueue, &EventQueue::dispatch_forever)); sample_thread.start(samples); //Attach ISRs sample.attach(&sampleISR, sample_rate); pc->attach(serialISR, Serial::RxIrq); //Flash to indicate goodness while(true) { greenLED = !greenLED; Thread::wait(500); } } void sampleISR() { sample_thread.signal_set(TAKE_SAMPLE); } void samples() { while(true) { //High priority thread Thread::signal_wait(TAKE_SAMPLE); //needs to be a class at some point //read time also double temp = sensor.getTemperature(); double pressure = sensor.getPressure(); float light = adcIn.read(); //Pass onto queues LCDqueue.call(LCD_display,temp,pressure,light); SDqueue.call(SDaddSample,temp,pressure); } } void serialISR() { pc->attach(NULL, Serial::RxIrq); serialqueue.call(serialiser); } void serialiser() { static int i = 0; if (pc->readable()) { cmdBuffer[i] = pc->getc(); if (cmdBuffer[i] == '\r') { i = 0; serialqueue.call(serialterm); } else i++; } pc->attach(serialISR, Serial::RxIrq); }