Mario Simaremare / Mbed 2 deprecated g3_waterplay

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers Waterplay.cpp Source File

Waterplay.cpp

00001 /*
00002 * G3: WATERPLAY
00003 */
00004 
00005 #include "Waterplay.h"
00006 #include "mbed.h"
00007 
00008 Waterplay::Waterplay(
00009     Printer &printer,
00010     TemperatureSensor &temperatureSensor,
00011     SalinitySensor &salinitySensor,
00012     Thermostat &thermostat,
00013     Tank &tank,
00014     Flasher &flasher,
00015     Flasher &alarm
00016 ):
00017     _printer(printer),
00018     _temperatureSensor(temperatureSensor),
00019     _salinitySensor(salinitySensor),
00020     _thermostat(thermostat),
00021     _tank(tank),
00022     _flasher(flasher),
00023     _alarm(alarm)
00024 {
00025 }
00026 
00027 int Waterplay::control()
00028 {
00029     int retVal = 1;
00030     _temperatureSensor.reload();
00031     _salinitySensor.reload();
00032     _flasher.flash(0.1);
00033 
00034     _printer.display(
00035         _salinitySensor.getSalinity(),
00036         _salinitySensor.getStrStatus(),
00037         _temperatureSensor.getTemperature(),
00038         _temperatureSensor.getStrStatus()
00039     );
00040     _flasher.flash(2);
00041     
00042     if(
00043         !_temperatureSensor.inBoundary()
00044         || !_salinitySensor.inBoundary()
00045         || !_tank.is_proximity_ok()
00046     ){
00047         if(!_temperatureSensor.inBoundary()){
00048             _printer.toBothln("check the temperature sensor");
00049         }
00050         
00051         if(_salinitySensor.inBoundary()){
00052             _printer.toBothln("check the salinity sensor");
00053         }
00054         
00055         if(!_tank.is_proximity_ok()){
00056             _printer.toBothln("check the salinity sensor");
00057         }
00058          _alarm.danger_flash_long();
00059     }
00060         
00061     if(_temperatureSensor.inDanger()) {
00062         _thermostat.react(
00063             _temperatureSensor.getStatus()
00064         );
00065     }
00066 
00067     if(_salinitySensor.inDanger()) {
00068         _tank.react(
00069             _salinitySensor.getStatus()
00070         );
00071     }
00072 
00073     _printer.display(
00074         _tank.getStrStatus(),
00075         _thermostat.getStrStatus()
00076     );
00077 
00078     return(retVal);
00079 }