9
9
* @author SparkFun Electronics
10
10
* @date 2025
11
11
* @copyright Copyright (c) 2025, SparkFun Electronics Inc. This project is released under the MIT License.
12
- *
12
+ *
13
13
* SPDX-License-Identifier: MIT
14
14
*/
15
15
16
-
17
16
#include " sfDevSoilMoisture.h"
18
17
19
18
// Impl for the core driver
22
21
/* *
23
22
* @brief Command to turn off the on-board LED
24
23
*/
25
- # define kCommandLEDOff 0x00
24
+ const uint8_t kCommandLEDOff = 0x00 ;
26
25
27
26
/* *
28
27
* @brief Command to turn on the on-board LED
29
28
*/
30
- # define kCommandLEDOn 0x01
29
+ const uint8_t kCommandLEDOn = 0x01 ;
31
30
32
31
/* *
33
32
* @brief Command to change the I2C address of the sensor
34
33
*/
35
- # define kCommandChangeAddress 0x03
34
+ const uint8_t kCommandChangeAddress = 0x03 ;
36
35
37
36
/* *
38
37
* @brief Command to get the moisture value from the sensor
39
38
*/
40
- # define kCommandGetValue 0x05
39
+ const uint8_t kCommandGetValue = 0x05 ;
41
40
42
41
/* *
43
42
* @brief Command indicating no new data is available
44
43
*/
45
- # define kCommandNothingNew 0x99
44
+ const uint8_t kCommandNothingNew = 0x99 ;
46
45
47
46
// ---------------------------------------------------------------------
48
47
// Core object implementation
@@ -68,7 +67,7 @@ sfTkError_t sfDevSoilMoisture::LEDOff(void)
68
67
return ksfTkErrBusNotInit;
69
68
70
69
// Send the command to turn the LED off
71
- return _theBus->writeByte (kCommandLEDOff );
70
+ return _theBus->writeData (kCommandLEDOff );
72
71
}
73
72
// ----------------------------------------------------------------------------------------
74
73
// LED on command
@@ -78,7 +77,7 @@ sfTkError_t sfDevSoilMoisture::LEDOn(void)
78
77
return ksfTkErrBusNotInit;
79
78
80
79
// Send the command to turn the LED on
81
- return _theBus->writeByte (kCommandLEDOn );
80
+ return _theBus->writeData (kCommandLEDOn );
82
81
}
83
82
84
83
// ----------------------------------------------------------------------------------------
@@ -89,7 +88,7 @@ uint16_t sfDevSoilMoisture::readMoistureValue(void)
89
88
return 0 ;
90
89
91
90
uint16_t value = 0 ;
92
- if (_theBus->readRegisterWord (kCommandGetValue , value) != ksfTkErrOk)
91
+ if (_theBus->readRegister (kCommandGetValue , value) != ksfTkErrOk)
93
92
return 0 ;
94
93
95
94
return value;
@@ -128,7 +127,7 @@ sfTkError_t sfDevSoilMoisture::setI2CAddress(uint8_t newAddress)
128
127
129
128
// Send the command to change the address. NOTE: Because of how the sensor works,
130
129
// the following will return an error (since the sensor side resets the bus)
131
- (void )_theBus->writeRegisterByte (kCommandChangeAddress , newAddress);
130
+ (void )_theBus->writeRegister (kCommandChangeAddress , newAddress);
132
131
133
132
return ksfTkErrOk;
134
133
}
0 commit comments