# HG changeset patch # User Daniel O'Connor # Date 1364807738 -37800 # Node ID 969bb070b181e823207921e119a156457bf6938c # Parent 38869c47410499f161b9d11a2e9b8735cbfffae7 - Remove superfluous debug message. - Remove unecessary indent. diff -r 38869c474104 -r 969bb070b181 1wire.c --- a/1wire.c Mon Apr 01 19:45:19 2013 +1030 +++ b/1wire.c Mon Apr 01 19:45:38 2013 +1030 @@ -307,57 +307,54 @@ OWPRINTFP(PSTR("bit_test = %d\r\n"), bit_test); /* check for no devices on 1-wire */ - if (bit_test == 3) { - OWPRINTFP(PSTR("bit_test = %d\r\n"), bit_test); + if (bit_test == 3) return(OW_BADWIRE); - } + + /* all devices coupled have 0 or 1 */ + if (bit_test > 0) + search_direction = !(bit_test & 0x01); /* bit write value for search */ else { - /* all devices coupled have 0 or 1 */ - if (bit_test > 0) - search_direction = !(bit_test & 0x01); /* bit write value for search */ - else { - /* if this discrepancy is before the Last Discrepancy - * on a previous OWNext then pick the same as last time */ - if (bit_number < OW_LastDiscrepancy) - search_direction = ((ROM[rom_byte_number] & rom_byte_mask) > 0); - else - /* if equal to last pick 1, if not then pick 0 */ - search_direction = (bit_number == OW_LastDiscrepancy); + /* if this discrepancy is before the Last Discrepancy + * on a previous OWNext then pick the same as last time */ + if (bit_number < OW_LastDiscrepancy) + search_direction = ((ROM[rom_byte_number] & rom_byte_mask) > 0); + else + /* if equal to last pick 1, if not then pick 0 */ + search_direction = (bit_number == OW_LastDiscrepancy); - /* if 0 was picked then record its position in LastZero */ - if (search_direction == 0) { - last_zero = bit_number; + /* if 0 was picked then record its position in LastZero */ + if (search_direction == 0) { + last_zero = bit_number; - /* check for Last discrepancy in family */ - if (last_zero < 9) - OW_LastFamilyDiscrepancy = last_zero; - } + /* check for Last discrepancy in family */ + if (last_zero < 9) + OW_LastFamilyDiscrepancy = last_zero; } + } - /* set or clear the bit in the ROM byte rom_byte_number - * with mask rom_byte_mask */ - if (search_direction == 1) - ROM[rom_byte_number] |= rom_byte_mask; - else - ROM[rom_byte_number] &= ~rom_byte_mask; + /* set or clear the bit in the ROM byte rom_byte_number + * with mask rom_byte_mask */ + if (search_direction == 1) + ROM[rom_byte_number] |= rom_byte_mask; + else + ROM[rom_byte_number] &= ~rom_byte_mask; - /* serial number search direction write bit */ - OWWriteBit(search_direction); + /* serial number search direction write bit */ + OWWriteBit(search_direction); - /* increment the byte counter bit_number - * and shift the mask rom_byte_mask */ - bit_number++; - rom_byte_mask <<= 1; + /* increment the byte counter bit_number + * and shift the mask rom_byte_mask */ + bit_number++; + rom_byte_mask <<= 1; - /* if the mask is 0 then go to new ROM byte rom_byte_number - * and reset mask */ - if (rom_byte_mask == 0) { - OWCRC(ROM[rom_byte_number], &crcaccum); /* accumulate the CRC */ - lastcrc8 = crcaccum; + /* if the mask is 0 then go to new ROM byte rom_byte_number + * and reset mask */ + if (rom_byte_mask == 0) { + OWCRC(ROM[rom_byte_number], &crcaccum); /* accumulate the CRC */ + lastcrc8 = crcaccum; - rom_byte_number++; - rom_byte_mask = 1; - } + rom_byte_number++; + rom_byte_mask = 1; } } while (rom_byte_number < 8); /* loop until through all ROM bytes 0-7 */