Latest
Dependencies: serial_terminal sample_hardware PLL_Config SDCard BMP280 Networkbits TextLCD SDBlockDevice
main.cpp@15:8af9672a6778, 2018-11-23 (annotated)
- Committer:
- Swabey89
- Date:
- Fri Nov 23 18:10:19 2018 +0000
- Revision:
- 15:8af9672a6778
- Parent:
- 13:00545b1cb247
- Child:
- 16:15588fdc5d11
pre time changes
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 | 5:956984cbe447 | 9 | |
Swabey89 | 10:0fffc988d325 | 10 | |
Swabey89 | 10:0fffc988d325 | 11 | //Signals |
Swabey89 | 8:c81b0ff8b822 | 12 | #define TAKE_SAMPLE 1 |
Swabey89 | 10:0fffc988d325 | 13 | |
Swabey89 | 10:0fffc988d325 | 14 | |
Swabey89 | 10:0fffc988d325 | 15 | |
Swabey89 | 10:0fffc988d325 | 16 | float sample_rate = 15; |
Swabey89 | 10:0fffc988d325 | 17 | //bool sample_enable = true; |
Swabey89 | 8:c81b0ff8b822 | 18 | |
Swabey89 | 8:c81b0ff8b822 | 19 | //Queues |
Swabey89 | 11:3ad0327e8c9f | 20 | EventQueue SDqueue(32*EVENTS_EVENT_SIZE); |
Swabey89 | 11:3ad0327e8c9f | 21 | EventQueue LCDqueue(32*EVENTS_EVENT_SIZE); |
Swabey89 | 11:3ad0327e8c9f | 22 | |
Swabey89 | 1:31c7b4ab552b | 23 | |
Swabey89 | 1:31c7b4ab552b | 24 | //Threads |
Swabey89 | 11:3ad0327e8c9f | 25 | Thread SDqueue_thread; |
Swabey89 | 11:3ad0327e8c9f | 26 | Thread LCDqueue_thread; |
Swabey89 | 11:3ad0327e8c9f | 27 | //Thread sterm_thread; |
Swabey89 | 8:c81b0ff8b822 | 28 | Thread sample_thread(osPriorityHigh); |
Swabey89 | 8:c81b0ff8b822 | 29 | //Thread ntwkthread |
Swabey89 | 0:4afd4940a189 | 30 | |
Swabey89 | 8:c81b0ff8b822 | 31 | Ticker sample; |
Swabey89 | 10:0fffc988d325 | 32 | |
Swabey89 | 8:c81b0ff8b822 | 33 | void sampleISR(void); |
Swabey89 | 8:c81b0ff8b822 | 34 | void takesample(void); |
Swabey89 | 8:c81b0ff8b822 | 35 | void samples(void); |
Swabey89 | 7:e2bf2d703867 | 36 | |
Swabey89 | 10:0fffc988d325 | 37 | |
Swabey89 | 9:fa8a35d9d6c0 | 38 | FILE* fp; |
Swabey89 | 9:fa8a35d9d6c0 | 39 | FATFileSystem* fs; |
Swabey89 | 7:e2bf2d703867 | 40 | |
Swabey89 | 11:3ad0327e8c9f | 41 | |
Swabey89 | 11:3ad0327e8c9f | 42 | //TEST |
Swabey89 | 11:3ad0327e8c9f | 43 | Thread serialthread(osPriorityAboveNormal); |
Swabey89 | 11:3ad0327e8c9f | 44 | EventQueue serialqueue(32*EVENTS_EVENT_SIZE); |
Swabey89 | 11:3ad0327e8c9f | 45 | char buffer[256]; |
Swabey89 | 11:3ad0327e8c9f | 46 | RawSerial* pc; |
Swabey89 | 11:3ad0327e8c9f | 47 | void serialISR(void); |
Swabey89 | 11:3ad0327e8c9f | 48 | void serialiser(void); |
Swabey89 | 11:3ad0327e8c9f | 49 | int i = 0; |
Swabey89 | 15:8af9672a6778 | 50 | |
Swabey89 | 15:8af9672a6778 | 51 | time_t seconds; |
Swabey89 | 15:8af9672a6778 | 52 | |
Swabey89 | 15:8af9672a6778 | 53 | |
Swabey89 | 11:3ad0327e8c9f | 54 | //TEST |
Swabey89 | 11:3ad0327e8c9f | 55 | |
Swabey89 | 11:3ad0327e8c9f | 56 | |
Swabey89 | 15:8af9672a6778 | 57 | int main() { |
Swabey89 | 11:3ad0327e8c9f | 58 | |
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 | 15:8af9672a6778 | 82 | |
Swabey89 | 15:8af9672a6778 | 83 | //set_time(1256729737); |
Swabey89 | 15:8af9672a6778 | 84 | |
Swabey89 | 11:3ad0327e8c9f | 85 | //TEST |
Swabey89 | 10:0fffc988d325 | 86 | |
Swabey89 | 1:31c7b4ab552b | 87 | |
Swabey89 | 1:31c7b4ab552b | 88 | //Flash to indicate goodness |
Swabey89 | 1:31c7b4ab552b | 89 | while(true) { |
Swabey89 | 5:956984cbe447 | 90 | greenLED = !greenLED; |
Swabey89 | 5:956984cbe447 | 91 | Thread::wait(500); |
Swabey89 | 0:4afd4940a189 | 92 | } |
Swabey89 | 0:4afd4940a189 | 93 | } |
Swabey89 | 1:31c7b4ab552b | 94 | |
Swabey89 | 8:c81b0ff8b822 | 95 | void sampleISR() |
Swabey89 | 8:c81b0ff8b822 | 96 | { |
Swabey89 | 8:c81b0ff8b822 | 97 | sample_thread.signal_set(TAKE_SAMPLE); |
Swabey89 | 8:c81b0ff8b822 | 98 | } |
Swabey89 | 8:c81b0ff8b822 | 99 | |
Swabey89 | 8:c81b0ff8b822 | 100 | void samples() |
Swabey89 | 8:c81b0ff8b822 | 101 | { |
Swabey89 | 8:c81b0ff8b822 | 102 | while(true) |
Swabey89 | 8:c81b0ff8b822 | 103 | { |
Swabey89 | 8:c81b0ff8b822 | 104 | //High priority thread |
Swabey89 | 8:c81b0ff8b822 | 105 | Thread::signal_wait(TAKE_SAMPLE); |
Swabey89 | 8:c81b0ff8b822 | 106 | |
Swabey89 | 11:3ad0327e8c9f | 107 | //needs to be a class at some point |
Swabey89 | 12:3a54cbaa714c | 108 | //read time also |
Swabey89 | 8:c81b0ff8b822 | 109 | double temp = sensor.getTemperature(); |
Swabey89 | 8:c81b0ff8b822 | 110 | double pressure = sensor.getPressure(); |
Swabey89 | 12:3a54cbaa714c | 111 | float light = adcIn.read(); |
Swabey89 | 8:c81b0ff8b822 | 112 | |
Swabey89 | 8:c81b0ff8b822 | 113 | //Pass onto queues |
Swabey89 | 12:3a54cbaa714c | 114 | LCDqueue.call(LCD_display,temp,pressure,light); |
Swabey89 | 8:c81b0ff8b822 | 115 | SDqueue.call(SDaddSample,temp,pressure); |
Swabey89 | 8:c81b0ff8b822 | 116 | } |
Swabey89 | 8:c81b0ff8b822 | 117 | } |
Swabey89 | 1:31c7b4ab552b | 118 | |
Swabey89 | 11:3ad0327e8c9f | 119 | void serialISR() |
Swabey89 | 11:3ad0327e8c9f | 120 | { |
Swabey89 | 11:3ad0327e8c9f | 121 | pc->attach(NULL, Serial::RxIrq); |
Swabey89 | 11:3ad0327e8c9f | 122 | serialqueue.call(serialiser); |
Swabey89 | 11:3ad0327e8c9f | 123 | } |
Swabey89 | 1:31c7b4ab552b | 124 | |
Swabey89 | 11:3ad0327e8c9f | 125 | void serialiser() |
Swabey89 | 12:3a54cbaa714c | 126 | { |
Swabey89 | 11:3ad0327e8c9f | 127 | if (pc->readable()) |
Swabey89 | 11:3ad0327e8c9f | 128 | { |
Swabey89 | 11:3ad0327e8c9f | 129 | buffer[i] = pc->getc(); |
Swabey89 | 11:3ad0327e8c9f | 130 | if (buffer[i] == '\r') |
Swabey89 | 11:3ad0327e8c9f | 131 | { |
Swabey89 | 11:3ad0327e8c9f | 132 | i = 0; |
Swabey89 | 11:3ad0327e8c9f | 133 | serialqueue.call(serialterm); |
Swabey89 | 11:3ad0327e8c9f | 134 | |
Swabey89 | 11:3ad0327e8c9f | 135 | } |
Swabey89 | 11:3ad0327e8c9f | 136 | else i++; |
Swabey89 | 11:3ad0327e8c9f | 137 | } |
Swabey89 | 11:3ad0327e8c9f | 138 | pc->attach(serialISR, Serial::RxIrq); |
Swabey89 | 11:3ad0327e8c9f | 139 | } |