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:
- joran
- Date:
- 2016-06-13
- Revision:
- 24:eeef4009640d
- Parent:
- 19:ee89eabe1fa2
File content as of revision 24:eeef4009640d:
#include <vector> #include <iostream> #include "SalinityController.h" #include "TemperatureController.h" #include "MotorController.h" #include "LCDController.h" #include "ProximityController.h" #include "AlarmController.h" #include "MockSensorController.h" #include "mbed.h" #include "rtos.h" #include "testing.h" #define MAIN_THREAD_DELAY_MS 1000 int main(); 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() { return MAIN(); } extern int test_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); //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); AlarmController alarm(false,0,&temperature,&salt,&proximity); controllers.push_back((void *)&alarm); // ----------------------------------------------------------------------------- MotorController motor; // 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; int i = 0; while(1) { Thread::wait(MAIN_THREAD_DELAY_MS); 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 exit // TODO maybe signal threads to terminate if(alarm.is_error()) { lcd.error(alarm.get_error_message()); break; } 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 either temperature and salinity or the water level given by the proximity controller if(i++ % 2) lcd.updateScreen(t, s); else lcd.updateScreen(d); } }