9
9
*---------------------------------------------------------------------------------
10
10
*/
11
11
12
- // A simple wrapper around the SparkFun Soil Moisture Sensor - based on the original example driver /example from Zio
13
- // from here https://github.com/sparkfun/Zio-Qwiic-Soil-Moisture-Sensor
12
+ // A simple wrapper around the SparkFun Soil Moisture Sensor - based on the original example driver /example from Zio
13
+ // from here https://github.com/sparkfun/Zio-Qwiic-Soil-Moisture-Sensor
14
14
15
15
#pragma once
16
16
17
17
// To make the Arduino machine happy, include the toolkit header before the core implementation for this device
18
18
#include < SparkFun_Toolkit.h>
19
19
#include " sfeTk/sfeDevSoilMoisture.h"
20
20
21
+
21
22
// Note:
22
23
// The core of the implementation for this device library is in the SparkFun Toolkit object sfeDevSoilMoisture,
23
24
// contained in the directory sfeTk. This object implements all functionality independent of the bus type, I2C or SPI.
24
- // The SparkFunSoilMoistureSensorI2C and SparkFunSoilMoistureSensorSPI classes below are the Arduino-specific, bus-specific
25
- // implementations that inherit from the core toolkit class.
25
+ // The SparkFunSoilMoistureSensorI2C and SparkFunSoilMoistureSensorSPI classes below are the Arduino-specific,
26
+ // bus-specific implementations that inherit from the core toolkit class.
26
27
//
27
28
// -----------------------------------------------------------------------------------------------
28
29
// Define our Arduino Object - I2C version
29
30
class SparkFunSoilMoistureSensorI2C : public sfeDevSoilMoisture
30
31
{
31
32
public:
32
- // / @brief Begins the Device
33
- // / @param address I2C device address to use for the sensor
34
- // / @param wirePort Wire port to use for I2C communication
35
- // / @return True if successful, false otherwise
33
+ /* *
34
+ * @brief Begins the Device
35
+ *
36
+ * Initializes the soil moisture sensor for I2C communication using the specified
37
+ * I2C address and wire port.
38
+ *
39
+ * @param address I2C device address to use for the sensor (default is SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS)
40
+ * @param wirePort Wire port to use for I2C communication (default is Wire)
41
+ * @return true if successful, false otherwise
42
+ */
36
43
bool begin (const uint8_t address = SFE_SOIL_MOISTURE_DEFAULT_I2C_ADDRESS, TwoWire &wirePort = Wire)
37
44
{
38
45
// Setup Arduino I2C bus
@@ -42,8 +49,14 @@ class SparkFunSoilMoistureSensorI2C : public sfeDevSoilMoisture
42
49
return sfeDevSoilMoisture::begin (&_theI2CBus) == kSTkErrOk ? isConnected () : false ;
43
50
}
44
51
45
- // / @brief Checks if the Device is connected
46
- // / @return True if the sensor is connected, false otherwise
52
+ /* *
53
+ * @brief Checks if the device is connected and responding
54
+ *
55
+ * Tests communication with the sensor by attempting to ping it over I2C.
56
+ * A successful ping indicates the sensor is properly connected and responding.
57
+ *
58
+ * @return true if the sensor responds to communication attempts, false otherwise
59
+ */
47
60
bool isConnected ()
48
61
{
49
62
return _theI2CBus.ping () == kSTkErrOk ;
@@ -58,19 +71,27 @@ class SparkFunSoilMoistureSensorI2C : public sfeDevSoilMoisture
58
71
class SparkFunSoilMoistureSensorSPI : public sfeDevSoilMoisture
59
72
{
60
73
public:
61
- // / @brief Begins the Device with SPI as the communication bus
62
- // / @param csPin The chip select pin for the sensor
63
- // / @param spiPort The SPI port to use for communication
64
- // / @param spiSettings The SPI settings to use for communication
65
- // / @return True if successful, false otherwise
66
- bool begin (const uint8_t csPin, SPIClass &spiPort = SPI, SPISettings spiSettings = SPISettings(100000 , MSBFIRST, SPI_MODE0))
74
+ /* *
75
+ * @brief Begins the Device with SPI as the communication bus
76
+ *
77
+ * Initializes the soil moisture sensor for SPI communication using the specified
78
+ * chip select pin, SPI port, and SPI settings.
79
+ *
80
+ * @param csPin The chip select pin for the sensor
81
+ * @param spiPort The SPI port to use for communication (default is SPI)
82
+ * @param spiSettings The SPI settings to use for communication (default is SPISettings(100000, MSBFIRST,
83
+ * SPI_MODE0))
84
+ * @return true if successful, false otherwise
85
+ */
86
+ bool begin (const uint8_t csPin, SPIClass &spiPort = SPI,
87
+ SPISettings spiSettings = SPISettings(100000 , MSBFIRST, SPI_MODE0))
67
88
{
68
89
69
90
// Setup Arduino SPI bus
70
91
_theSPIBus.init (spiPort, spiSettings, csPin, true );
71
92
72
93
// Begin the sensor with the SPI bus connection
73
- return (sfeDevSoilMoisture::begin (&_theSPIBus) == kSTkErrOk );
94
+ return (sfeDevSoilMoisture::begin (&_theSPIBus) == kSTkErrOk );
74
95
}
75
96
76
97
private:
0 commit comments