ok

Dependencies:   mbed

Fork of g3_waterplay by Mario Simaremare

Committer:
ekasinambela
Date:
Mon Jun 20 14:46:19 2016 +0000
Revision:
10:fbab9fa07922
Parent:
5:4cbe44452889
temperature measurement is OK

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mariosimaremare 0:ad9362f18797 1 /*
mariosimaremare 0:ad9362f18797 2 * G3: WATERPLAY
mariosimaremare 0:ad9362f18797 3 */
mariosimaremare 0:ad9362f18797 4
mariosimaremare 0:ad9362f18797 5 #include "SalinitySensor.h"
mariosimaremare 0:ad9362f18797 6 #include "mbed.h"
mariosimaremare 3:7c648d1d8802 7 #include <algorithm>
mariosimaremare 3:7c648d1d8802 8 #include "Printer.h"
mariosimaremare 0:ad9362f18797 9
mariosimaremare 0:ad9362f18797 10 SalinitySensor::SalinitySensor(
mariosimaremare 3:7c648d1d8802 11 Printer &printer,
mariosimaremare 5:4cbe44452889 12 PinName pin
mariosimaremare 0:ad9362f18797 13 ):
mariosimaremare 3:7c648d1d8802 14 _printer(printer),
mariosimaremare 0:ad9362f18797 15 _analog_in(pin),
mariosimaremare 1:f448c12d2c5b 16 _reading(0.0),
mariosimaremare 1:f448c12d2c5b 17 _voltage(0.0),
mariosimaremare 2:ed17e258da0d 18 _salinity(0.0),
mariosimaremare 3:7c648d1d8802 19 _status(0.0),
mariosimaremare 3:7c648d1d8802 20 _strStatus("OK")
mariosimaremare 0:ad9362f18797 21 {
mariosimaremare 2:ed17e258da0d 22 this->reload();
mariosimaremare 0:ad9362f18797 23 }
mariosimaremare 0:ad9362f18797 24
mariosimaremare 2:ed17e258da0d 25 void SalinitySensor::reload()
mariosimaremare 0:ad9362f18797 26 {
mariosimaremare 5:4cbe44452889 27 double readings[SAMPLING_NUMBER];
mariosimaremare 3:7c648d1d8802 28
mariosimaremare 5:4cbe44452889 29 for(int counter = 0; counter < SAMPLING_NUMBER; ++counter){
mariosimaremare 3:7c648d1d8802 30 // the reading from sensor.
mariosimaremare 3:7c648d1d8802 31 readings[counter] = this->_analog_in.read();
mariosimaremare 3:7c648d1d8802 32 }
mariosimaremare 3:7c648d1d8802 33
mariosimaremare 5:4cbe44452889 34 sort(readings, readings + SAMPLING_NUMBER);
mariosimaremare 3:7c648d1d8802 35
mariosimaremare 5:4cbe44452889 36 this->_reading = readings[SAMPLING_NUMBER / 2];
mariosimaremare 3:7c648d1d8802 37
mariosimaremare 1:f448c12d2c5b 38 // converted voltage.
mariosimaremare 1:f448c12d2c5b 39 this->_voltage =
mariosimaremare 1:f448c12d2c5b 40 this->_reading *
mariosimaremare 5:4cbe44452889 41 VIN *
mariosimaremare 5:4cbe44452889 42 CONVERTER;
mariosimaremare 1:f448c12d2c5b 43 // the salinity value.
mariosimaremare 1:f448c12d2c5b 44 this->_salinity =
mariosimaremare 1:f448c12d2c5b 45 this->_voltage *
mariosimaremare 5:4cbe44452889 46 MULTIPLIER;
mariosimaremare 2:ed17e258da0d 47
mariosimaremare 2:ed17e258da0d 48 this->_status = 0.0;
mariosimaremare 3:7c648d1d8802 49 this->_strStatus = "OK";
mariosimaremare 5:4cbe44452889 50 if(this->_salinity < LOWER_BOUNDARY){
mariosimaremare 5:4cbe44452889 51 this->_status = this->_salinity - LOWER_BOUNDARY;
mariosimaremare 3:7c648d1d8802 52 this->_strStatus = "LW";
mariosimaremare 5:4cbe44452889 53 } else if(this->_salinity > UPPER_BOUNDARY){
mariosimaremare 5:4cbe44452889 54 this->_status = UPPER_BOUNDARY - this->_salinity;
mariosimaremare 3:7c648d1d8802 55 this->_strStatus = "HI";
mariosimaremare 2:ed17e258da0d 56 }
mariosimaremare 2:ed17e258da0d 57 }
mariosimaremare 1:f448c12d2c5b 58
mariosimaremare 2:ed17e258da0d 59 double SalinitySensor::getReading()
mariosimaremare 2:ed17e258da0d 60 {
mariosimaremare 1:f448c12d2c5b 61 return(this->_reading);
mariosimaremare 0:ad9362f18797 62 }
mariosimaremare 0:ad9362f18797 63
mariosimaremare 0:ad9362f18797 64 double SalinitySensor::getVoltage()
mariosimaremare 0:ad9362f18797 65 {
mariosimaremare 1:f448c12d2c5b 66 return(this->_voltage);
mariosimaremare 0:ad9362f18797 67 }
mariosimaremare 0:ad9362f18797 68
mariosimaremare 0:ad9362f18797 69 double SalinitySensor::getSalinity()
mariosimaremare 0:ad9362f18797 70 {
mariosimaremare 1:f448c12d2c5b 71 return(this->_salinity);
mariosimaremare 0:ad9362f18797 72 }
mariosimaremare 2:ed17e258da0d 73
mariosimaremare 2:ed17e258da0d 74 double SalinitySensor::getStatus()
mariosimaremare 2:ed17e258da0d 75 {
mariosimaremare 2:ed17e258da0d 76 return(this->_status);
mariosimaremare 2:ed17e258da0d 77 }
mariosimaremare 3:7c648d1d8802 78
mariosimaremare 3:7c648d1d8802 79 char* SalinitySensor::getStrStatus()
mariosimaremare 3:7c648d1d8802 80 {
mariosimaremare 3:7c648d1d8802 81 return(this->_strStatus);
mariosimaremare 3:7c648d1d8802 82 }