Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow bypassing address validation in HT16K33 code to address Issue #1834 #1835

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions docs/led-digits-clock-HT16K33.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,39 @@ function time(showColon) {



## Additional Options
### Specifying Addresses
You can specify the addresses to use for the controller:
```
const digits = new Led.Digits({
controller: "HT16K33",
address: 0x70,
});
```

### Bypassing Address Validation
Led.Digits will ensure that you do not use the same address twice,
but if you use multiple Arduino boards you want to reuse the same address.
You can use the `skipAddressValidation` option to bypass this check:
```
const digitsA = new Led.Digits({
controller: "HT16K33",
board: boards.byId("A"),
address: 0x70,
skipAddressValidation: true,
});
const digitsB = new Led.Digits({
controller: "HT16K33",
board: boards.byId("B"),
address: 0x70,
skipAddressValidation: true,
});
```






## Additional Notes
Learn More:
Expand Down
18 changes: 12 additions & 6 deletions lib/led/ledcontrol.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const priv = new Map();
* @param {Boolean} [options.colon] Whether the device has a built in colon.
* @param {Number} [options.devices] The number of connected LED devices.
* @param {Array} [options.addresses] I2C addresses.
* @param {Boolean} [options.skipAddressValidation] Bypass address checking and incrementing.
* Use this when using multiple HT16K33 but at the same address
* on multiple Arduino or other type boards.
* You should also include the address or addresses when using this.
* @param {*} options.pins The digital pin numbers that connect to
* data, clock, and cs connections on the controller device.
* Only for use with the default controller.
Expand Down Expand Up @@ -454,12 +458,14 @@ const Controllers = {
this.addresses = available.slice(0, state.devices);
}

this.addresses.forEach(address => {
if (!addresses.has(address)) {
throw new Error(`Invalid HT16K33 controller address: ${address}`);
}
addresses.delete(address);
});
if (!options.skipAddressValidation) {
this.addresses.forEach(address => {
if (!addresses.has(address)) {
throw new Error(`Invalid HT16K33 controller address: ${address}`);
}
addresses.delete(address);
});
}

this.rotation = options.rotation || 1;
// set a default rotation that works with AdaFruit 16x8 matrix if using 16 columns
Expand Down