Fork of DS1820 that can function with the data and parasite power pin being the same.
Dependents: AutonomousDAQ AutonomousDAQ
Fork of DS1820 by
Diff: DS1820.h
- Revision:
- 7:aceafdd78b28
- Parent:
- 6:c78fb487c397
--- a/DS1820.h Mon Sep 22 00:38:39 2014 +0000 +++ b/DS1820.h Thu Oct 30 05:55:15 2014 +0000 @@ -89,7 +89,8 @@ * @param data_pin DigitalInOut pin for the data bus * @param power_pin DigitalOut pin to control the power MOSFET */ - DS1820(PinName data_pin, PinName power_pin); // Constructor with parasite power pin + DS1820(PinName data_pin, PinName power_pin, + const bool useParasitePwr=true); // Constructor with parasite power pin /** Create a probe object connected to the specified pin * this is used when all probes are externally powered @@ -247,21 +248,6 @@ * returns false if the device (or ANY device) is parasite powered. */ bool read_power_supply(devices device=this_device); - - /** Allow the parasite pin to be set at any time. If it is set - * to "NC", then parasite mode is turned off. It is ok if this - * pin is the same as the datapin. - * - * @param parasitePin The pin to use for parasite power, or NC for - * external power - * @returns true if the parasite power is set to a connected pin - * false if parasite power is not connected (external power) - */ - bool set_parasite_pin(DigitalInOut parasitePin) { - _parasitepin = parasitePin; - _parasite_power = (NC!=parasitePin); - return _parasite_power; - } /** Check if parasite power is being used. * @@ -270,8 +256,26 @@ */ bool is_on_parasite_power() const { return _parasite_power; } + /** Allow use of parasite power to be switched on or off + * + * @param pwr Specify whether to use the parasite pin for power (true) + * or not (false). + * @return true if using parasite power + * false if not (i.e. parasite mode requested, but no parasite pin) + */ + bool set_use_parasite_power(const bool pwr) { + if (pwr && (_parasite_power_pn!=NC)) { + _parasite_power = true; + } else { + _parasite_power = false; + } + return _parasite_power; + } + private: bool _parasite_power; + PinName _parasite_power_pn; + char CRC_byte (char CRC, char byte ); bool onewire_reset(); void match_ROM();