Program for the water play project for the course Software Testing Practical 2016 given at the VU University

Dependencies:   mbed DRV88255 TextLCD Ping mbed-rtos

Committer:
joran
Date:
Mon Jun 20 10:53:46 2016 +0000
Revision:
66:133398875949
Parent:
58:b5f0c0f305ff
Child:
68:b769c0f23406
setLed

Who changed what in which revision?

UserRevisionLine numberNew contents of line
6366295 0:dab140a197e0 1 #include "SalinityController.h"
6366295 0:dab140a197e0 2
sbouber1 58:b5f0c0f305ff 3 static AnalogIn salinity_sensor(p19);
joran 66:133398875949 4 static DigitalOut alarmled(LED2);
6366295 0:dab140a197e0 5
joran 42:e7c726f9c6ed 6 //Read the sensor, update the local variable.
sbouber1 10:fd4670ec0806 7 void SalinityController::update() {
sbouber1 10:fd4670ec0806 8 this->salinity = SalinityController::getAdjustedPPT();
sbouber1 10:fd4670ec0806 9 }
sbouber1 10:fd4670ec0806 10
joran 42:e7c726f9c6ed 11 //Return the value, this function does not update the value.
sbouber1 10:fd4670ec0806 12 float SalinityController::getValue() {
sbouber1 10:fd4670ec0806 13 return this->salinity;
6366295 0:dab140a197e0 14 }
6366295 0:dab140a197e0 15
sbouber1 58:b5f0c0f305ff 16 //Read the voltage, get an average over NUM_MEASUREMENTS values defined in settings.h
sbouber1 58:b5f0c0f305ff 17 float SalinityController::getVoltage() {
joran 42:e7c726f9c6ed 18 float voltage = 0;
6366295 0:dab140a197e0 19 float analogin_value = 0;
6366295 0:dab140a197e0 20
6366295 0:dab140a197e0 21 // Read 0-1.0 value
sbouber1 58:b5f0c0f305ff 22 for(int i = 0; i < NUM_MEASUREMENTS; i++) {
6366295 0:dab140a197e0 23 analogin_value += salinity_sensor.read();
sbouber1 58:b5f0c0f305ff 24 Thread::wait(MEASUREMENT_DELAY);
6366295 0:dab140a197e0 25 }
6366295 0:dab140a197e0 26
sbouber1 58:b5f0c0f305ff 27 analogin_value /= (float) NUM_MEASUREMENTS;
joran 6:067e999b9c6e 28 voltage = analogin_value * 3.3f * (5.0f/3.0f);
joran 6:067e999b9c6e 29
joran 6:067e999b9c6e 30 return voltage;
joran 6:067e999b9c6e 31 }
joran 6:067e999b9c6e 32
joran 42:e7c726f9c6ed 33 //Convert inputvolt to corrected sensor value
sbouber1 58:b5f0c0f305ff 34 float SalinityController::voltToSensor(float inputvolt) {
joran 7:8b3aef52aa7b 35 float slope = 0.7931723;
joran 7:8b3aef52aa7b 36 float intercept = 0.0050561;
joran 7:8b3aef52aa7b 37
joran 7:8b3aef52aa7b 38 float offset = (slope * inputvolt) - intercept;
joran 7:8b3aef52aa7b 39
joran 7:8b3aef52aa7b 40 return inputvolt + offset;
joran 7:8b3aef52aa7b 41 }
joran 7:8b3aef52aa7b 42
joran 42:e7c726f9c6ed 43 //Convert corrected sensor value to actual PPT
sbouber1 58:b5f0c0f305ff 44 float SalinityController::sensorToPPT(float inputvolt) {
joran 7:8b3aef52aa7b 45 float slope = 11.53368;
sbouber1 58:b5f0c0f305ff 46 float intercept = 0.43580;
sbouber1 58:b5f0c0f305ff 47 float minimum = 0.03778499;
joran 7:8b3aef52aa7b 48
sbouber1 58:b5f0c0f305ff 49 if (inputvolt <= minimum)
sbouber1 58:b5f0c0f305ff 50 return 0.00;
joran 7:8b3aef52aa7b 51
sbouber1 58:b5f0c0f305ff 52 return (slope * inputvolt) - intercept;
joran 7:8b3aef52aa7b 53 }
joran 7:8b3aef52aa7b 54
joran 42:e7c726f9c6ed 55 //Chain the needed functions to get the proper PPT
sbouber1 58:b5f0c0f305ff 56 float SalinityController::getAdjustedPPT() {
joran 7:8b3aef52aa7b 57 return sensorToPPT(voltToSensor(getVoltage()));
joran 7:8b3aef52aa7b 58 }
joran 42:e7c726f9c6ed 59
sbouber1 10:fd4670ec0806 60
sbouber1 58:b5f0c0f305ff 61 std::string SalinityController::getName() {
sbouber1 10:fd4670ec0806 62 return "SalinityController";
joran 26:966bad4c6365 63 }
joran 66:133398875949 64
joran 66:133398875949 65 void SalinityController::setLed(bool value){
joran 66:133398875949 66 if (value) alarmled = 1;
joran 66:133398875949 67 if (!value) alarmled = 0;
joran 66:133398875949 68 }