From 6af633895c382065e541a22019da6259a48a4869 Mon Sep 17 00:00:00 2001 From: PaulStoffregen Date: Sun, 6 Dec 2015 01:36:33 -0800 Subject: [PATCH] Support conditional search --- OneWire.cpp | 8 ++++++-- OneWire.h | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/OneWire.cpp b/OneWire.cpp index 6d55de0..cf34933 100644 --- a/OneWire.cpp +++ b/OneWire.cpp @@ -344,7 +344,7 @@ void OneWire::target_search(uint8_t family_code) // Return TRUE : device found, ROM number in ROM_NO buffer // FALSE : device not found, end of search // -uint8_t OneWire::search(uint8_t *newAddr) +uint8_t OneWire::search(uint8_t *newAddr, bool search_mode /* = true */) { uint8_t id_bit_number; uint8_t last_zero, rom_byte_number, search_result; @@ -373,7 +373,11 @@ uint8_t OneWire::search(uint8_t *newAddr) } // issue the search command - write(0xF0); + if (search_mode == true) { + write(0xF0); // NORMAL SEARCH + } else { + write(0xEC); // CONDITIONAL SEARCH + } // loop to do the search do diff --git a/OneWire.h b/OneWire.h index 6ad2ac0..d8513e6 100644 --- a/OneWire.h +++ b/OneWire.h @@ -210,7 +210,7 @@ class OneWire // might be a good idea to check the CRC to make sure you didn't // get garbage. The order is deterministic. You will always get // the same devices in the same order. - uint8_t search(uint8_t *newAddr); + uint8_t search(uint8_t *newAddr, bool search_mode = true); #endif #if ONEWIRE_CRC