comparison 1wire.c @ 39:969bb070b181

- Remove superfluous debug message. - Remove unecessary indent.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 01 Apr 2013 19:45:38 +1030
parents 96c345d304af
children cc998b0b2bae
comparison
equal deleted inserted replaced
38:38869c474104 39:969bb070b181
305 bit_test |= OWReadBit(); 305 bit_test |= OWReadBit();
306 306
307 OWPRINTFP(PSTR("bit_test = %d\r\n"), bit_test); 307 OWPRINTFP(PSTR("bit_test = %d\r\n"), bit_test);
308 308
309 /* check for no devices on 1-wire */ 309 /* check for no devices on 1-wire */
310 if (bit_test == 3) { 310 if (bit_test == 3)
311 OWPRINTFP(PSTR("bit_test = %d\r\n"), bit_test);
312 return(OW_BADWIRE); 311 return(OW_BADWIRE);
312
313 /* all devices coupled have 0 or 1 */
314 if (bit_test > 0)
315 search_direction = !(bit_test & 0x01); /* bit write value for search */
316 else {
317 /* if this discrepancy is before the Last Discrepancy
318 * on a previous OWNext then pick the same as last time */
319 if (bit_number < OW_LastDiscrepancy)
320 search_direction = ((ROM[rom_byte_number] & rom_byte_mask) > 0);
321 else
322 /* if equal to last pick 1, if not then pick 0 */
323 search_direction = (bit_number == OW_LastDiscrepancy);
324
325 /* if 0 was picked then record its position in LastZero */
326 if (search_direction == 0) {
327 last_zero = bit_number;
328
329 /* check for Last discrepancy in family */
330 if (last_zero < 9)
331 OW_LastFamilyDiscrepancy = last_zero;
332 }
313 } 333 }
314 else { 334
315 /* all devices coupled have 0 or 1 */ 335 /* set or clear the bit in the ROM byte rom_byte_number
316 if (bit_test > 0) 336 * with mask rom_byte_mask */
317 search_direction = !(bit_test & 0x01); /* bit write value for search */ 337 if (search_direction == 1)
318 else { 338 ROM[rom_byte_number] |= rom_byte_mask;
319 /* if this discrepancy is before the Last Discrepancy 339 else
320 * on a previous OWNext then pick the same as last time */ 340 ROM[rom_byte_number] &= ~rom_byte_mask;
321 if (bit_number < OW_LastDiscrepancy) 341
322 search_direction = ((ROM[rom_byte_number] & rom_byte_mask) > 0); 342 /* serial number search direction write bit */
323 else 343 OWWriteBit(search_direction);
324 /* if equal to last pick 1, if not then pick 0 */ 344
325 search_direction = (bit_number == OW_LastDiscrepancy); 345 /* increment the byte counter bit_number
326 346 * and shift the mask rom_byte_mask */
327 /* if 0 was picked then record its position in LastZero */ 347 bit_number++;
328 if (search_direction == 0) { 348 rom_byte_mask <<= 1;
329 last_zero = bit_number; 349
330 350 /* if the mask is 0 then go to new ROM byte rom_byte_number
331 /* check for Last discrepancy in family */ 351 * and reset mask */
332 if (last_zero < 9) 352 if (rom_byte_mask == 0) {
333 OW_LastFamilyDiscrepancy = last_zero; 353 OWCRC(ROM[rom_byte_number], &crcaccum); /* accumulate the CRC */
334 } 354 lastcrc8 = crcaccum;
335 }
336
337 /* set or clear the bit in the ROM byte rom_byte_number
338 * with mask rom_byte_mask */
339 if (search_direction == 1)
340 ROM[rom_byte_number] |= rom_byte_mask;
341 else
342 ROM[rom_byte_number] &= ~rom_byte_mask;
343
344 /* serial number search direction write bit */
345 OWWriteBit(search_direction);
346
347 /* increment the byte counter bit_number
348 * and shift the mask rom_byte_mask */
349 bit_number++;
350 rom_byte_mask <<= 1;
351
352 /* if the mask is 0 then go to new ROM byte rom_byte_number
353 * and reset mask */
354 if (rom_byte_mask == 0) {
355 OWCRC(ROM[rom_byte_number], &crcaccum); /* accumulate the CRC */
356 lastcrc8 = crcaccum;
357 355
358 rom_byte_number++; 356 rom_byte_number++;
359 rom_byte_mask = 1; 357 rom_byte_mask = 1;
360 }
361 } 358 }
362 } while (rom_byte_number < 8); /* loop until through all ROM bytes 0-7 */ 359 } while (rom_byte_number < 8); /* loop until through all ROM bytes 0-7 */
363 360
364 /* if the search was successful then */ 361 /* if the search was successful then */
365 if (!(bit_number < 65) || lastcrc8) { 362 if (!(bit_number < 65) || lastcrc8) {