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
- Committer:
- sbouber1
- Date:
- 2016-06-17
- Revision:
- 55:ee80f248919d
- Parent:
- 46:7e4c1f2ab76c
- Child:
- 57:8dc3192ff150
File content as of revision 55:ee80f248919d:
#include <vector> #include <iostream> #include "SalinityController.h" #include "TemperatureController.h" #include "LCDController.h" #include "ProximityController.h" #include "AlarmController.h" #include "PIDController.h" #include "settings.h" #include "mbed.h" extern int test_main(); int real_main(); int main() { // Either test_main() or real_main() depending on TEST_MODE define in settings.h return MAIN(); } int real_main() { std::vector<void *> controllers; // ----------------------------------------------------------------------------- /* THE FOLLOWING CONTROLLERS CAN BE THREADED BY SETTING THE FIRST ARG TO TRUE */ /* THE SECOND ARG SPECIFIES THE DELAY AFTER EACH UPDATE, ONLY WHEN THREADED */ // ----------------------------------------------------------------------------- TemperatureController temperature(false,0); controllers.push_back((void*)&temperature); ProximityController proximity(false,0); controllers.push_back((void*)&proximity); SalinityController salt(false,0); 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); // ----------------------------------------------------------------------------- // Show the splash screen indicating the system is starting up LCDController::splash(); int i = 0; // 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()) { // Get the next controller Controller *c = ((Controller *)*v); if(!c->is_threaded()) cout << "Running " << c->get_name() << " from main loop" << "\r\n"; // The controller only updates here if it's not threaded c->run(); // Advance to the next controller v++; } // If the alarm controller detected a dangerous situation then update lcd and possibly exit if(alarm.is_error()) { LCDController::error(alarm.get_error_message()); #ifdef HALT_ON_ALARM break; #endif } //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) LCDController::updateScreen(temperature.getValue(), salt.getValue(), &pidc); else LCDController::updateScreen(proximity.getValue()); } return 1; }