Mario Simaremare / Mbed 2 deprecated g3_waterplay

Dependencies:   mbed

Revision:
2:ed17e258da0d
Parent:
1:f448c12d2c5b
Child:
3:7c648d1d8802
--- a/SalinitySensor.cpp	Tue Jun 07 10:21:07 2016 +0000
+++ b/SalinitySensor.cpp	Tue Jun 14 09:14:24 2016 +0000
@@ -10,22 +10,27 @@
     PinName pin,
     double const_voltage,
     double const_converter,
-    double const_multiplier
+    double const_multiplier,
+    double const_lower_boundary,
+    double const_upper_boundary
 ):
     _serial(serial),
     _analog_in(pin),
     _const_voltage(const_voltage),
     _const_converter(const_converter),
     _const_multiplier(const_multiplier),
+    _const_lower_boundary(const_lower_boundary),
+    _const_upper_boundary(const_upper_boundary),
     _reading(0.0),
     _voltage(0.0),
-    _salinity(0.0)
+    _salinity(0.0),
+    _status(0.0)
 {
-    this->read();
+    this->reload();
     
 }
 
-double SalinitySensor::read()
+void SalinitySensor::reload()
 {
     // the reading from sensor.
     this->_reading = this->_analog_in.read();
@@ -38,16 +43,24 @@
     this->_salinity = 
         this->_voltage *
         this->_const_multiplier;
-
-    /*
+        
+    this->_status = 0.0;
+    if(this->_salinity < this->_const_lower_boundary){
+        this->_status = this->_salinity - this->_const_lower_boundary;
+    } else if(this->_salinity > this->_const_upper_boundary){
+        this->_status = this->_const_lower_boundary - this->_salinity;
+    }
+    
     _serial.printf(
         "\tsalinity: %5.4F | %5.4F | %5.4F\n\r",
         this->_reading,
         this->_voltage,
         this->_salinity
     );
-    */
+}
 
+double SalinitySensor::getReading()
+{
     return(this->_reading);
 }
 
@@ -60,3 +73,8 @@
 {
     return(this->_salinity);
 }
+
+double SalinitySensor::getStatus()
+{
+    return(this->_status);
+}