File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -65,6 +65,22 @@ uint16_t sfeDevSoilMoisture::readMoistureValue(void)
6565 return value;
6666}
6767
68+ // ----------------------------------------------------------------------------------------
69+ // Returns the moisture ratio from the sensor (0 - 1.0)
70+ float sfeDevSoilMoisture::readMoistureRatio (void )
71+ {
72+ if (_theBus == nullptr )
73+ return 0.0 ;
74+
75+ return (((float )SFE_SOIL_MOISTURE_MAX_VALUE - (float )readMoistureValue ()) / (float )SFE_SOIL_MOISTURE_MAX_VALUE);
76+ }
77+
78+ // ----------------------------------------------------------------------------------------
79+ // Returns the moisture percentage from the sensor (0 - 100%)
80+ float sfeDevSoilMoisture::readMoisturePercentage (void )
81+ {
82+ return readMoistureRatio () * 100.0 ;
83+ }
6884// ----------------------------------------------------------------------------------------
6985sfeTkError_t sfeDevSoilMoisture::changeSensorAddress (uint8_t newAddress)
7086{
Original file line number Diff line number Diff line change 1515#include " sfeTk/sfeTkII2C.h"
1616#include < sfeTk/sfeToolKit.h>
1717
18- #define kSfeDevSoilMoistureDefaultI2CAddress 0x28
18+ // Default I2C address for the sensor
19+ #define SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS 0x28
20+
21+ // Max value for the sensor value (10-bit ADC) 2^10 = 1024-1
22+ #define SFE_SOIL_MOISTURE_MAX_VALUE 1023
1923
2024class sfeDevSoilMoisture
2125{
@@ -43,6 +47,14 @@ class sfeDevSoilMoisture
4347 // / @return The moisture value - a resistance reading between 0 and 1023
4448 uint16_t readMoistureValue (void );
4549
50+ // / @brief Reads the sensor value and returns the moisture ratio from the sensor (0 - 1.0)
51+ // / @return The moisture ratio
52+ float readMoistureRatio (void );
53+
54+ // / @brief Reads the sensor value and returns the moisture percentage from the sensor (0 - 100%)
55+ // / @return The moisture percentage
56+ float readMoisturePercentage (void );
57+
4658 // / @brief Changes the I2C address of the sensor
4759 // / @param newAddress The new I2C address to assign to the sensor
4860 // / @return kSTkErrOk if successful, otherwise an error code
You can’t perform that action at this time.
0 commit comments