Skip to content

Commit

Permalink
v1.6.0 (#129)
Browse files Browse the repository at this point in the history
* 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()`
  • Loading branch information
zfields authored Jun 24, 2024
1 parent f0d8357 commit db721b3
Show file tree
Hide file tree
Showing 26 changed files with 746 additions and 556 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@

// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-vscode.cpptools"
"ms-vscode.cpptools",
"shardulm94.trailing-spaces"
]

// Use 'forwardPorts' to make a list of ports inside the container available locally.
Expand Down
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,19 @@ if (rsp != NULL) {

## Keeping up to date with note-c repo

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

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

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

## Documentation

The documentation for this library can be found
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Blues Wireless Notecard
version=1.5.4
version=1.6.0
author=Blues
maintainer=Blues <info@blues.com>
sentence=An easy to use Notecard Library for Arduino.
Expand Down
9 changes: 7 additions & 2 deletions scripts/update_note_c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,27 @@ pushd $ROOT_DIR
rm -rf src/note-c
# Commit the changes so that the next git subtree command doesn't complain about
# changes in the working tree.
git commit -am 'remove note-c before re-add'
git commit -am 'Remove `note-c` before re-add'
# Check out the note-c subtree using the given ref or master if not specified.
git subtree add --prefix=src/note-c --squash https://github.com/blues/note-c.git $REF

# Remove all the unneeded directories from the subtree.
NOTE_C_DIR="$ROOT_DIR/src/note-c"
NOTE_C_UNNEEDED_DIRS=(
"$NOTE_C_DIR/.devcontainer"
"$NOTE_C_DIR/.github"
"$NOTE_C_DIR/.vscode"
"$NOTE_C_DIR/assets"
"$NOTE_C_DIR/docs"
"$NOTE_C_DIR/scripts"
"$NOTE_C_DIR/test"
"$NOTE_C_DIR/.github"
)
for DIR in "${NOTE_C_UNNEEDED_DIRS[@]}"; do
rm -rf "$DIR"
done

# Commit the removal of unneeded directories.
git commit -am 'Remove unneeded directories from `note-c`'

# Return to original directory.
popd
9 changes: 9 additions & 0 deletions src/NoteI2c_Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,15 @@ NoteI2c_Arduino::NoteI2c_Arduino
_i2cPort.begin();
}

NoteI2c_Arduino::~NoteI2c_Arduino (
void
)
{
#if WIRE_HAS_END
_i2cPort.end();
#endif
}

const char *
NoteI2c_Arduino::receive (
uint16_t device_address_,
Expand Down
1 change: 1 addition & 0 deletions src/NoteI2c_Arduino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class NoteI2c_Arduino final : public NoteI2c
{
public:
NoteI2c_Arduino(TwoWire & i2c_bus);
~NoteI2c_Arduino(void);
const char * receive(uint16_t device_address, uint8_t * buffer, uint16_t requested_byte_count, uint32_t * available) override;
bool reset(uint16_t device_address) override;
const char * transmit(uint16_t device_address, uint8_t * buffer, uint16_t size) override;
Expand Down
8 changes: 8 additions & 0 deletions src/NoteSerial_Arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ NoteSerial_Arduino::NoteSerial_Arduino
_notecardSerial.begin(_notecardSerialSpeed);
}

NoteSerial_Arduino::~NoteSerial_Arduino (
void
)
{
_notecardSerial.end();
}

size_t
NoteSerial_Arduino::available (
void
Expand All @@ -50,6 +57,7 @@ NoteSerial_Arduino::reset (
void
)
{
_notecardSerial.end();
_notecardSerial.begin(_notecardSerialSpeed);

return true;
Expand Down
1 change: 1 addition & 0 deletions src/NoteSerial_Arduino.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class NoteSerial_Arduino final : public NoteSerial
{
public:
NoteSerial_Arduino(HardwareSerial & hw_serial_, size_t baud_rate_);
~NoteSerial_Arduino(void);
size_t available(void) override;
char receive(void) override;
bool reset(void) override;
Expand Down
61 changes: 41 additions & 20 deletions src/Notecard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ void noteTransactionStop (void) {
The TwoWire implementation to use for I2C communication.
*/
/**************************************************************************/
void Notecard::platformInit (bool assignCallbacks)
void Notecard::platformInit (bool assignCallbacks) const
{
NoteSetUserAgent((char *)"note-arduino");
NoteSetUserAgent((char *) ("note-arduino " NOTE_ARDUINO_VERSION));
if (assignCallbacks) {
NoteSetFnDefault(malloc, free, noteDelay, noteMillis);
} else {
Expand Down Expand Up @@ -225,7 +225,7 @@ Notecard::~Notecard (void)
appropriately for the host.
*/
/**************************************************************************/
void Notecard::begin(NoteI2c * noteI2c_, uint32_t i2cAddress_, uint32_t i2cMax_)
void Notecard::begin(NoteI2c * noteI2c_, uint32_t i2cAddress_, uint32_t i2cMax_) const
{
noteI2c = noteI2c_;
platformInit(noteI2c);
Expand All @@ -247,7 +247,7 @@ void Notecard::begin(NoteI2c * noteI2c_, uint32_t i2cAddress_, uint32_t i2cMax_)
communicating with the Notecard from the host.
*/
/**************************************************************************/
void Notecard::begin(NoteSerial * noteSerial_)
void Notecard::begin(NoteSerial * noteSerial_) const
{
noteSerial = noteSerial_;
platformInit(noteSerial);
Expand All @@ -273,7 +273,7 @@ void Notecard::begin(NoteSerial * noteSerial_)
@brief Clear the debug output source.
*/
/**************************************************************************/
void Notecard::clearDebugOutputStream(void)
void Notecard::clearDebugOutputStream(void) const
{
setDebugOutputStream(nullptr);
}
Expand All @@ -290,7 +290,7 @@ void Notecard::clearDebugOutputStream(void)
@return `True` if a pending response was displayed to the debug stream.
*/
/**************************************************************************/
bool Notecard::debugSyncStatus(int pollFrequencyMs, int maxLevel)
bool Notecard::debugSyncStatus(int pollFrequencyMs, int maxLevel) const
{
return NoteDebugSyncStatus(pollFrequencyMs, maxLevel);
}
Expand All @@ -302,11 +302,32 @@ bool Notecard::debugSyncStatus(int pollFrequencyMs, int maxLevel)
A `J` JSON response object.
*/
/**************************************************************************/
void Notecard::deleteResponse(J *rsp)
void Notecard::deleteResponse(J *rsp) const
{
NoteDeleteResponse(rsp);
}

/**************************************************************************/
/*!
@brief Deinitialize the Notecard object communication.
This function clears the Notecard object's communication
interfaces, and frees all associated memory.
*/
/**************************************************************************/
void Notecard::end(void) const
{
// Clear Communication Interfaces
NoteSetFnI2C(0, 0, nullptr, nullptr, nullptr);
NoteSetFnSerial(nullptr, nullptr, nullptr, nullptr);

// Clear Platform Callbacks
platformInit(false);

// Delete Singletons
noteI2c = make_note_i2c(nullptr);
noteSerial = make_note_serial(nullptr);
}

/**************************************************************************/
/*!
@deprecated NoteDebug, which this function wraps, should be treated as an
Expand All @@ -317,7 +338,7 @@ void Notecard::deleteResponse(J *rsp)
A string to log to the serial debug stream.
*/
/**************************************************************************/
NOTE_ARDUINO_DEPRECATED void Notecard::logDebug(const char *message)
NOTE_ARDUINO_DEPRECATED void Notecard::logDebug(const char *message) const
{
#ifdef NOTE_ARDUINO_NO_DEPRECATED_ATTR
NOTE_C_LOG_WARN("logDebug is deprecated.")
Expand All @@ -336,7 +357,7 @@ NOTE_ARDUINO_DEPRECATED void Notecard::logDebug(const char *message)
@param ... one or more values to interpolate into the format string.
*/
/**************************************************************************/
NOTE_ARDUINO_DEPRECATED void Notecard::logDebugf(const char *format, ...)
NOTE_ARDUINO_DEPRECATED void Notecard::logDebugf(const char *format, ...) const
{
char message[256];
va_list args;
Expand All @@ -360,7 +381,7 @@ NOTE_ARDUINO_DEPRECATED void Notecard::logDebugf(const char *format, ...)
@return A `J` JSON Object populated with the request name.
*/
/**************************************************************************/
J *Notecard::newCommand(const char *request)
J *Notecard::newCommand(const char *request) const
{
return NoteNewCommand(request);
}
Expand All @@ -375,7 +396,7 @@ J *Notecard::newCommand(const char *request)
@return A `J` JSON Object populated with the request name.
*/
/**************************************************************************/
J *Notecard::newRequest(const char *request)
J *Notecard::newRequest(const char *request) const
{
return NoteNewRequest(request);
}
Expand All @@ -390,7 +411,7 @@ J *Notecard::newRequest(const char *request)
@return `J` JSON Object with the response from the Notecard.
*/
/**************************************************************************/
J *Notecard::requestAndResponse(J *req)
J *Notecard::requestAndResponse(J *req) const
{
return NoteRequestResponse(req);
}
Expand All @@ -406,7 +427,7 @@ J *Notecard::requestAndResponse(J *req)
@return `J` JSON Object with the response from the Notecard.
*/
/**************************************************************************/
J *Notecard::requestAndResponseWithRetry(J *req, uint32_t timeoutSeconds)
J *Notecard::requestAndResponseWithRetry(J *req, uint32_t timeoutSeconds) const
{
return NoteRequestResponseWithRetry(req, timeoutSeconds);
}
Expand All @@ -419,7 +440,7 @@ J *Notecard::requestAndResponseWithRetry(J *req, uint32_t timeoutSeconds)
@return `true` if the response object contains an error.
*/
/**************************************************************************/
bool Notecard::responseError(J *rsp)
bool Notecard::responseError(J *rsp) const
{
return NoteResponseError(rsp);
}
Expand All @@ -435,7 +456,7 @@ bool Notecard::responseError(J *rsp)
`False` if there was an error.
*/
/**************************************************************************/
bool Notecard::sendRequest(J *req)
bool Notecard::sendRequest(J *req) const
{
return NoteRequest(req);
}
Expand All @@ -452,7 +473,7 @@ bool Notecard::sendRequest(J *req)
`False` if the message couldn't be sent.
*/
/**************************************************************************/
bool Notecard::sendRequestWithRetry(J *req, uint32_t timeoutSeconds)
bool Notecard::sendRequestWithRetry(J *req, uint32_t timeoutSeconds) const
{
return NoteRequestWithRetry(req, timeoutSeconds);
}
Expand All @@ -469,7 +490,7 @@ bool Notecard::sendRequestWithRetry(J *req, uint32_t timeoutSeconds)
debug output.
*/
/**************************************************************************/
void Notecard::setDebugOutputStream(NoteLog * noteLog_)
void Notecard::setDebugOutputStream(NoteLog * noteLog_) const
{
noteLog = noteLog_;
if (noteLog) {
Expand All @@ -492,7 +513,7 @@ void Notecard::setDebugOutputStream(NoteLog * noteLog_)
I2C bus taken during the call to `lockI2cFn()`.
*/
/**************************************************************************/
void Notecard::setFnI2cMutex(mutexFn lockI2cFn_, mutexFn unlockI2cFn_) {
void Notecard::setFnI2cMutex(mutexFn lockI2cFn_, mutexFn unlockI2cFn_) const {
NoteSetFnI2CMutex(lockI2cFn_, unlockI2cFn_);
}

Expand All @@ -509,7 +530,7 @@ void Notecard::setFnI2cMutex(mutexFn lockI2cFn_, mutexFn unlockI2cFn_) {
Notecard transaction taken during the call to `lockNoteFn()`.
*/
/**************************************************************************/
void Notecard::setFnNoteMutex(mutexFn lockNoteFn_, mutexFn unlockNoteFn_) {
void Notecard::setFnNoteMutex(mutexFn lockNoteFn_, mutexFn unlockNoteFn_) const {
NoteSetFnNoteMutex(lockNoteFn_, unlockNoteFn_);
}

Expand All @@ -528,7 +549,7 @@ void Notecard::setFnNoteMutex(mutexFn lockNoteFn_, mutexFn unlockNoteFn_) {
A platform specific tuple of digital I/O pins.
*/
/**************************************************************************/
void Notecard::setTransactionPins(NoteTxn * noteTxn_) {
void Notecard::setTransactionPins(NoteTxn * noteTxn_) const {
noteTxn = noteTxn_; // Set global interface
if (noteTxn_) {
NoteSetFnTransaction(noteTransactionStart, noteTransactionStop);
Expand Down
Loading

0 comments on commit db721b3

Please sign in to comment.