From 0643e42b76ede60e99837ced18de0d0dc813f655 Mon Sep 17 00:00:00 2001 From: Prashant Date: Sun, 19 Oct 2014 22:36:33 +0530 Subject: [PATCH 1/2] Modifications by Prashant : An extra no arguments constructor to simplify multiple OneWire buse use, allowing for easier construction of arrays of OneWire buses, in the limited environment provided by Arduino. See the Multibus_simple example illustrating a use-case of the extension. --- OneWire.cpp | 13 +++++- OneWire.h | 2 + README.md | 5 ++ examples/Multibus_simple/Multibus_simple.ino | 48 ++++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 examples/Multibus_simple/Multibus_simple.ino diff --git a/OneWire.cpp b/OneWire.cpp index 81d1a92..e570ec2 100644 --- a/OneWire.cpp +++ b/OneWire.cpp @@ -1,6 +1,11 @@ /* Copyright (c) 2007, Jim Studt (original old version - many contributors since) +Modifications by Prashant : An extra no arguments constructor to simplify +multiple OneWire buse use, allowing for easier construction of arrays of OneWire buses, +in the limited environment provided by Arduino. +See the Multibus_simple example illustrating a use-case of the extension. + Version 2.3: Modifications by Norbert Truchsess, January 2013 add search_alarms() to find only devices in alarmed state. @@ -122,7 +127,8 @@ sample code bearing this copyright. #include "OneWire.h" -OneWire::OneWire(uint8_t pin) +OneWire::OneWire() {} +void OneWire::setPin(uint8_t pin) { pinMode(pin, INPUT); bitmask = PIN_TO_BITMASK(pin); @@ -132,6 +138,11 @@ OneWire::OneWire(uint8_t pin) #endif } +OneWire::OneWire(uint8_t pin) +{ + setPin(pin); +} + // Perform the onewire reset function. We will wait up to 250uS for // the bus to come high, if it doesn't then it is broken or shorted diff --git a/OneWire.h b/OneWire.h index 7acd488..ace3255 100644 --- a/OneWire.h +++ b/OneWire.h @@ -126,6 +126,8 @@ class OneWire #endif public: + OneWire(); + void setPin(uint8_t pin); OneWire( uint8_t pin); // Perform a 1-Wire reset cycle. Returns 1 if a device responds diff --git a/README.md b/README.md index a0f9c8c..aedd7a2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ Copyright (c) 2007, Jim Studt (original old version - many contributors since) +Modifications by Prashant : An extra no arguments constructor to simplify +multiple OneWire buse use, allowing for easier construction of arrays of OneWire buses, +in the limited environment provided by Arduino. +See the Multibus_simple example illustrating a use-case of the extension. + Version 2.3: Modifications by Norbert Truchsess, January 2013 add search_alarms() to find only devices in alarmed state. diff --git a/examples/Multibus_simple/Multibus_simple.ino b/examples/Multibus_simple/Multibus_simple.ino new file mode 100644 index 0000000..a818e07 --- /dev/null +++ b/examples/Multibus_simple/Multibus_simple.ino @@ -0,0 +1,48 @@ +#include +#include + +int oneWirePins[]={3,7};//OneWire DS18x20 temperature sensors on these wires +const int oneWirePinsCount=sizeof(oneWirePins)/sizeof(int); + +OneWire ds18x20[oneWirePinsCount]; +DallasTemperature sensor[oneWirePinsCount]; + + +void setup(void) { + // start serial port + Serial.begin(9600); + Serial.println("Dallas Temperature Multiple Bus Control Library Simple Demo"); + Serial.print("============Ready with "); + Serial.print(oneWirePinsCount); + Serial.println(" Sensors================"); + + // Start up the library on all defined bus-wires + DeviceAddress deviceAddress; + for (int i=0; i Date: Sun, 19 Oct 2014 22:38:34 +0530 Subject: [PATCH 2/2] Added a comment --- OneWire.cpp | 1 + README.md | 1 + 2 files changed, 2 insertions(+) diff --git a/OneWire.cpp b/OneWire.cpp index e570ec2..ca330fc 100644 --- a/OneWire.cpp +++ b/OneWire.cpp @@ -5,6 +5,7 @@ Modifications by Prashant : An extra no arguments constructor to simplify multiple OneWire buse use, allowing for easier construction of arrays of OneWire buses, in the limited environment provided by Arduino. See the Multibus_simple example illustrating a use-case of the extension. +Use in conjunction with my modification of the DallasTemperature library. Version 2.3: Modifications by Norbert Truchsess, January 2013 add search_alarms() to find only devices in alarmed state. diff --git a/README.md b/README.md index aedd7a2..c9e877a 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Modifications by Prashant : An extra no arguments constructor to simplify multiple OneWire buse use, allowing for easier construction of arrays of OneWire buses, in the limited environment provided by Arduino. See the Multibus_simple example illustrating a use-case of the extension. +Use in conjunction with my modification of the DallasTemperature library. Version 2.3: Modifications by Norbert Truchsess, January 2013 add search_alarms() to find only devices in alarmed state.