Latest
Dependencies: serial_terminal sample_hardware PLL_Config SDCard BMP280 Networkbits TextLCD SDBlockDevice
main.cpp
- Committer:
- Swabey89
- Date:
- 2018-11-18
- Revision:
- 12:3a54cbaa714c
- Parent:
- 11:3ad0327e8c9f
- Child:
- 13:00545b1cb247
File content as of revision 12:3a54cbaa714c:
#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" #include "Clock.h" //Signals #define TAKE_SAMPLE 1 float sample_rate = 15; //bool sample_enable = true; //Queues EventQueue SDqueue(32*EVENTS_EVENT_SIZE); EventQueue LCDqueue(32*EVENTS_EVENT_SIZE); //Threads Thread SDqueue_thread; Thread LCDqueue_thread; //Thread sterm_thread; Thread sample_thread(osPriorityHigh); //Thread ntwkthread Ticker sample; void sampleISR(void); void takesample(void); void samples(void); FILE* fp; FATFileSystem* fs; //TEST Thread serialthread(osPriorityAboveNormal); EventQueue serialqueue(32*EVENTS_EVENT_SIZE); char buffer[256]; RawSerial* pc; void serialISR(void); void serialiser(void); int i = 0; //TEST Clock rtc; int main() { pc = new RawSerial(USBTX, USBRX); //Move threads into a thread init function? SDqueue_thread.start(callback(&SDqueue, &EventQueue::dispatch_forever)); LCDqueue_thread.start(callback(&LCDqueue, &EventQueue::dispatch_forever)); //sterm_thread.start(serialterm); sample_thread.start(samples); //Initialise, move into initialise function SDcard(); //Power on self test post(); pc->printf("Send commands\n\r"); sample.attach(&sampleISR, sample_rate); //TEST serialthread.start(callback(&serialqueue, &EventQueue::dispatch_forever)); pc->attach(serialISR, Serial::RxIrq); //TEST //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() { if (pc->readable()) { buffer[i] = pc->getc(); if (buffer[i] == '\r') { i = 0; serialqueue.call(serialterm); } else i++; } pc->attach(serialISR, Serial::RxIrq); }