Skip to content

Add optional addressBook output to begin() to capture discovered ROM addresses#292

Open
blah188 wants to merge 1 commit into
milesburton:masterfrom
blah188:begin-addressbook
Open

Add optional addressBook output to begin() to capture discovered ROM addresses#292
blah188 wants to merge 1 commit into
milesburton:masterfrom
blah188:begin-addressbook

Conversation

@blah188

@blah188 blah188 commented Jun 26, 2026

Copy link
Copy Markdown

Motivation

begin() already enumerates the bus (it searches and counts devices), but the discovered ROM addresses are dropped — they live only in a local variable. Callers that need the addresses must call getAddress(addr, index) afterwards, which runs a second SearchROM pass. On long or electrically marginal 1-Wire buses that second pass can intermittently fail (returns a zero / CRC-invalid ROM) even though begin()'s own search just succeeded — so a device that was counted can't be addressed.

Change

Add two optional, defaulted parameters:

void begin(uint8_t* addressBook = nullptr, uint8_t maxDeviceCount = 0);

When addressBook is provided, each valid ROM found during enumeration is copied into it (in discovery order, up to maxDeviceCount). This lets the caller reuse the addresses captured by the search that already ran, instead of re-discovering them with a second, less reliable search pass.

Backward compatibility

Fully backward compatible — with no arguments begin() behaves exactly as before (nothing is written). No change to any existing call site or behavior.

Example

DeviceAddress book[4];
sensors.begin(&book[0][0], 4);            // addresses captured during enumeration
uint8_t n = sensors.getDeviceCount();
float t = sensors.getTempC(book[0]);      // read by stored address, no re-search

begin() already enumerates the bus but drops the ROM addresses it finds. Callers that need the addresses must run a second SearchROM via getAddress(), which can fail intermittently on long or marginal 1-Wire buses even though begin()'s own search just succeeded.

Add two optional, defaulted parameters so begin() can copy each valid ROM found during enumeration into a caller-provided buffer (in discovery order, up to maxDeviceCount). Fully backward compatible: with no arguments begin() behaves exactly as before.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants