Library to communicate with Maxim OneWire protocol devices Modified timings and IRQ overrides

Dependents:   RdGasUseMonitor

Fork of Onewire by Simon Barker

Revision:
6:d2452e9b169b
Parent:
5:45b6a39002f1
Child:
7:0a87f8c2d9e6
--- a/Onewire.cpp	Mon Sep 28 10:31:58 2015 +0000
+++ b/Onewire.cpp	Mon Oct 05 14:03:29 2015 +0000
@@ -128,7 +128,12 @@
 
 // Search Copied from Arduino code
 //
-// Perform a search. If this function returns a '1' then it has
+// Perform a search.
+// Returns 
+// ONEWIRE_OK if a new address has been returned.
+// ONEWIRE_SEARCH_ALL_DONE = all devices found
+// ONEWIRE_SEARCH_INIT_FAIL = failed to init
+// ONEWIRE_SEARCH_NOT_FOUND = no devices found If this function returns a '1' then it has
 // enumerated the next device and you may retrieve the ROM from the
 // Onewire::address variable. If there are no devices, no further
 // devices, or something horrible happens in the middle of the
@@ -146,7 +151,8 @@
 uint8_t Onewire::search(uint8_t *newAddr)
 {
    uint8_t id_bit_number = 1;
-   uint8_t last_zero = 0, rom_byte_number = 0, search_result = 0;
+   uint8_t last_zero = 0, rom_byte_number = 0;
+   uint8_t search_result = ONEWIRE_SEARCH_ALL_DONE;
    uint8_t id_bit = 0, cmp_id_bit = 0;
 
    // initialize for search
@@ -162,7 +168,7 @@
          _search_LastDiscrepancy = 0;
          _search_LastDeviceFlag = false;
          _search_LastFamilyDiscrepancy = 0;
-         return false;
+         return ONEWIRE_SEARCH_INIT_FAIL;
       }
 
       // issue the search command
@@ -239,18 +245,20 @@
          if (_search_LastDiscrepancy == 0)
             _search_LastDeviceFlag = true;
 
-         search_result = true;
+         search_result = ONEWIRE_OK;
       }
    }
 
    // if no device found then reset counters so next 'search' will be like a first
-   if (!search_result || !_search_ROM_NO[0])
+   if (!_search_ROM_NO[0])
    {
       _search_LastDiscrepancy = 0;
       _search_LastDeviceFlag = false;
       _search_LastFamilyDiscrepancy = 0;
-      search_result = false;
+      search_result = ONEWIRE_SEARCH_NOT_FOUND;
    }
+   if (search_result != ONEWIRE_OK)
+        return search_result;
    for (int i = 0; i < ONEWIRE_ADDR_BYTES; i++)
        newAddr[i] = _search_ROM_NO[i];
    return search_result;