Skip to content

Commit c499f29

Browse files
committed
Adds two functions for sending data to a device that doesn't indexing to a given register
* Still needs test
1 parent 8422de8 commit c499f29

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

src/sfeTkArdI2C.cpp

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2222
*/
2323

2424
#include "sfeTkArdI2C.h"
25+
#include <cstdint>
2526

2627
//---------------------------------------------------------------------------------
2728
// init()
@@ -87,7 +88,7 @@ sfeTkError_t sfeTkArdI2C::ping()
8788
//---------------------------------------------------------------------------------
8889
// writeByte()
8990
//
90-
// Writes a single byte to the device.
91+
// Sends a single byte to the device.
9192
//
9293
// Returns true on success, false on failure
9394
//
@@ -102,6 +103,41 @@ sfeTkError_t sfeTkArdI2C::writeByte(uint8_t dataToWrite)
102103
return _i2cPort->endTransmission() == 0 ? kSTkErrOk : kSTkErrFail;
103104
}
104105

106+
//---------------------------------------------------------------------------------
107+
// writeWord()
108+
//
109+
// Sends a word to the device.
110+
//
111+
// Returns true on success, false on failure
112+
//
113+
sfeTkError_t sfeTkArdI2C::writeWord(uint16_t dataToWrite)
114+
{
115+
if (!_i2cPort)
116+
return kSTkErrBusNotInit;
117+
118+
return writeBlock((uint8_t *)&dataToWrite, sizeof(uint16_t));
119+
}
120+
121+
//---------------------------------------------------------------------------------
122+
// writeBlock()
123+
//
124+
// Sends an array of data to the device.
125+
//
126+
// Returns true on success, false on failure
127+
//
128+
sfeTkError_t sfeTkArdI2C::writeBlock(const uint8_t *dataToWrite, size_t length)
129+
{
130+
int nData = 0;
131+
if (!_i2cPort)
132+
return kSTkErrBusNotInit;
133+
134+
// do the Arduino I2C work
135+
_i2cPort->beginTransmission(address());
136+
_i2cPort->write(data, (int)length);
137+
138+
return _i2cPort->endTransmission() == 0 ? kSTkErrOk : kSTkErrFail;
139+
}
140+
105141
//---------------------------------------------------------------------------------
106142
// writeRegisterByte()
107143
//

src/sfeTkArdI2C.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ class sfeTkArdI2C : public sfeTkII2C
109109
sfeTkError_t ping();
110110

111111
/**
112-
@brief Write a single byte to the device
112+
@brief Sends a single byte to the device
113113
@note sfeTkIBus interface method
114114
115115
@param data Data to write.
@@ -118,6 +118,26 @@ class sfeTkArdI2C : public sfeTkII2C
118118
*/
119119
sfeTkError_t writeByte(uint8_t data);
120120

121+
/**
122+
@brief Sends a word to the device.
123+
@note sfeTkIBus interface method
124+
125+
@param data Data to write.
126+
127+
@retval returns kStkErrOk on success
128+
*/
129+
sfeTkError_t writeWord(uint16_t data);
130+
131+
/**
132+
@brief Sends a block of data to the device.
133+
@note sfeTkIBus interface method
134+
135+
@param data Data to write.
136+
137+
@retval returns kStkErrOk on success
138+
*/
139+
sfeTkError_t writeBlock(const uint8_t *data);
140+
121141
/**
122142
@brief Write a single byte to the given register
123143
@note sfeTkIBus interface method

0 commit comments

Comments
 (0)