Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of SOFT253_Assignment_V2 by
main.cpp@37:b62b3aa19645, 2017-05-12 (annotated)
- Committer:
- akovaci
- Date:
- Fri May 12 22:09:40 2017 +0000
- Revision:
- 37:b62b3aa19645
- Parent:
- 36:7426f37f0c96
- Child:
- 38:8b6a6927b4f2
SOFT ASSIGN
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| Jonathan Austin | 0:2757d7abb7d9 | 1 | #include "mbed.h" | 
| martinsimpson | 32:260a288be58f | 2 | #include "rtos.h" | 
| noutram | 35:af125862c33e | 3 | #include "hts221.h" | 
| martinsimpson | 32:260a288be58f | 4 | #include "LPS25H.h" | 
| akovaci | 37:b62b3aa19645 | 5 | |
| akovaci | 36:7426f37f0c96 | 6 | Serial pc(USBTX, USBRX); | 
| martinsimpson | 32:260a288be58f | 7 | |
| akovaci | 37:b62b3aa19645 | 8 | #define NUMTHRDS 2 | 
| akovaci | 36:7426f37f0c96 | 9 | #define N 10 | 
| akovaci | 36:7426f37f0c96 | 10 | DigitalOut myled(D7); | 
| akovaci | 36:7426f37f0c96 | 11 | Ticker t; | 
| martinsimpson | 32:260a288be58f | 12 | I2C i2c2(I2C_SDA, I2C_SCL); | 
| noutram | 35:af125862c33e | 13 | |
| noutram | 35:af125862c33e | 14 | float tempCelsius = 25.50; | 
| noutram | 35:af125862c33e | 15 | float humi = 55; | 
| noutram | 35:af125862c33e | 16 | int humiMax = 100; | 
| noutram | 35:af125862c33e | 17 | char cmd=0; | 
| akovaci | 36:7426f37f0c96 | 18 | float tempArray[N]; | 
| akovaci | 36:7426f37f0c96 | 19 | float humArray[N]; | 
| akovaci | 36:7426f37f0c96 | 20 | float pressArray[N]; | 
| noutram | 35:af125862c33e | 21 | uint32_t seconds = 0, minutes=0, hours=0; | 
| akovaci | 37:b62b3aa19645 | 22 | |
| akovaci | 36:7426f37f0c96 | 23 | |
| akovaci | 37:b62b3aa19645 | 24 | |
| martinsimpson | 32:260a288be58f | 25 | |
| noutram | 35:af125862c33e | 26 | LPS25H barometer(i2c2, LPS25H_V_CHIP_ADDR); | 
| noutram | 35:af125862c33e | 27 | HTS221 humidity(I2C_SDA, I2C_SCL); | 
| noutram | 35:af125862c33e | 28 | |
| noutram | 35:af125862c33e | 29 | |
| akovaci | 36:7426f37f0c96 | 30 | void adcISR(); | 
| akovaci | 37:b62b3aa19645 | 31 | void thread1 (void const *args ); | 
| akovaci | 37:b62b3aa19645 | 32 | void threadcomun (void const *args); | 
| akovaci | 37:b62b3aa19645 | 33 | |
| akovaci | 37:b62b3aa19645 | 34 | Thread* t1; | 
| akovaci | 37:b62b3aa19645 | 35 | Thread* t2; | 
| akovaci | 37:b62b3aa19645 | 36 | |
| akovaci | 37:b62b3aa19645 | 37 | |
| akovaci | 36:7426f37f0c96 | 38 | |
| akovaci | 36:7426f37f0c96 | 39 | |
| akovaci | 36:7426f37f0c96 | 40 | |
| akovaci | 36:7426f37f0c96 | 41 | typedef struct { | 
| akovaci | 36:7426f37f0c96 | 42 | |
| akovaci | 36:7426f37f0c96 | 43 | float tempVal ; | 
| akovaci | 36:7426f37f0c96 | 44 | float humVal; | 
| akovaci | 36:7426f37f0c96 | 45 | float pressVal; | 
| akovaci | 36:7426f37f0c96 | 46 | }message_t; | 
| martinsimpson | 32:260a288be58f | 47 | |
| akovaci | 36:7426f37f0c96 | 48 | Mail<message_t, 10> mail_box; | 
| akovaci | 36:7426f37f0c96 | 49 | |
| akovaci | 36:7426f37f0c96 | 50 | void adcISR() | 
| akovaci | 36:7426f37f0c96 | 51 | { | 
| akovaci | 36:7426f37f0c96 | 52 | message_t *message = mail_box.alloc(); | 
| akovaci | 36:7426f37f0c96 | 53 | message->tempVal = tempCelsius; | 
| akovaci | 36:7426f37f0c96 | 54 | message->humVal = humi; | 
| akovaci | 36:7426f37f0c96 | 55 | message->pressVal = barometer.pressure(); | 
| akovaci | 36:7426f37f0c96 | 56 | myled=1; | 
| akovaci | 36:7426f37f0c96 | 57 | mail_box.put(message); | 
| akovaci | 36:7426f37f0c96 | 58 | //Thread::wait(1000); | 
| akovaci | 36:7426f37f0c96 | 59 | |
| akovaci | 36:7426f37f0c96 | 60 | } | 
| akovaci | 37:b62b3aa19645 | 61 | void thread1 (void const *args ) | 
| akovaci | 36:7426f37f0c96 | 62 | { | 
| akovaci | 36:7426f37f0c96 | 63 | |
| akovaci | 36:7426f37f0c96 | 64 | pc.baud(115200); | 
| akovaci | 37:b62b3aa19645 | 65 | //pc.printf("Temperature,Humidity,Pressure\n\n"); | 
| akovaci | 36:7426f37f0c96 | 66 | while(1) | 
| akovaci | 36:7426f37f0c96 | 67 | { | 
| akovaci | 37:b62b3aa19645 | 68 | cmd=NULL; | 
| akovaci | 36:7426f37f0c96 | 69 | osEvent evt = mail_box.get(); | 
| akovaci | 36:7426f37f0c96 | 70 | if (evt.status == osEventMail) | 
| akovaci | 36:7426f37f0c96 | 71 | { | 
| akovaci | 36:7426f37f0c96 | 72 | for (unsigned int n=(N-1); n>0; n--) | 
| akovaci | 36:7426f37f0c96 | 73 | { | 
| akovaci | 36:7426f37f0c96 | 74 | tempArray[n]= tempArray[n-1]; | 
| akovaci | 36:7426f37f0c96 | 75 | humArray[n]= humArray[n-1]; | 
| akovaci | 36:7426f37f0c96 | 76 | pressArray[n]= pressArray[n-1]; | 
| akovaci | 36:7426f37f0c96 | 77 | } | 
| akovaci | 36:7426f37f0c96 | 78 | message_t *message = (message_t*)evt.value.p; | 
| akovaci | 36:7426f37f0c96 | 79 | tempArray[0]= message->tempVal; | 
| akovaci | 36:7426f37f0c96 | 80 | humArray[0] = message->humVal; | 
| akovaci | 36:7426f37f0c96 | 81 | pressArray[0]= message->pressVal; | 
| akovaci | 37:b62b3aa19645 | 82 | |
| akovaci | 36:7426f37f0c96 | 83 | |
| akovaci | 36:7426f37f0c96 | 84 | // pc.printf("%4.2f,%3.1f,%6.1f\n\r", tempArray[N/2], humArray[N/2], pressArray[N/2]); | 
| akovaci | 36:7426f37f0c96 | 85 | |
| akovaci | 36:7426f37f0c96 | 86 | mail_box.free(message); | 
| akovaci | 36:7426f37f0c96 | 87 | } | 
| akovaci | 36:7426f37f0c96 | 88 | } | 
| akovaci | 36:7426f37f0c96 | 89 | } | 
| akovaci | 37:b62b3aa19645 | 90 | |
| akovaci | 37:b62b3aa19645 | 91 | void threadcomun (void const *args) | 
| akovaci | 37:b62b3aa19645 | 92 | { | 
| akovaci | 37:b62b3aa19645 | 93 | pc.baud(115200); | 
| akovaci | 37:b62b3aa19645 | 94 | pc.printf("Temperature,Humidity,Pressure\n\n"); | 
| akovaci | 37:b62b3aa19645 | 95 | while(cmd==NULL){cmd=getchar();} | 
| akovaci | 37:b62b3aa19645 | 96 | if(cmd=='A') | 
| akovaci | 37:b62b3aa19645 | 97 | { | 
| akovaci | 37:b62b3aa19645 | 98 | for (unsigned int n=0; n<N; n++) | 
| akovaci | 37:b62b3aa19645 | 99 | { | 
| akovaci | 37:b62b3aa19645 | 100 | pc.printf("the element of %d is %4.2f\n\r ",n,tempArray[n]); | 
| akovaci | 37:b62b3aa19645 | 101 | //wait(1.0); | 
| akovaci | 37:b62b3aa19645 | 102 | } | 
| akovaci | 37:b62b3aa19645 | 103 | } | 
| akovaci | 37:b62b3aa19645 | 104 | |
| akovaci | 37:b62b3aa19645 | 105 | } | 
| akovaci | 36:7426f37f0c96 | 106 | char answer; | 
| akovaci | 36:7426f37f0c96 | 107 | int main(void) | 
| akovaci | 36:7426f37f0c96 | 108 | { | 
| akovaci | 36:7426f37f0c96 | 109 | |
| akovaci | 36:7426f37f0c96 | 110 | puts("Loading... \n\n"); | 
| akovaci | 37:b62b3aa19645 | 111 | t1 = new Thread(thread1); | 
| akovaci | 37:b62b3aa19645 | 112 | t2 = new Thread(threadcomun); | 
| akovaci | 37:b62b3aa19645 | 113 | |
| akovaci | 37:b62b3aa19645 | 114 | |
| akovaci | 37:b62b3aa19645 | 115 | // Thread thread(thread1); | 
| akovaci | 37:b62b3aa19645 | 116 | //threadcomun(); | 
| akovaci | 37:b62b3aa19645 | 117 | |
| akovaci | 37:b62b3aa19645 | 118 | //Thread thread(threadcomun); | 
| akovaci | 37:b62b3aa19645 | 119 | t.attach(&adcISR,1); | 
| akovaci | 36:7426f37f0c96 | 120 | |
| akovaci | 36:7426f37f0c96 | 121 | while(1) | 
| noutram | 35:af125862c33e | 122 | { | 
| akovaci | 36:7426f37f0c96 | 123 | humidity.init(); | 
| akovaci | 36:7426f37f0c96 | 124 | humidity.calib(); | 
| akovaci | 36:7426f37f0c96 | 125 | humidity.ReadTempHumi(&tempCelsius, &humi); | 
| akovaci | 36:7426f37f0c96 | 126 | barometer.get(); | 
| akovaci | 36:7426f37f0c96 | 127 | barometer.pressure(); | 
| akovaci | 36:7426f37f0c96 | 128 | barometer.temperature(); | 
| akovaci | 36:7426f37f0c96 | 129 | sleep(); | 
| akovaci | 36:7426f37f0c96 | 130 | Thread::wait(200); // 200 ms NB 'Thread::wait(int d);' !!! d is in milliseconds! | 
| akovaci | 36:7426f37f0c96 | 131 | myled = 0; // LED is OFF | 
| akovaci | 36:7426f37f0c96 | 132 | Thread::wait(100); // 100 ms | 
| FairyMental | 34:62aae7d507e2 | 133 | } | 
| akovaci | 36:7426f37f0c96 | 134 | |
| noutram | 35:af125862c33e | 135 | } | 
| noutram | 35:af125862c33e | 136 | |
| noutram | 35:af125862c33e | 137 | |
| noutram | 35:af125862c33e | 138 | |
| akovaci | 36:7426f37f0c96 | 139 | |
| noutram | 35:af125862c33e | 140 | |
| akovaci | 36:7426f37f0c96 | 141 | |
| noutram | 35:af125862c33e | 142 | |
| akovaci | 36:7426f37f0c96 | 143 | |
| akovaci | 36:7426f37f0c96 | 144 | |
| akovaci | 36:7426f37f0c96 | 145 | |
| akovaci | 36:7426f37f0c96 | 146 | 
