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:
- 57:8dc3192ff150
- Parent:
- 55:ee80f248919d
- Child:
- 59:614f713fb48b
--- a/main.cpp Sun Jun 19 20:55:16 2016 +0000 +++ b/main.cpp Sun Jun 19 22:21:08 2016 +0000 @@ -5,14 +5,14 @@ #include "TemperatureController.h" #include "LCDController.h" #include "ProximityController.h" -#include "AlarmController.h" +#include "SensorAlarmController.h" #include "PIDController.h" #include "settings.h" #include "mbed.h" -extern int test_main(); -int real_main(); +extern int testMain(); +int realMain(); int main() { // Either test_main() or real_main() depending on TEST_MODE define in settings.h @@ -20,8 +20,9 @@ } -int real_main() { +int realMain() { + // Collection of all controllers updated in the main loop, updated in the order they were added std::vector<void *> controllers; // ----------------------------------------------------------------------------- @@ -29,20 +30,31 @@ /* THE SECOND ARG SPECIFIES THE DELAY AFTER EACH UPDATE, ONLY WHEN THREADED */ // ----------------------------------------------------------------------------- - TemperatureController temperature(false,0); + TemperatureController temperature(false, 0); controllers.push_back((void*)&temperature); - ProximityController proximity(false,0); + ProximityController proximity(false, 0); controllers.push_back((void*)&proximity); - SalinityController salt(false,0); - controllers.push_back((void *)&salt); + SalinityController salt(false, 0); + controllers.push_back((void *)&salt); - PIDController pidc(false,0,&temperature,&salt,&proximity); - controllers.push_back((void *)&pidc); + // Add alarms to monitor sensor values + SensorAlarmController temp_alarm = SensorAlarmController(false, 0, &temperature, + TEMP_MIN_CRIT, TEMP_MIN_UNDESIRED, TEMP_MAX_CRIT, TEMP_MAX_UNDESIRED); + controllers.push_back((void *)&temp_alarm); + + SensorAlarmController salt_alarm = SensorAlarmController(false, 0, &salt, + SALT_MIN_CRIT, SALT_MIN_UNDESIRED, SALT_MAX_CRIT, SALT_MAX_UNDESIRED); + controllers.push_back((void *)&salt_alarm); - AlarmController alarm(false,0,&temperature,&salt,&proximity); - controllers.push_back((void *)&alarm); + SensorAlarmController prox_alarm = SensorAlarmController(false, 0, &proximity, + VOLUME_MIN_CRIT, VOLUME_MIN_UNDESIRED, VOLUME_MAX_CRIT, VOLUME_MAX_UNDESIRED); + controllers.push_back((void *)&prox_alarm); + + // PIDController last, as alarms should update first + PIDController pidc(false, 0, &temperature,&salt,&proximity); + controllers.push_back((void *)&pidc); // ----------------------------------------------------------------------------- @@ -76,8 +88,9 @@ } // If the alarm controller detected a dangerous situation then update lcd and possibly exit - if(alarm.is_error()) { - LCDController::error(alarm.get_error_message()); + // TODO move LCD updating to alarm controller + if(temp_alarm.isError() || salt_alarm.isError() || prox_alarm.isError()) { + //LCDController::error(alarm.get_error_message()); #ifdef HALT_ON_ALARM break; #endif