Skip to content
Open
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
6 changes: 3 additions & 3 deletions onewire_bus/src/onewire_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,9 @@ esp_err_t onewire_device_iter_get_next(onewire_device_iter_handle_t iter, onewir
}, 1), TAG, "send ONEWIRE_CMD_SEARCH_NORMAL failed");

uint8_t last_zero = 0;
Copy link
Preview

Copilot AI May 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider adding a comment to explain why the loop index now starts at 1 and goes through (sizeof(onewire_device_address_t) * 8) + 1. This will improve code clarity for future maintainers regarding the off-by-one adjustment in bit indexing.

Suggested change
uint8_t last_zero = 0;
uint8_t last_zero = 0;
// The loop index starts at 1 and goes through (sizeof(onewire_device_address_t) * 8) + 1
// because bit indexing in the 1-Wire protocol starts from 1. The logic inside the loop
// adjusts for this by subtracting 1 when calculating rom_byte_index and rom_bit_mask.

Copilot uses AI. Check for mistakes.

for (uint16_t rom_bit_index = 0; rom_bit_index < sizeof(onewire_device_address_t) * 8; rom_bit_index ++) {
uint8_t rom_byte_index = rom_bit_index / 8;
uint8_t rom_bit_mask = 1 << (rom_bit_index % 8); // calculate byte index and bit mask in advance for convenience
for (uint16_t rom_bit_index = 1; rom_bit_index < ((sizeof(onewire_device_address_t) * 8) + 1); rom_bit_index++) {
uint8_t rom_byte_index = (rom_bit_index - 1) / 8;
uint8_t rom_bit_mask = 1 << ((rom_bit_index - 1) % 8); // calculate byte index and bit mask in advance for convenience

uint8_t rom_bit = 0;
uint8_t rom_bit_complement = 0;
Expand Down