Latest
Dependencies: serial_terminal sample_hardware PLL_Config SDCard BMP280 Networkbits TextLCD SDBlockDevice
main.cpp@13:00545b1cb247, 2018-11-23 (annotated)
- Committer:
- Swabey89
- Date:
- Fri Nov 23 14:41:21 2018 +0000
- Revision:
- 13:00545b1cb247
- Parent:
- 12:3a54cbaa714c
- Child:
- 15:8af9672a6778
Working on setdate
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Swabey89 | 7:e2bf2d703867 | 1 | #include "mbed.h" |
Swabey89 | 1:31c7b4ab552b | 2 | #include "sample_hardware.hpp" |
Swabey89 | 1:31c7b4ab552b | 3 | #include "Networkbits.hpp" |
Swabey89 | 5:956984cbe447 | 4 | #include "serial_terminal.hpp" |
Swabey89 | 6:a5394c9e5927 | 5 | #include "SDCard.hpp" |
Swabey89 | 5:956984cbe447 | 6 | #include "rtos.h" |
Swabey89 | 11:3ad0327e8c9f | 7 | #include "events/mbed_events.h" |
Swabey89 | 8:c81b0ff8b822 | 8 | #include "LCDdisplay.hpp" |
Swabey89 | 12:3a54cbaa714c | 9 | #include "Clock.h" |
Swabey89 | 5:956984cbe447 | 10 | |
Swabey89 | 10:0fffc988d325 | 11 | |
Swabey89 | 10:0fffc988d325 | 12 | //Signals |
Swabey89 | 8:c81b0ff8b822 | 13 | #define TAKE_SAMPLE 1 |
Swabey89 | 10:0fffc988d325 | 14 | |
Swabey89 | 10:0fffc988d325 | 15 | |
Swabey89 | 10:0fffc988d325 | 16 | |
Swabey89 | 10:0fffc988d325 | 17 | float sample_rate = 15; |
Swabey89 | 10:0fffc988d325 | 18 | //bool sample_enable = true; |
Swabey89 | 8:c81b0ff8b822 | 19 | |
Swabey89 | 8:c81b0ff8b822 | 20 | //Queues |
Swabey89 | 11:3ad0327e8c9f | 21 | EventQueue SDqueue(32*EVENTS_EVENT_SIZE); |
Swabey89 | 11:3ad0327e8c9f | 22 | EventQueue LCDqueue(32*EVENTS_EVENT_SIZE); |
Swabey89 | 11:3ad0327e8c9f | 23 | |
Swabey89 | 1:31c7b4ab552b | 24 | |
Swabey89 | 1:31c7b4ab552b | 25 | //Threads |
Swabey89 | 11:3ad0327e8c9f | 26 | Thread SDqueue_thread; |
Swabey89 | 11:3ad0327e8c9f | 27 | Thread LCDqueue_thread; |
Swabey89 | 11:3ad0327e8c9f | 28 | //Thread sterm_thread; |
Swabey89 | 8:c81b0ff8b822 | 29 | Thread sample_thread(osPriorityHigh); |
Swabey89 | 8:c81b0ff8b822 | 30 | //Thread ntwkthread |
Swabey89 | 0:4afd4940a189 | 31 | |
Swabey89 | 8:c81b0ff8b822 | 32 | Ticker sample; |
Swabey89 | 10:0fffc988d325 | 33 | |
Swabey89 | 8:c81b0ff8b822 | 34 | void sampleISR(void); |
Swabey89 | 8:c81b0ff8b822 | 35 | void takesample(void); |
Swabey89 | 8:c81b0ff8b822 | 36 | void samples(void); |
Swabey89 | 7:e2bf2d703867 | 37 | |
Swabey89 | 10:0fffc988d325 | 38 | |
Swabey89 | 9:fa8a35d9d6c0 | 39 | FILE* fp; |
Swabey89 | 9:fa8a35d9d6c0 | 40 | FATFileSystem* fs; |
Swabey89 | 7:e2bf2d703867 | 41 | |
Swabey89 | 11:3ad0327e8c9f | 42 | |
Swabey89 | 11:3ad0327e8c9f | 43 | //TEST |
Swabey89 | 11:3ad0327e8c9f | 44 | Thread serialthread(osPriorityAboveNormal); |
Swabey89 | 11:3ad0327e8c9f | 45 | EventQueue serialqueue(32*EVENTS_EVENT_SIZE); |
Swabey89 | 11:3ad0327e8c9f | 46 | char buffer[256]; |
Swabey89 | 11:3ad0327e8c9f | 47 | RawSerial* pc; |
Swabey89 | 11:3ad0327e8c9f | 48 | void serialISR(void); |
Swabey89 | 11:3ad0327e8c9f | 49 | void serialiser(void); |
Swabey89 | 11:3ad0327e8c9f | 50 | int i = 0; |
Swabey89 | 11:3ad0327e8c9f | 51 | //TEST |
Swabey89 | 11:3ad0327e8c9f | 52 | |
Swabey89 | 11:3ad0327e8c9f | 53 | |
Swabey89 | 12:3a54cbaa714c | 54 | Clock rtc; |
Swabey89 | 12:3a54cbaa714c | 55 | |
Swabey89 | 11:3ad0327e8c9f | 56 | |
Swabey89 | 13:00545b1cb247 | 57 | int main() { |
Swabey89 | 13:00545b1cb247 | 58 | set_time(1256729737); |
Swabey89 | 11:3ad0327e8c9f | 59 | pc = new RawSerial(USBTX, USBRX); |
Swabey89 | 11:3ad0327e8c9f | 60 | |
Swabey89 | 8:c81b0ff8b822 | 61 | //Move threads into a thread init function? |
Swabey89 | 8:c81b0ff8b822 | 62 | SDqueue_thread.start(callback(&SDqueue, &EventQueue::dispatch_forever)); |
Swabey89 | 8:c81b0ff8b822 | 63 | LCDqueue_thread.start(callback(&LCDqueue, &EventQueue::dispatch_forever)); |
Swabey89 | 8:c81b0ff8b822 | 64 | |
Swabey89 | 11:3ad0327e8c9f | 65 | //sterm_thread.start(serialterm); |
Swabey89 | 8:c81b0ff8b822 | 66 | sample_thread.start(samples); |
Swabey89 | 8:c81b0ff8b822 | 67 | |
Swabey89 | 8:c81b0ff8b822 | 68 | //Initialise, move into initialise function |
Swabey89 | 8:c81b0ff8b822 | 69 | SDcard(); |
Swabey89 | 5:956984cbe447 | 70 | |
Swabey89 | 9:fa8a35d9d6c0 | 71 | |
Swabey89 | 1:31c7b4ab552b | 72 | //Power on self test |
Swabey89 | 1:31c7b4ab552b | 73 | post(); |
Swabey89 | 1:31c7b4ab552b | 74 | |
Swabey89 | 11:3ad0327e8c9f | 75 | pc->printf("Send commands\n\r"); |
Swabey89 | 3:b1583f309b43 | 76 | |
Swabey89 | 10:0fffc988d325 | 77 | sample.attach(&sampleISR, sample_rate); |
Swabey89 | 11:3ad0327e8c9f | 78 | |
Swabey89 | 11:3ad0327e8c9f | 79 | //TEST |
Swabey89 | 11:3ad0327e8c9f | 80 | serialthread.start(callback(&serialqueue, &EventQueue::dispatch_forever)); |
Swabey89 | 11:3ad0327e8c9f | 81 | pc->attach(serialISR, Serial::RxIrq); |
Swabey89 | 11:3ad0327e8c9f | 82 | //TEST |
Swabey89 | 10:0fffc988d325 | 83 | |
Swabey89 | 1:31c7b4ab552b | 84 | |
Swabey89 | 1:31c7b4ab552b | 85 | //Flash to indicate goodness |
Swabey89 | 1:31c7b4ab552b | 86 | while(true) { |
Swabey89 | 5:956984cbe447 | 87 | greenLED = !greenLED; |
Swabey89 | 5:956984cbe447 | 88 | Thread::wait(500); |
Swabey89 | 0:4afd4940a189 | 89 | } |
Swabey89 | 0:4afd4940a189 | 90 | } |
Swabey89 | 1:31c7b4ab552b | 91 | |
Swabey89 | 8:c81b0ff8b822 | 92 | void sampleISR() |
Swabey89 | 8:c81b0ff8b822 | 93 | { |
Swabey89 | 8:c81b0ff8b822 | 94 | sample_thread.signal_set(TAKE_SAMPLE); |
Swabey89 | 8:c81b0ff8b822 | 95 | } |
Swabey89 | 8:c81b0ff8b822 | 96 | |
Swabey89 | 8:c81b0ff8b822 | 97 | void samples() |
Swabey89 | 8:c81b0ff8b822 | 98 | { |
Swabey89 | 8:c81b0ff8b822 | 99 | while(true) |
Swabey89 | 8:c81b0ff8b822 | 100 | { |
Swabey89 | 8:c81b0ff8b822 | 101 | //High priority thread |
Swabey89 | 8:c81b0ff8b822 | 102 | Thread::signal_wait(TAKE_SAMPLE); |
Swabey89 | 8:c81b0ff8b822 | 103 | |
Swabey89 | 11:3ad0327e8c9f | 104 | //needs to be a class at some point |
Swabey89 | 12:3a54cbaa714c | 105 | //read time also |
Swabey89 | 8:c81b0ff8b822 | 106 | double temp = sensor.getTemperature(); |
Swabey89 | 8:c81b0ff8b822 | 107 | double pressure = sensor.getPressure(); |
Swabey89 | 12:3a54cbaa714c | 108 | float light = adcIn.read(); |
Swabey89 | 8:c81b0ff8b822 | 109 | |
Swabey89 | 8:c81b0ff8b822 | 110 | //Pass onto queues |
Swabey89 | 12:3a54cbaa714c | 111 | LCDqueue.call(LCD_display,temp,pressure,light); |
Swabey89 | 8:c81b0ff8b822 | 112 | SDqueue.call(SDaddSample,temp,pressure); |
Swabey89 | 8:c81b0ff8b822 | 113 | } |
Swabey89 | 8:c81b0ff8b822 | 114 | } |
Swabey89 | 1:31c7b4ab552b | 115 | |
Swabey89 | 11:3ad0327e8c9f | 116 | void serialISR() |
Swabey89 | 11:3ad0327e8c9f | 117 | { |
Swabey89 | 11:3ad0327e8c9f | 118 | pc->attach(NULL, Serial::RxIrq); |
Swabey89 | 11:3ad0327e8c9f | 119 | serialqueue.call(serialiser); |
Swabey89 | 11:3ad0327e8c9f | 120 | } |
Swabey89 | 1:31c7b4ab552b | 121 | |
Swabey89 | 11:3ad0327e8c9f | 122 | void serialiser() |
Swabey89 | 12:3a54cbaa714c | 123 | { |
Swabey89 | 11:3ad0327e8c9f | 124 | if (pc->readable()) |
Swabey89 | 11:3ad0327e8c9f | 125 | { |
Swabey89 | 11:3ad0327e8c9f | 126 | buffer[i] = pc->getc(); |
Swabey89 | 11:3ad0327e8c9f | 127 | if (buffer[i] == '\r') |
Swabey89 | 11:3ad0327e8c9f | 128 | { |
Swabey89 | 11:3ad0327e8c9f | 129 | i = 0; |
Swabey89 | 11:3ad0327e8c9f | 130 | serialqueue.call(serialterm); |
Swabey89 | 11:3ad0327e8c9f | 131 | |
Swabey89 | 11:3ad0327e8c9f | 132 | } |
Swabey89 | 11:3ad0327e8c9f | 133 | else i++; |
Swabey89 | 11:3ad0327e8c9f | 134 | } |
Swabey89 | 11:3ad0327e8c9f | 135 | pc->attach(serialISR, Serial::RxIrq); |
Swabey89 | 11:3ad0327e8c9f | 136 | } |