projet capteur connecté ST/SE
Dependencies: HP206C mbed HMC5883L DHT DS1820
Diff: T_H_soil.cpp
- Revision:
- 59:6d48aee9f7d5
- Child:
- 60:8b65fdf54d56
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/T_H_soil.cpp Mon Oct 08 21:36:02 2018 +0000 @@ -0,0 +1,54 @@ +#include "T_H_soil.h" + +bool initSoilTemp(DS1820& probe, PinName pin) +{ + //check that a DS1820 is connected at its port and init it + return probe.unassignedProbe(pin); +} + +float getSoilTemperature(DS1820& probe) +{ + bool wait(true);// if true, waits up to 750ms before returning + //return the ms_delay until the conversion will complete (=0 if wait == true) + int ms_delay = probe.convertTemperature(wait, DS1820::this_device); + if(ms_delay > 0) + wait_ms(ms_delay); + + //grab and return the conversion result + return probe.temperature(); +} + +float getSoilHumidity(AnalogIn& probe, float& airValue, float& waterValue, bool adaptiveCalibration) +{ + float HumidSensorVal = probe.read(); + float onePercent = (airValue - waterValue)/100; + float humidityPercentage = 100-(HumidSensorVal-waterValue)/onePercent; + if(humidityPercentage < 0 && adaptiveCalibration)// in case its drier than we expected at max + { + humidityPercentage = 0; + airValue = HumidSensorVal; + } + else if(humidityPercentage > 100 && adaptiveCalibration)// in case its wetter than we expected at max + { + humidityPercentage = 100; + waterValue = HumidSensorVal; + } + return humidityPercentage; +} +/* +int main() { + if(probe.unassignedProbe(PA_5)) + pc.printf("unassigned Probe"); + float airH = 0.77, waterH = 0.38; + float onePercent = (airH - waterH)/100; + while(1) { + + probe.convertTemperature(true, DS1820::this_device); + /*while(temp == DS1820::invalid_conversion) + temp = probe.temperature(); + float temp = probe.temperature(); + + + pc.printf("Soil ## T:%.2foC ## H:.2%f | calcH :%.2f%% ##\r\n", temp, humidSensor.read(), humidityPercentage); + wait(1); + }*/