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.
Dependencies: mbed DRV88255 TextLCD Ping mbed-rtos
main.cpp@9:b3674516729d, 2016-06-10 (annotated)
- Committer:
- sbouber1
- Date:
- Fri Jun 10 12:56:53 2016 +0000
- Revision:
- 9:b3674516729d
- Parent:
- 7:8b3aef52aa7b
- Child:
- 10:fd4670ec0806
Started threading stuff
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
6366295 | 0:dab140a197e0 | 1 | #include "SalinityController.h" |
6366295 | 0:dab140a197e0 | 2 | #include "TemperatureController.h" |
6366295 | 2:f6ebc225f232 | 3 | #include "MotorController.h" |
joran | 6:067e999b9c6e | 4 | #include "LCDController.h" |
sbouber1 | 9:b3674516729d | 5 | #include "ProximityController.h" |
6366295 | 0:dab140a197e0 | 6 | |
6366295 | 0:dab140a197e0 | 7 | #include "mbed.h" |
sbouber1 | 9:b3674516729d | 8 | #include "rtos.h" |
sbouber1 | 9:b3674516729d | 9 | |
sbouber1 | 9:b3674516729d | 10 | typedef struct Controllers { |
sbouber1 | 9:b3674516729d | 11 | TemperatureController *temperature; |
sbouber1 | 9:b3674516729d | 12 | SalinityController *salinity; |
sbouber1 | 9:b3674516729d | 13 | ProximityController *proximity; |
sbouber1 | 9:b3674516729d | 14 | LCDController *lcd; |
sbouber1 | 9:b3674516729d | 15 | |
sbouber1 | 9:b3674516729d | 16 | } Controllers; |
sbouber1 | 9:b3674516729d | 17 | |
sbouber1 | 9:b3674516729d | 18 | |
sbouber1 | 9:b3674516729d | 19 | |
sbouber1 | 9:b3674516729d | 20 | /* |
sbouber1 | 9:b3674516729d | 21 | Continuously update controller every 100 ms |
sbouber1 | 9:b3674516729d | 22 | */ |
sbouber1 | 9:b3674516729d | 23 | void controller_thread(void const *args) { |
sbouber1 | 9:b3674516729d | 24 | Controller *controller = (Controller*)args; |
sbouber1 | 9:b3674516729d | 25 | |
sbouber1 | 9:b3674516729d | 26 | while(1) { |
sbouber1 | 9:b3674516729d | 27 | controller->update(); |
sbouber1 | 9:b3674516729d | 28 | Thread::wait(100); |
sbouber1 | 9:b3674516729d | 29 | } |
sbouber1 | 9:b3674516729d | 30 | |
sbouber1 | 9:b3674516729d | 31 | } |
sbouber1 | 9:b3674516729d | 32 | |
6366295 | 0:dab140a197e0 | 33 | |
6366295 | 0:dab140a197e0 | 34 | int main() |
6366295 | 0:dab140a197e0 | 35 | { |
6366295 | 0:dab140a197e0 | 36 | int count; |
6366295 | 0:dab140a197e0 | 37 | |
6366295 | 0:dab140a197e0 | 38 | TemperatureController temperature; |
sbouber1 | 9:b3674516729d | 39 | Thread t1(controller_thread, (Controller*)&temperature); |
sbouber1 | 9:b3674516729d | 40 | |
sbouber1 | 9:b3674516729d | 41 | //SalinityController salt; |
sbouber1 | 9:b3674516729d | 42 | //Thread t2(controller_thread, (Controller*)&salt); |
sbouber1 | 9:b3674516729d | 43 | |
sbouber1 | 9:b3674516729d | 44 | |
sbouber1 | 9:b3674516729d | 45 | |
6366295 | 2:f6ebc225f232 | 46 | MotorController motor; |
sbouber1 | 9:b3674516729d | 47 | // Keep LCD controller outside thread |
joran | 6:067e999b9c6e | 48 | LCDController lcd; |
6366295 | 2:f6ebc225f232 | 49 | |
6366295 | 4:4011a1562a77 | 50 | // for(int i = 0; i < 20; i++) |
6366295 | 4:4011a1562a77 | 51 | // { |
6366295 | 4:4011a1562a77 | 52 | // motor.test(); |
6366295 | 4:4011a1562a77 | 53 | // motor.test2(); |
6366295 | 4:4011a1562a77 | 54 | // } |
sbouber1 | 9:b3674516729d | 55 | //lcd.splash(); |
sbouber1 | 9:b3674516729d | 56 | //while(1) { |
joran | 6:067e999b9c6e | 57 | // printf("%d> ", count); |
joran | 6:067e999b9c6e | 58 | |
joran | 6:067e999b9c6e | 59 | // salt.displayPPT(); |
6366295 | 0:dab140a197e0 | 60 | |
joran | 6:067e999b9c6e | 61 | //temperature.displayTemperature(); |
6366295 | 0:dab140a197e0 | 62 | |
joran | 6:067e999b9c6e | 63 | // temperature.controlHeater(); |
6366295 | 1:eb527bc93b62 | 64 | |
sbouber1 | 9:b3674516729d | 65 | // lcd.updateScreen(temperature.getTemperature(),salt.getVoltage()); |
sbouber1 | 9:b3674516729d | 66 | // count++; |
6366295 | 0:dab140a197e0 | 67 | |
sbouber1 | 9:b3674516729d | 68 | // wait(0.5); |
sbouber1 | 9:b3674516729d | 69 | //} |
sbouber1 | 9:b3674516729d | 70 | |
sbouber1 | 9:b3674516729d | 71 | float s = 0.0; |
sbouber1 | 9:b3674516729d | 72 | float t = 0.0; |
sbouber1 | 9:b3674516729d | 73 | |
sbouber1 | 9:b3674516729d | 74 | while(1) { |
sbouber1 | 9:b3674516729d | 75 | lcd.splash(); |
sbouber1 | 9:b3674516729d | 76 | Thread::wait(1000); |
sbouber1 | 9:b3674516729d | 77 | |
sbouber1 | 9:b3674516729d | 78 | t = temperature.getValue(); |
sbouber1 | 9:b3674516729d | 79 | // s=... |
sbouber1 | 9:b3674516729d | 80 | |
sbouber1 | 9:b3674516729d | 81 | printf("Grabbing temperature value from main thread: %f\r\n", t); |
sbouber1 | 9:b3674516729d | 82 | //printf("Grabbing salinity value from main thread: %f\n", salt.getValue()); |
sbouber1 | 9:b3674516729d | 83 | |
sbouber1 | 9:b3674516729d | 84 | lcd.updateScreen(t, s); |
sbouber1 | 9:b3674516729d | 85 | |
sbouber1 | 9:b3674516729d | 86 | motor.test(); |
6366295 | 0:dab140a197e0 | 87 | } |
6366295 | 0:dab140a197e0 | 88 | } |