Skip to content

Commit 17d588f

Browse files
authored
Refactor NoteSetFn calls to use default functions (#147)
* Refactor NoteSetFn calls to use default functions * fix broken tests
1 parent 3a8a7b5 commit 17d588f

File tree

5 files changed

+280
-116
lines changed

5 files changed

+280
-116
lines changed

src/Notecard.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,6 @@ void noteTransactionStop (void) {
169169
@param assignCallbacks
170170
When `true` the system callbacks will be assigned,
171171
when `false` the system callbacks will be cleared.
172-
@param i2cmax
173-
The max length of each message to send from the host to
174-
the Notecard. Used to ensure the messages are sized appropriately
175-
for the host.
176-
@param wirePort
177-
The TwoWire implementation to use for I2C communication.
178172
*/
179173
/**************************************************************************/
180174
void Notecard::platformInit (bool assignCallbacks)
@@ -183,7 +177,7 @@ void Notecard::platformInit (bool assignCallbacks)
183177
if (assignCallbacks) {
184178
NoteSetFnDefault(malloc, free, noteDelay, noteMillis);
185179
} else {
186-
NoteSetFnDefault(nullptr, nullptr, nullptr, nullptr);
180+
NoteSetFn(nullptr, nullptr, nullptr, nullptr); // Force clear
187181
}
188182
}
189183

@@ -210,21 +204,23 @@ Notecard::~Notecard (void)
210204
communicating with the Notecard from the host.
211205
@param i2cAddress
212206
The I2C Address to use for the Notecard.
213-
@param i2cMax
207+
@param i2cMtu
214208
The max length of each message to send from the host
215209
to the Notecard. Used to ensure the messages are sized
216210
appropriately for the host.
217211
*/
218212
/**************************************************************************/
219-
void Notecard::begin(NoteI2c * noteI2c_, uint32_t i2cAddress_, uint32_t i2cMax_)
213+
void Notecard::begin(NoteI2c * noteI2c_, uint32_t i2cAddress_, uint32_t i2cMtu_)
220214
{
221215
noteI2c = noteI2c_;
222216
platformInit(noteI2c);
223217
if (noteI2c) {
224-
NoteSetFnI2C(i2cAddress_, i2cMax_, noteI2cReset,
225-
noteI2cTransmit, noteI2cReceive);
218+
NoteSetI2CAddress(i2cAddress_); // Force set user supplied address
219+
NoteSetI2CMtu(i2cMtu_); // Force set user supplied MTU
220+
NoteSetFnI2CDefault(i2cAddress_, i2cMtu_, noteI2cReset,
221+
noteI2cTransmit, noteI2cReceive);
226222
} else {
227-
NoteSetFnI2C(0, 0, nullptr, nullptr, nullptr);
223+
NoteSetFnI2C(0, 0, nullptr, nullptr, nullptr); // Force clear
228224
}
229225
}
230226

@@ -243,10 +239,10 @@ void Notecard::begin(NoteSerial * noteSerial_)
243239
noteSerial = noteSerial_;
244240
platformInit(noteSerial);
245241
if (noteSerial) {
246-
NoteSetFnSerial(noteSerialReset, noteSerialTransmit,
247-
noteSerialAvailable, noteSerialReceive);
242+
NoteSetFnSerialDefault(noteSerialReset, noteSerialTransmit,
243+
noteSerialAvailable, noteSerialReceive);
248244
} else {
249-
NoteSetFnSerial(nullptr, nullptr, nullptr, nullptr);
245+
NoteSetFnSerial(nullptr, nullptr, nullptr, nullptr); // Force clear
250246
}
251247
}
252248

src/Notecard.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ class Notecard
6161
~Notecard(void);
6262
#ifdef ARDUINO
6363
inline void begin(uint32_t i2cAddress = NOTE_I2C_ADDR_DEFAULT,
64-
uint32_t i2cMax = NOTE_I2C_MAX_DEFAULT,
64+
uint32_t i2cMtu = NOTE_I2C_MTU_DEFAULT,
6565
TwoWire &wirePort = Wire) {
66-
begin(make_note_i2c(wirePort), i2cAddress, i2cMax);
66+
begin(make_note_i2c(wirePort), i2cAddress, i2cMtu);
6767
}
6868
inline void begin(HardwareSerial &serial, uint32_t speed = 9600) {
6969
MakeNoteSerial_ArduinoParameters<HardwareSerial> arduino_parameters(serial, speed);
@@ -85,7 +85,7 @@ class Notecard
8585
#endif
8686
void begin(NoteI2c * noteI2c,
8787
uint32_t i2cAddress = NOTE_I2C_ADDR_DEFAULT,
88-
uint32_t i2cMax = NOTE_I2C_MAX_DEFAULT);
88+
uint32_t i2cMtu = NOTE_I2C_MTU_DEFAULT);
8989
void begin(NoteSerial * noteSerial);
9090
inline void clearDebugOutputStream(void) {
9191
setDebugOutputStream(nullptr);

0 commit comments

Comments
 (0)