Latest
Dependencies: serial_terminal sample_hardware PLL_Config SDCard BMP280 Networkbits TextLCD SDBlockDevice
main.cpp@5:956984cbe447, 2018-11-06 (annotated)
- Committer:
- Swabey89
- Date:
- Tue Nov 06 19:19:45 2018 +0000
- Revision:
- 5:956984cbe447
- Parent:
- 4:a4dd5fd5cad8
- Child:
- 6:a5394c9e5927
Serial comms library for thread added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Swabey89 | 1:31c7b4ab552b | 1 | #include "sample_hardware.hpp" |
Swabey89 | 1:31c7b4ab552b | 2 | #include "Networkbits.hpp" |
Swabey89 | 5:956984cbe447 | 3 | #include "serial_terminal.hpp" |
Swabey89 | 5:956984cbe447 | 4 | #include "rtos.h" |
Swabey89 | 0:4afd4940a189 | 5 | |
Swabey89 | 5:956984cbe447 | 6 | |
Swabey89 | 1:31c7b4ab552b | 7 | // You will need a network connection set up (covered elsewhere). The host PC should have the address 10.0.0.1 |
Swabey89 | 1:31c7b4ab552b | 8 | |
Swabey89 | 1:31c7b4ab552b | 9 | //Threads |
Swabey89 | 5:956984cbe447 | 10 | //Thread nwrkThread; |
Swabey89 | 5:956984cbe447 | 11 | Thread serial_terminal; |
Swabey89 | 1:31c7b4ab552b | 12 | |
Swabey89 | 0:4afd4940a189 | 13 | |
Swabey89 | 0:4afd4940a189 | 14 | int main() { |
Swabey89 | 5:956984cbe447 | 15 | |
Swabey89 | 5:956984cbe447 | 16 | |
Swabey89 | 5:956984cbe447 | 17 | //Move threads into a thread init function |
Swabey89 | 5:956984cbe447 | 18 | serial_terminal.start(serialterm); |
Swabey89 | 5:956984cbe447 | 19 | |
Swabey89 | 1:31c7b4ab552b | 20 | //Greeting |
Swabey89 | 1:31c7b4ab552b | 21 | printf("Testing\n\n"); |
Swabey89 | 1:31c7b4ab552b | 22 | |
Swabey89 | 1:31c7b4ab552b | 23 | //Power on self test |
Swabey89 | 1:31c7b4ab552b | 24 | post(); |
Swabey89 | 1:31c7b4ab552b | 25 | |
Swabey89 | 5:956984cbe447 | 26 | /* |
Swabey89 | 1:31c7b4ab552b | 27 | //Initialise the SD card (this needs to move) |
Swabey89 | 1:31c7b4ab552b | 28 | if ( sd.init() != 0) { |
Swabey89 | 1:31c7b4ab552b | 29 | printf("Init failed \n"); |
Swabey89 | 1:31c7b4ab552b | 30 | lcd.cls(); |
Swabey89 | 1:31c7b4ab552b | 31 | lcd.printf("CANNOT INIT SD"); |
Swabey89 | 1:31c7b4ab552b | 32 | errorCode(FATAL); |
Swabey89 | 1:31c7b4ab552b | 33 | } |
Swabey89 | 1:31c7b4ab552b | 34 | |
Swabey89 | 1:31c7b4ab552b | 35 | //Create a filing system for SD Card |
Swabey89 | 1:31c7b4ab552b | 36 | FATFileSystem fs("sd", &sd); |
Swabey89 | 1:31c7b4ab552b | 37 | |
Swabey89 | 1:31c7b4ab552b | 38 | //Open to WRITE |
Swabey89 | 1:31c7b4ab552b | 39 | FILE* fp = fopen("/sd/test.csv","a"); |
Swabey89 | 1:31c7b4ab552b | 40 | if (fp == NULL) { |
Swabey89 | 1:31c7b4ab552b | 41 | error("Could not open file for write\n"); |
Swabey89 | 1:31c7b4ab552b | 42 | lcd.cls(); |
Swabey89 | 1:31c7b4ab552b | 43 | lcd.printf("CANNOT OPEN FILE\n\n"); |
Swabey89 | 1:31c7b4ab552b | 44 | errorCode(FATAL); |
Swabey89 | 1:31c7b4ab552b | 45 | } |
Swabey89 | 1:31c7b4ab552b | 46 | |
Swabey89 | 1:31c7b4ab552b | 47 | //Last message before sampling begins |
Swabey89 | 1:31c7b4ab552b | 48 | lcd.cls(); |
Swabey89 | 1:31c7b4ab552b | 49 | lcd.printf("READY\n\n"); |
Swabey89 | 3:b1583f309b43 | 50 | |
Swabey89 | 1:31c7b4ab552b | 51 | |
Swabey89 | 1:31c7b4ab552b | 52 | //Press either switch to unmount |
Swabey89 | 1:31c7b4ab552b | 53 | while ((SW1 == 0) && (SW2 == 0)) { |
Swabey89 | 1:31c7b4ab552b | 54 | |
Swabey89 | 1:31c7b4ab552b | 55 | //Base loop delay |
Swabey89 | 1:31c7b4ab552b | 56 | wait(1.0); |
Swabey89 | 1:31c7b4ab552b | 57 | |
Swabey89 | 1:31c7b4ab552b | 58 | //Read environmental sensors |
Swabey89 | 1:31c7b4ab552b | 59 | double temp = sensor.getTemperature(); |
Swabey89 | 1:31c7b4ab552b | 60 | double pressure = sensor.getPressure(); |
Swabey89 | 1:31c7b4ab552b | 61 | |
Swabey89 | 1:31c7b4ab552b | 62 | //Write new data to LCD (not fast!) |
Swabey89 | 1:31c7b4ab552b | 63 | lcd.cls(); |
Swabey89 | 1:31c7b4ab552b | 64 | lcd.printf("Temp Pressure\n"); |
Swabey89 | 1:31c7b4ab552b | 65 | lcd.printf("%6.1f ",temp); |
Swabey89 | 1:31c7b4ab552b | 66 | lcd.printf("%.2f\n",pressure); |
Swabey89 | 1:31c7b4ab552b | 67 | |
Swabey89 | 1:31c7b4ab552b | 68 | //Write to SD (potentially slow) |
Swabey89 | 5:956984cbe447 | 69 | //fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure); |
Swabey89 | 1:31c7b4ab552b | 70 | } |
Swabey89 | 1:31c7b4ab552b | 71 | |
Swabey89 | 1:31c7b4ab552b | 72 | //Close File |
Swabey89 | 1:31c7b4ab552b | 73 | fclose(fp); |
Swabey89 | 1:31c7b4ab552b | 74 | |
Swabey89 | 1:31c7b4ab552b | 75 | //Close down |
Swabey89 | 1:31c7b4ab552b | 76 | sd.deinit(); |
Swabey89 | 1:31c7b4ab552b | 77 | printf("Unmounted...\n"); |
Swabey89 | 1:31c7b4ab552b | 78 | lcd.cls(); |
Swabey89 | 1:31c7b4ab552b | 79 | lcd.printf("Unmounted...\n\n"); |
Swabey89 | 5:956984cbe447 | 80 | */ |
Swabey89 | 1:31c7b4ab552b | 81 | |
Swabey89 | 1:31c7b4ab552b | 82 | //Flash to indicate goodness |
Swabey89 | 1:31c7b4ab552b | 83 | while(true) { |
Swabey89 | 5:956984cbe447 | 84 | greenLED = !greenLED; |
Swabey89 | 5:956984cbe447 | 85 | Thread::wait(500); |
Swabey89 | 0:4afd4940a189 | 86 | } |
Swabey89 | 0:4afd4940a189 | 87 | } |
Swabey89 | 1:31c7b4ab552b | 88 | |
Swabey89 | 1:31c7b4ab552b | 89 | |
Swabey89 | 1:31c7b4ab552b | 90 | |
Swabey89 | 1:31c7b4ab552b | 91 |