test to establish how we can share the project on MBED
Dependencies: BME280 BMP280 ELEC350-Coursework-2017 TextLCD
Fork of ELEC350-CWTEMPLATE-2017 by
main.cpp@14:b5baf59f53b9, 2017-12-15 (annotated)
- Committer:
- bdarling
- Date:
- Fri Dec 15 16:22:19 2017 +0000
- Revision:
- 14:b5baf59f53b9
- Parent:
- 7:83d2d9087972
Commented out getData() and readSerial() from main.cpp
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 1:e1cf7663f5ff | 1 | #include "sample_hardware.hpp" |
noutram | 3:a88838ff33e7 | 2 | #include "Networkbits.hpp" |
bdarling | 7:83d2d9087972 | 3 | #include "serial_protocol.hpp" |
noutram | 2:40403785b690 | 4 | |
noutram | 3:a88838ff33e7 | 5 | // This is a very short demo that demonstrates all the hardware used in the coursework. |
noutram | 3:a88838ff33e7 | 6 | // You will need a network connection set up (covered elsewhere). The host PC should have the address 10.0.0.1 |
noutram | 0:36e89e3ed7c4 | 7 | |
noutram | 3:a88838ff33e7 | 8 | //Threads |
noutram | 3:a88838ff33e7 | 9 | Thread nwrkThread; |
noutram | 1:e1cf7663f5ff | 10 | |
noutram | 3:a88838ff33e7 | 11 | |
noutram | 1:e1cf7663f5ff | 12 | int main() { |
noutram | 1:e1cf7663f5ff | 13 | //Greeting |
noutram | 3:a88838ff33e7 | 14 | printf("Testing\n\n"); |
noutram | 1:e1cf7663f5ff | 15 | |
noutram | 1:e1cf7663f5ff | 16 | //Power on self test |
noutram | 1:e1cf7663f5ff | 17 | post(); |
noutram | 1:e1cf7663f5ff | 18 | |
Chrispok21 | 5:d8e149da9f3f | 19 | /* //Initialise the SD card (this needs to move) |
noutram | 1:e1cf7663f5ff | 20 | if ( sd.init() != 0) { |
noutram | 1:e1cf7663f5ff | 21 | printf("Init failed \n"); |
noutram | 3:a88838ff33e7 | 22 | lcd.cls(); |
noutram | 3:a88838ff33e7 | 23 | lcd.printf("CANNOT INIT SD"); |
noutram | 1:e1cf7663f5ff | 24 | errorCode(FATAL); |
noutram | 1:e1cf7663f5ff | 25 | } |
noutram | 1:e1cf7663f5ff | 26 | |
noutram | 1:e1cf7663f5ff | 27 | //Create a filing system for SD Card |
noutram | 1:e1cf7663f5ff | 28 | FATFileSystem fs("sd", &sd); |
noutram | 0:36e89e3ed7c4 | 29 | |
noutram | 1:e1cf7663f5ff | 30 | //Open to WRITE |
noutram | 1:e1cf7663f5ff | 31 | FILE* fp = fopen("/sd/test.csv","a"); |
noutram | 1:e1cf7663f5ff | 32 | if (fp == NULL) { |
noutram | 1:e1cf7663f5ff | 33 | error("Could not open file for write\n"); |
noutram | 3:a88838ff33e7 | 34 | lcd.cls(); |
noutram | 3:a88838ff33e7 | 35 | lcd.printf("CANNOT OPEN FILE\n\n"); |
noutram | 1:e1cf7663f5ff | 36 | errorCode(FATAL); |
noutram | 1:e1cf7663f5ff | 37 | } |
noutram | 3:a88838ff33e7 | 38 | |
noutram | 3:a88838ff33e7 | 39 | //Last message before sampling begins |
noutram | 3:a88838ff33e7 | 40 | lcd.cls(); |
noutram | 3:a88838ff33e7 | 41 | lcd.printf("READY\n\n"); |
noutram | 3:a88838ff33e7 | 42 | |
noutram | 3:a88838ff33e7 | 43 | |
noutram | 1:e1cf7663f5ff | 44 | //Press either switch to unmount |
noutram | 1:e1cf7663f5ff | 45 | while ((SW1 == 0) && (SW2 == 0)) { |
noutram | 3:a88838ff33e7 | 46 | |
noutram | 3:a88838ff33e7 | 47 | //Base loop delay |
noutram | 3:a88838ff33e7 | 48 | wait(1.0); |
noutram | 3:a88838ff33e7 | 49 | |
noutram | 3:a88838ff33e7 | 50 | //Read environmental sensors |
noutram | 0:36e89e3ed7c4 | 51 | double temp = sensor.getTemperature(); |
noutram | 0:36e89e3ed7c4 | 52 | double pressure = sensor.getPressure(); |
noutram | 3:a88838ff33e7 | 53 | |
noutram | 3:a88838ff33e7 | 54 | //Write new data to LCD (not fast!) |
noutram | 3:a88838ff33e7 | 55 | lcd.cls(); |
noutram | 0:36e89e3ed7c4 | 56 | lcd.printf("Temp Pressure\n"); |
noutram | 0:36e89e3ed7c4 | 57 | lcd.printf("%6.1f ",temp); |
noutram | 0:36e89e3ed7c4 | 58 | lcd.printf("%.2f\n",pressure); |
noutram | 1:e1cf7663f5ff | 59 | |
noutram | 3:a88838ff33e7 | 60 | //Write to SD (potentially slow) |
noutram | 1:e1cf7663f5ff | 61 | fprintf(fp, "%6.1f,%.2f\n\r", temp, pressure); |
noutram | 1:e1cf7663f5ff | 62 | } |
noutram | 1:e1cf7663f5ff | 63 | |
Chrispok21 | 5:d8e149da9f3f | 64 | //Close File |
noutram | 1:e1cf7663f5ff | 65 | fclose(fp); |
noutram | 1:e1cf7663f5ff | 66 | |
noutram | 1:e1cf7663f5ff | 67 | //Close down |
noutram | 1:e1cf7663f5ff | 68 | sd.deinit(); |
noutram | 1:e1cf7663f5ff | 69 | printf("Unmounted...\n"); |
noutram | 1:e1cf7663f5ff | 70 | lcd.cls(); |
noutram | 1:e1cf7663f5ff | 71 | lcd.printf("Unmounted...\n\n"); |
noutram | 1:e1cf7663f5ff | 72 | |
noutram | 1:e1cf7663f5ff | 73 | //Flash to indicate goodness |
noutram | 1:e1cf7663f5ff | 74 | while(true) { |
noutram | 1:e1cf7663f5ff | 75 | greenLED = 1; |
noutram | 1:e1cf7663f5ff | 76 | wait(0.5); |
noutram | 1:e1cf7663f5ff | 77 | greenLED = 0; |
noutram | 1:e1cf7663f5ff | 78 | wait(0.1); |
Chrispok21 | 5:d8e149da9f3f | 79 | }*/ |
bdarling | 7:83d2d9087972 | 80 | while(1){ |
bdarling | 14:b5baf59f53b9 | 81 | //getData(); |
bdarling | 14:b5baf59f53b9 | 82 | //readSerial(); |
bdarling | 7:83d2d9087972 | 83 | } |
bdarling | 7:83d2d9087972 | 84 | } |