Mario Simaremare / Mbed 2 deprecated g3_waterplay

Dependencies:   mbed

Revision:
14:6c24cab82ff0
Parent:
13:142a142a7ac5
--- a/Tank.cpp	Wed Jun 22 22:15:33 2016 +0000
+++ b/Tank.cpp	Fri Jun 24 13:46:52 2016 +0000
@@ -18,12 +18,12 @@
     _waterSyringe(waterSyringe),
     _pinger(pinger),
     _alarm(alarm),
+    _strStatus("Add nothing"),
     _previous_direction_salt(-1),
     _previous_direction_pure(-1),
     _position_salt(14),
     _position_pure(27),
-    _added_liquid(0.0),
-    _strStatus("Add nothing")
+    _added_liquid(0.0)
 {
 }
 
@@ -43,21 +43,17 @@
 
     range = range/2;
 
+    sprintf(
+        buffer,
+        "proximity is (%d cm)",
+        range
+    );
+    _printer.toBothln(buffer);
+
     if (range >= 7) {
-        sprintf(
-            buffer,
-            "proximity is ok (%d cm)",
-            range
-        );
         return true;
-    } else {
-        sprintf(
-            buffer,
-            "proximity is wrong (%d cm)",
-            range
-        );
     }
-    _printer.toBothln(buffer);
+
     return false;
 }
 
@@ -114,38 +110,26 @@
 }
 void Tank::react(double salinity)
 {
-    bool is_allowed = true;
-    /*
-    if(
-        (this->_added_liquid > 0.0)
-        && (fmod(this->_added_liquid, PROXIMITY_CHECK_POINT) == 0.0)
-    ) {
-        is_allowed = is_proximity_ok();
-        if(is_allowed){
-            this->_added_liquid = 0.0;
-        }
-    }
-    */
-
     _strStatus = "Add nothing";
     float added_liquid = 0.0;
+    
     if(is_proximity_ok()) {
         if(salinity < 0.0) {
             _strStatus = "Add salt";
-            _printer.toBoth("set salt valve to the tank");
-            _alarm.flash(2, 0.2, 3.0);
+            _printer.toBothln("set salt valve to the tank");
+            _alarm.salinity_flash();
             this->add(TYPE_SALT, ADDED_SALT, DIRECTION_PUSH);
-            _printer.toBoth("set salt valve to the reservoir");
-            _alarm.flash(2, 0.2, 3.0);
+            _printer.toBothln("set salt valve to the reservoir");
+            _alarm.salinity_flash();
             this->add(TYPE_SALT, ADDED_SALT, DIRECTION_PULL);
             added_liquid = ADDED_SALT;
         } else if(salinity > 0.0) {
             _strStatus = "Add water";
-            _printer.toBoth("set water valve to the tank");
-            _alarm.flash(1, 0.2, 3.0);
+            _printer.toBothln("set water valve to the tank");
+            _alarm.water_flash();
             this->add(TYPE_PURE, ADDED_WATER, DIRECTION_PUSH);
-            _printer.toBoth("set water valve to reservoir");
-            _alarm.flash(1, 0.2, 3.0);
+            _printer.toBothln("set water valve to reservoir");
+            _alarm.water_flash();
             this->add(TYPE_PURE, ADDED_WATER, DIRECTION_PULL);
             added_liquid = ADDED_WATER;
         }
@@ -158,29 +142,29 @@
 
 void Tank::initialize()
 {
-    _printer.toBoth("initializing...");
+    _printer.toBothln("initializing...");
     //initialize
-    _alarm.flash(1, 0.2, 3.0); //turn the thing to pulling from reservoir
+    _alarm.water_flash(); //turn the thing to pulling from reservoir
     this->add(TYPE_PURE, 20.0, DIRECTION_PULL);//20
-    _alarm.flash(1, 0.2, 3.0); //turn the thing to pushing to glass
+    _alarm.water_flash(); //turn the thing to pushing to glass
     this->add(TYPE_PURE, 20.0, DIRECTION_PUSH);//19.5
-    _alarm.flash(1, 0.2, 3.0); //turn the thing to pulling from reservoir
+    _alarm.water_flash(); //turn the thing to pulling from reservoir
     this->add(TYPE_PURE, 20.0, DIRECTION_PULL); //20
-    _alarm.flash(1, 0.2, 3.0); //turn the thing to pushing to glass
+    _alarm.water_flash(); //turn the thing to pushing to glass
     this->add(TYPE_PURE, 20.0, DIRECTION_PUSH);
-    _alarm.flash(1, 0.2, 3.0); //turn the thing to pulling from reservoir
+    _alarm.water_flash(); //turn the thing to pulling from reservoir
     this->add(TYPE_PURE, 25.0, DIRECTION_PULL); //20
     //done
 
     //initialize
-    _alarm.flash(2, 0.2, 3.0); //turn the thing to pulling from reservoir
+    _alarm.salinity_flash(); //turn the thing to pulling from reservoir
     this->add(TYPE_SALT, 20.0, DIRECTION_PULL);//20
-    _alarm.flash(2, 0.2, 3.0); //turn the thing to pushing to glass
+    _alarm.salinity_flash(); //turn the thing to pushing to glass
     this->add(TYPE_SALT, 20.0, DIRECTION_PUSH);//19.5
-    _alarm.flash(2, 0.2, 3.0); //turn the thing to pulling from reservoir
+    _alarm.salinity_flash(); //turn the thing to pulling from reservoir
     this->add(TYPE_SALT, 20.0, DIRECTION_PULL); //20
-    _alarm.flash(2, 0.2, 3.0); //turn the thing to pushing to glass
+    _alarm.salinity_flash(); //turn the thing to pushing to glass
     this->add(TYPE_SALT, 20.0, DIRECTION_PUSH);
-    _alarm.flash(2, 0.2, 3.0); //turn the thing to pulling from reservoir
+    _alarm.salinity_flash(); //turn the thing to pulling from reservoir
     this->add(TYPE_SALT, 25.0, DIRECTION_PULL); //20
 }
\ No newline at end of file