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

onewire: Implement scan for multiple devices #139

Merged
merged 6 commits into from
Sep 28, 2022
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Rework "int search_result" to proper "bool device_found_p"
  • Loading branch information
jbglaw committed Sep 27, 2022
commit 74a30336f9c41780befe950f173fcf846cf86cae
13 changes: 7 additions & 6 deletions src/hydrabus/hydrabus_mode_onewire.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ static uint8_t onewire_crc8(uint8_t value, struct onewire_scan_state *state)
static bool onewire_search(t_hydra_console *con, struct onewire_scan_state *state, enum onewire_scan_mode mode)
jbglaw marked this conversation as resolved.
Show resolved Hide resolved
{
int id_bit_number;
int last_zero, rom_byte_number, search_result;
int last_zero, rom_byte_number;
bool device_found_p;
int id_bit, cmp_id_bit;
unsigned char rom_byte_mask, search_direction;

Expand All @@ -241,7 +242,7 @@ static bool onewire_search(t_hydra_console *con, struct onewire_scan_state *stat
last_zero = 0;
rom_byte_number = 0;
rom_byte_mask = 1;
search_result = 0;
device_found_p = false;
state->crc8 = 0;

/* If the last call was not the last one. */
Expand Down Expand Up @@ -316,23 +317,23 @@ static bool onewire_search(t_hydra_console *con, struct onewire_scan_state *stat

/* If the search was successful then... */
if(!((id_bit_number < 65) || (state->crc8 != 0))) {
/* ...search successful so set last_discrepancy,last_device_p,search_result. */
/* ...search successful so set last_discrepancy,last_device_p,device_found_p. */
state->last_discrepancy = last_zero;

/* Check for last device. */
if (state->last_discrepancy == 0)
state->last_device_p = true;

search_result = true;
device_found_p = true;
}
}

/* If no device found then reset counters so next 'search' will be like a first. */
if(!search_result || !state->ROM_ADDR[0]) {
if(!device_found_p || !state->ROM_ADDR[0]) {
state->last_discrepancy = 0;
state->last_device_p = false;
state->last_family_discrepancy = 0;
search_result = false;
device_found_p = false;
}

return search_result;
jbglaw marked this conversation as resolved.
Show resolved Hide resolved
Expand Down