Skip to content

Commit db721b3

Browse files
authored
v1.6.0 (#129)
* chore: Update `note-c` * [TS-490] Add `const` to Notecard methods in `note-arduino` * [TS-488] `note-arduino` version should be recorded in user-agent data * [TS-267] Add `HardwareSerial::end()` to `NoteSerialReset` in `note-arduino` * [TS-254] Create `Notecard::end()`
1 parent f0d8357 commit db721b3

26 files changed

+746
-556
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515

1616
// Add the IDs of extensions you want installed when the container is created.
1717
"extensions": [
18-
"ms-vscode.cpptools"
18+
"ms-vscode.cpptools",
19+
"shardulm94.trailing-spaces"
1920
]
2021

2122
// Use 'forwardPorts' to make a list of ports inside the container available locally.

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,19 @@ if (rsp != NULL) {
8787

8888
## Keeping up to date with note-c repo
8989

90-
This library depends on the blues [note-c repo][note-c] and utilizes
91-
git subtrees to include those files in the src/note-c folder. To
92-
update this repo with the latest from note-c:
90+
This library depends on the Blues [`note-c` library][note-c]. To update this
91+
repo with the latest from `note-c`, run the `update_note_c.sh` shell script
92+
from the `scripts/` folder:
9393

9494
```none
95-
rm -rf src/note-c
96-
git commit -am 'remove note-c before re-add'
97-
git subtree add --prefix=src/note-c --squash https://github.com/blues/note-c.git master
95+
scripts/update_note_c.sh
9896
```
9997

98+
_**NOTE:** It is important to use the script. It utilizes git subtrees to
99+
include the appropriate files in the `src/note-c` folder. It also eliminates
100+
folders that necessary for testing `note-c` individually, but interfere with
101+
the Arduino build environment._
102+
100103
## Documentation
101104

102105
The documentation for this library can be found

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Blues Wireless Notecard
2-
version=1.5.4
2+
version=1.6.0
33
author=Blues
44
maintainer=Blues <[email protected]>
55
sentence=An easy to use Notecard Library for Arduino.

scripts/update_note_c.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,27 @@ pushd $ROOT_DIR
2929
rm -rf src/note-c
3030
# Commit the changes so that the next git subtree command doesn't complain about
3131
# changes in the working tree.
32-
git commit -am 'remove note-c before re-add'
32+
git commit -am 'Remove `note-c` before re-add'
3333
# Check out the note-c subtree using the given ref or master if not specified.
3434
git subtree add --prefix=src/note-c --squash https://github.com/blues/note-c.git $REF
3535

3636
# Remove all the unneeded directories from the subtree.
3737
NOTE_C_DIR="$ROOT_DIR/src/note-c"
3838
NOTE_C_UNNEEDED_DIRS=(
39+
"$NOTE_C_DIR/.devcontainer"
40+
"$NOTE_C_DIR/.github"
41+
"$NOTE_C_DIR/.vscode"
3942
"$NOTE_C_DIR/assets"
4043
"$NOTE_C_DIR/docs"
4144
"$NOTE_C_DIR/scripts"
4245
"$NOTE_C_DIR/test"
43-
"$NOTE_C_DIR/.github"
4446
)
4547
for DIR in "${NOTE_C_UNNEEDED_DIRS[@]}"; do
4648
rm -rf "$DIR"
4749
done
4850

51+
# Commit the removal of unneeded directories.
52+
git commit -am 'Remove unneeded directories from `note-c`'
53+
4954
# Return to original directory.
5055
popd

src/NoteI2c_Arduino.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ NoteI2c_Arduino::NoteI2c_Arduino
3030
_i2cPort.begin();
3131
}
3232

33+
NoteI2c_Arduino::~NoteI2c_Arduino (
34+
void
35+
)
36+
{
37+
#if WIRE_HAS_END
38+
_i2cPort.end();
39+
#endif
40+
}
41+
3342
const char *
3443
NoteI2c_Arduino::receive (
3544
uint16_t device_address_,

src/NoteI2c_Arduino.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class NoteI2c_Arduino final : public NoteI2c
1616
{
1717
public:
1818
NoteI2c_Arduino(TwoWire & i2c_bus);
19+
~NoteI2c_Arduino(void);
1920
const char * receive(uint16_t device_address, uint8_t * buffer, uint16_t requested_byte_count, uint32_t * available) override;
2021
bool reset(uint16_t device_address) override;
2122
const char * transmit(uint16_t device_address, uint8_t * buffer, uint16_t size) override;

src/NoteSerial_Arduino.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ NoteSerial_Arduino::NoteSerial_Arduino
2929
_notecardSerial.begin(_notecardSerialSpeed);
3030
}
3131

32+
NoteSerial_Arduino::~NoteSerial_Arduino (
33+
void
34+
)
35+
{
36+
_notecardSerial.end();
37+
}
38+
3239
size_t
3340
NoteSerial_Arduino::available (
3441
void
@@ -50,6 +57,7 @@ NoteSerial_Arduino::reset (
5057
void
5158
)
5259
{
60+
_notecardSerial.end();
5361
_notecardSerial.begin(_notecardSerialSpeed);
5462

5563
return true;

src/NoteSerial_Arduino.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class NoteSerial_Arduino final : public NoteSerial
2525
{
2626
public:
2727
NoteSerial_Arduino(HardwareSerial & hw_serial_, size_t baud_rate_);
28+
~NoteSerial_Arduino(void);
2829
size_t available(void) override;
2930
char receive(void) override;
3031
bool reset(void) override;

src/Notecard.cpp

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ void noteTransactionStop (void) {
186186
The TwoWire implementation to use for I2C communication.
187187
*/
188188
/**************************************************************************/
189-
void Notecard::platformInit (bool assignCallbacks)
189+
void Notecard::platformInit (bool assignCallbacks) const
190190
{
191-
NoteSetUserAgent((char *)"note-arduino");
191+
NoteSetUserAgent((char *) ("note-arduino " NOTE_ARDUINO_VERSION));
192192
if (assignCallbacks) {
193193
NoteSetFnDefault(malloc, free, noteDelay, noteMillis);
194194
} else {
@@ -225,7 +225,7 @@ Notecard::~Notecard (void)
225225
appropriately for the host.
226226
*/
227227
/**************************************************************************/
228-
void Notecard::begin(NoteI2c * noteI2c_, uint32_t i2cAddress_, uint32_t i2cMax_)
228+
void Notecard::begin(NoteI2c * noteI2c_, uint32_t i2cAddress_, uint32_t i2cMax_) const
229229
{
230230
noteI2c = noteI2c_;
231231
platformInit(noteI2c);
@@ -247,7 +247,7 @@ void Notecard::begin(NoteI2c * noteI2c_, uint32_t i2cAddress_, uint32_t i2cMax_)
247247
communicating with the Notecard from the host.
248248
*/
249249
/**************************************************************************/
250-
void Notecard::begin(NoteSerial * noteSerial_)
250+
void Notecard::begin(NoteSerial * noteSerial_) const
251251
{
252252
noteSerial = noteSerial_;
253253
platformInit(noteSerial);
@@ -273,7 +273,7 @@ void Notecard::begin(NoteSerial * noteSerial_)
273273
@brief Clear the debug output source.
274274
*/
275275
/**************************************************************************/
276-
void Notecard::clearDebugOutputStream(void)
276+
void Notecard::clearDebugOutputStream(void) const
277277
{
278278
setDebugOutputStream(nullptr);
279279
}
@@ -290,7 +290,7 @@ void Notecard::clearDebugOutputStream(void)
290290
@return `True` if a pending response was displayed to the debug stream.
291291
*/
292292
/**************************************************************************/
293-
bool Notecard::debugSyncStatus(int pollFrequencyMs, int maxLevel)
293+
bool Notecard::debugSyncStatus(int pollFrequencyMs, int maxLevel) const
294294
{
295295
return NoteDebugSyncStatus(pollFrequencyMs, maxLevel);
296296
}
@@ -302,11 +302,32 @@ bool Notecard::debugSyncStatus(int pollFrequencyMs, int maxLevel)
302302
A `J` JSON response object.
303303
*/
304304
/**************************************************************************/
305-
void Notecard::deleteResponse(J *rsp)
305+
void Notecard::deleteResponse(J *rsp) const
306306
{
307307
NoteDeleteResponse(rsp);
308308
}
309309

310+
/**************************************************************************/
311+
/*!
312+
@brief Deinitialize the Notecard object communication.
313+
This function clears the Notecard object's communication
314+
interfaces, and frees all associated memory.
315+
*/
316+
/**************************************************************************/
317+
void Notecard::end(void) const
318+
{
319+
// Clear Communication Interfaces
320+
NoteSetFnI2C(0, 0, nullptr, nullptr, nullptr);
321+
NoteSetFnSerial(nullptr, nullptr, nullptr, nullptr);
322+
323+
// Clear Platform Callbacks
324+
platformInit(false);
325+
326+
// Delete Singletons
327+
noteI2c = make_note_i2c(nullptr);
328+
noteSerial = make_note_serial(nullptr);
329+
}
330+
310331
/**************************************************************************/
311332
/*!
312333
@deprecated NoteDebug, which this function wraps, should be treated as an
@@ -317,7 +338,7 @@ void Notecard::deleteResponse(J *rsp)
317338
A string to log to the serial debug stream.
318339
*/
319340
/**************************************************************************/
320-
NOTE_ARDUINO_DEPRECATED void Notecard::logDebug(const char *message)
341+
NOTE_ARDUINO_DEPRECATED void Notecard::logDebug(const char *message) const
321342
{
322343
#ifdef NOTE_ARDUINO_NO_DEPRECATED_ATTR
323344
NOTE_C_LOG_WARN("logDebug is deprecated.")
@@ -336,7 +357,7 @@ NOTE_ARDUINO_DEPRECATED void Notecard::logDebug(const char *message)
336357
@param ... one or more values to interpolate into the format string.
337358
*/
338359
/**************************************************************************/
339-
NOTE_ARDUINO_DEPRECATED void Notecard::logDebugf(const char *format, ...)
360+
NOTE_ARDUINO_DEPRECATED void Notecard::logDebugf(const char *format, ...) const
340361
{
341362
char message[256];
342363
va_list args;
@@ -360,7 +381,7 @@ NOTE_ARDUINO_DEPRECATED void Notecard::logDebugf(const char *format, ...)
360381
@return A `J` JSON Object populated with the request name.
361382
*/
362383
/**************************************************************************/
363-
J *Notecard::newCommand(const char *request)
384+
J *Notecard::newCommand(const char *request) const
364385
{
365386
return NoteNewCommand(request);
366387
}
@@ -375,7 +396,7 @@ J *Notecard::newCommand(const char *request)
375396
@return A `J` JSON Object populated with the request name.
376397
*/
377398
/**************************************************************************/
378-
J *Notecard::newRequest(const char *request)
399+
J *Notecard::newRequest(const char *request) const
379400
{
380401
return NoteNewRequest(request);
381402
}
@@ -390,7 +411,7 @@ J *Notecard::newRequest(const char *request)
390411
@return `J` JSON Object with the response from the Notecard.
391412
*/
392413
/**************************************************************************/
393-
J *Notecard::requestAndResponse(J *req)
414+
J *Notecard::requestAndResponse(J *req) const
394415
{
395416
return NoteRequestResponse(req);
396417
}
@@ -406,7 +427,7 @@ J *Notecard::requestAndResponse(J *req)
406427
@return `J` JSON Object with the response from the Notecard.
407428
*/
408429
/**************************************************************************/
409-
J *Notecard::requestAndResponseWithRetry(J *req, uint32_t timeoutSeconds)
430+
J *Notecard::requestAndResponseWithRetry(J *req, uint32_t timeoutSeconds) const
410431
{
411432
return NoteRequestResponseWithRetry(req, timeoutSeconds);
412433
}
@@ -419,7 +440,7 @@ J *Notecard::requestAndResponseWithRetry(J *req, uint32_t timeoutSeconds)
419440
@return `true` if the response object contains an error.
420441
*/
421442
/**************************************************************************/
422-
bool Notecard::responseError(J *rsp)
443+
bool Notecard::responseError(J *rsp) const
423444
{
424445
return NoteResponseError(rsp);
425446
}
@@ -435,7 +456,7 @@ bool Notecard::responseError(J *rsp)
435456
`False` if there was an error.
436457
*/
437458
/**************************************************************************/
438-
bool Notecard::sendRequest(J *req)
459+
bool Notecard::sendRequest(J *req) const
439460
{
440461
return NoteRequest(req);
441462
}
@@ -452,7 +473,7 @@ bool Notecard::sendRequest(J *req)
452473
`False` if the message couldn't be sent.
453474
*/
454475
/**************************************************************************/
455-
bool Notecard::sendRequestWithRetry(J *req, uint32_t timeoutSeconds)
476+
bool Notecard::sendRequestWithRetry(J *req, uint32_t timeoutSeconds) const
456477
{
457478
return NoteRequestWithRetry(req, timeoutSeconds);
458479
}
@@ -469,7 +490,7 @@ bool Notecard::sendRequestWithRetry(J *req, uint32_t timeoutSeconds)
469490
debug output.
470491
*/
471492
/**************************************************************************/
472-
void Notecard::setDebugOutputStream(NoteLog * noteLog_)
493+
void Notecard::setDebugOutputStream(NoteLog * noteLog_) const
473494
{
474495
noteLog = noteLog_;
475496
if (noteLog) {
@@ -492,7 +513,7 @@ void Notecard::setDebugOutputStream(NoteLog * noteLog_)
492513
I2C bus taken during the call to `lockI2cFn()`.
493514
*/
494515
/**************************************************************************/
495-
void Notecard::setFnI2cMutex(mutexFn lockI2cFn_, mutexFn unlockI2cFn_) {
516+
void Notecard::setFnI2cMutex(mutexFn lockI2cFn_, mutexFn unlockI2cFn_) const {
496517
NoteSetFnI2CMutex(lockI2cFn_, unlockI2cFn_);
497518
}
498519

@@ -509,7 +530,7 @@ void Notecard::setFnI2cMutex(mutexFn lockI2cFn_, mutexFn unlockI2cFn_) {
509530
Notecard transaction taken during the call to `lockNoteFn()`.
510531
*/
511532
/**************************************************************************/
512-
void Notecard::setFnNoteMutex(mutexFn lockNoteFn_, mutexFn unlockNoteFn_) {
533+
void Notecard::setFnNoteMutex(mutexFn lockNoteFn_, mutexFn unlockNoteFn_) const {
513534
NoteSetFnNoteMutex(lockNoteFn_, unlockNoteFn_);
514535
}
515536

@@ -528,7 +549,7 @@ void Notecard::setFnNoteMutex(mutexFn lockNoteFn_, mutexFn unlockNoteFn_) {
528549
A platform specific tuple of digital I/O pins.
529550
*/
530551
/**************************************************************************/
531-
void Notecard::setTransactionPins(NoteTxn * noteTxn_) {
552+
void Notecard::setTransactionPins(NoteTxn * noteTxn_) const {
532553
noteTxn = noteTxn_; // Set global interface
533554
if (noteTxn_) {
534555
NoteSetFnTransaction(noteTransactionStart, noteTransactionStop);

0 commit comments

Comments
 (0)