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
Diff: main.cpp
- Revision:
- 55:ee80f248919d
- Parent:
- 46:7e4c1f2ab76c
- Child:
- 57:8dc3192ff150
diff -r 2710f0b92766 -r ee80f248919d main.cpp --- a/main.cpp Fri Jun 17 12:10:08 2016 +0000 +++ b/main.cpp Fri Jun 17 19:10:15 2016 +0000 @@ -6,35 +6,22 @@ #include "LCDController.h" #include "ProximityController.h" #include "AlarmController.h" -#include "MockSensorController.h" #include "PIDController.h" +#include "settings.h" #include "mbed.h" -#include "rtos.h" -#include "testing.h" -#define MAIN_THREAD_DELAY_MS 1000 - -int main(); -int test_main(); +extern int test_main(); int real_main(); - - - -MOCK(temp_mock, 20.0+0.01*i) -MOCK(salt_mock, 3.0+0.001*i) -MOCK(prox_mock, 10.0f) - - int main() { + // Either test_main() or real_main() depending on TEST_MODE define in settings.h return MAIN(); } -extern int test_main(); -int real_main() -{ +int real_main() { + std::vector<void *> controllers; // ----------------------------------------------------------------------------- @@ -43,48 +30,35 @@ // ----------------------------------------------------------------------------- TemperatureController temperature(false,0); - //MockSensorController temperature(false,0,temp_mock); controllers.push_back((void*)&temperature); ProximityController proximity(false,0); - //MockSensorController proximity(false,0,prox_mock); controllers.push_back((void*)&proximity); SalinityController salt(false,0); - //MockSensorController salt(false,0,salt_mock); controllers.push_back((void *)&salt); PIDController pidc(false,0,&temperature,&salt,&proximity); controllers.push_back((void *)&pidc); AlarmController alarm(false,0,&temperature,&salt,&proximity); - // controllers.push_back((void *)&alarm); - - + controllers.push_back((void *)&alarm); + // ----------------------------------------------------------------------------- - // Only the main thread calls the LCDController, it doesn't matter if there is a small delay - LCDController lcd; - lcd.splash(); - - float s = 0.0; - float t = 0.0; - float d = 0.0; + // Show the splash screen indicating the system is starting up + LCDController::splash(); - int i = 0; + int i = 0; - /* UNCOMMENT TO TEST MOTORS - while(1) - pidc.doTestingStuff(10); - */ - - - + // Loop forever, only breaks when an alarm triggers while(1) { + // Wait for a specified amount of time after each iteration Thread::wait(MAIN_THREAD_DELAY_MS); + // Iterate over all available Controllers vector<void *>::iterator v = controllers.begin(); while(v != controllers.end()) { @@ -101,27 +75,25 @@ v++; } - // if the alarm controller detected a dangerous situation then update lcd and exit - // TODO maybe signal threads to terminate + // If the alarm controller detected a dangerous situation then update lcd and possibly exit if(alarm.is_error()) { - lcd.error(alarm.get_error_message()); + LCDController::error(alarm.get_error_message()); + #ifdef HALT_ON_ALARM break; - } + #endif + } - t = temperature.getValue(); - d = proximity.getValue(); - s = salt.getValue(); - printf("Grabbing temperature value from main thread: %f\r\n", t); - printf("Grabbing salinity value from main thread: %f\r\n", s); - printf("Grabbing distance value from main thread: %f\r\n", d); - - + //Show temperature, salinity and volume of the water tank on the PC if connected through serial + cout << "Temperature value: " << temperature.getValue() << "\r\n"; + cout << "Salinity value: " << salt.getValue() << "\r\n"; + cout << "Volume value: " << proximity.getValue() << "\r\n"; + // Show either temperature and salinity or the water level given by the proximity controller if(i++ % 2) - lcd.updateScreen(t, s, &pidc); + LCDController::updateScreen(temperature.getValue(), salt.getValue(), &pidc); else - lcd.updateScreen(d); + LCDController::updateScreen(proximity.getValue()); }