@@ -67,6 +67,7 @@ DSFamily_Class::~DSFamily_Class() { } //
6767*******************************************************************************************************************/
6868uint8_t DSFamily_Class::ScanForDevices () { // //
6969 uint8_t tempTherm[8 ]; // Temporary DS address array //
70+ _LastCommandWasConvert = false ; // Set switch to false //
7071 reset_search (); // Reset the search status //
7172 ThermometersFound = 0 ; // Reset the number of thermometers //
7273 while (search (tempTherm)) { // Use the 1-Wire "search" method //
@@ -92,6 +93,7 @@ uint8_t DSFamily_Class::ScanForDevices() { //
9293*******************************************************************************************************************/
9394boolean DSFamily_Class::Read1WireScratchpad (const uint8_t deviceNumber, // //
9495 uint8_t buffer[9 ]) { // //
96+ _LastCommandWasConvert = false ; // Set switch to false //
9597 SelectDevice (deviceNumber); // Reset the 1-wire, address device //
9698 write_byte (DS_READ_SCRATCHPAD); // Request device send Scratchpad //
9799 for (uint8_t i=0 ;i<9 ;i++) buffer[i] = read_byte (); // read all 9 bytes sent by DS //
@@ -110,8 +112,10 @@ int16_t DSFamily_Class::ReadDeviceTemp(const uint8_t deviceNumber, //
110112 const bool raw=false ) { // //
111113 uint8_t dsBuffer[9 ]; // Buffer to hold scratchpad return //
112114 int16_t temperature = DS_BAD_TEMPERATURE; // Holds return value //
113- if ((_ConvStartTime+ConversionMillis)>millis ()) // If a conversion is still running //
115+ if (Parasitic || !_LastCommandWasConvert) { // Wait a fixed time in parasite or //
116+ if ((_ConvStartTime+ConversionMillis)>millis ()) // If a conversion is still running //
114117 delay (millis ()-(_ConvStartTime+ConversionMillis)); // then wait until it is finished //
118+ } else if (_LastCommandWasConvert) while (read_bit ()==0 ); // bit high when conversion finished//
115119 if ( deviceNumber < ThermometersFound && // on a successful read from the //
116120 Read1WireScratchpad (deviceNumber,dsBuffer)) { // device scratchpad //
117121 if (dsBuffer[0 ]==DS1822_FAMILY) { // The results returned by DS18S20 //
@@ -126,17 +130,21 @@ int16_t DSFamily_Class::ReadDeviceTemp(const uint8_t deviceNumber, //
126130
127131/* ******************************************************************************************************************
128132** method DeviceStartConvert() to start the sampling and conversion on a device. At maximum resolution this **
129- ** conversion can take 750ms. If the optional parameter is not specified then all device conversions are started **
130- ** at the same time **
133+ ** conversion can take 750ms. If the optional deviceNumber is not specified then all device conversions are **
134+ ** started at the same time. If the optional WaitSwitch parameter is set to "true" then call doesn't return until **
135+ ** the conversion has completed **
131136*******************************************************************************************************************/
132- void DSFamily_Class::DeviceStartConvert (const uint8_t deviceNumber=UINT8_MAX){// //
137+ void DSFamily_Class::DeviceStartConvert (const uint8_t deviceNumber=UINT8_MAX, // //
138+ const bool WaitSwitch = false ) { // //
133139 ParasiticWait (); // Wait for conversion if necessary //
134140 if (deviceNumber==UINT8_MAX) { // If no parameter specified, use //
135141 reset (); // Reset 1-wire network //
136142 write_byte (DS_SKIP_ROM); // Tell all devices to listen //
137143 } else SelectDevice (deviceNumber); // of if-then all devices or just one // //
138144 write_byte (DS_START_CONVERT); // Initiate temperature conversion //
139145 _ConvStartTime = millis (); // Store start time of conversion //
146+ _LastCommandWasConvert = true ; // Set switch to true //
147+ if (!Parasitic && WaitSwitch) while (read_bit ()==0 ); // Read bit goes high when finished //
140148} // of method DeviceStartConvert //----------------------------------//
141149
142150/* ******************************************************************************************************************
@@ -161,6 +169,7 @@ void DSFamily_Class::Calibrate(const uint8_t iterations=30) { //
161169 int64_t tempSum = 0 ; // Stores interim values //
162170 int8_t offset = 0 ; // Stores the computed offset value //
163171 uint8_t ThermometersUsed = min (DS_MAX_THERMOMETERS,ThermometersFound); // Use the lower of the 2 values //
172+ _LastCommandWasConvert = false ; // Set switch to false //
164173 for (uint8_t i=0 ;i<iterations;i++) { // Loop to get a good sampling //
165174 for (uint8_t x=0 ;x<ThermometersUsed;x++) { // process each thermometer //
166175 stats1[x] += ReadDeviceTemp (x,true ); // read raw temperature, no offset //
@@ -182,6 +191,7 @@ void DSFamily_Class::Calibrate(const uint8_t iterations=30) { //
182191void DSFamily_Class::SetDeviceCalibration (const uint8_t deviceNumber, // //
183192 const int8_t offset) { // //
184193 uint8_t dsBuffer[9 ]; // Temporary scratchpad buffer //
194+ _LastCommandWasConvert = false ; // Set switch to false //
185195 Read1WireScratchpad (deviceNumber,dsBuffer); // Read from the device scratchpad //
186196 SelectDevice (deviceNumber); // Reset 1-wire, address device //
187197 write_byte (DS_WRITE_SCRATCHPAD); // Write scratchpad, send 3 bytes //
@@ -199,6 +209,7 @@ void DSFamily_Class::SetDeviceCalibration(const uint8_t deviceNumber, //
199209int8_t DSFamily_Class::GetDeviceCalibration (const uint8_t deviceNumber) { // //
200210 int8_t offset = INT8_MIN; // Default to an invalid value //
201211 uint8_t dsBuffer[9 ]; // Temporary scratchpad buffer //
212+ _LastCommandWasConvert = false ; // Set switch to false //
202213 Read1WireScratchpad (deviceNumber,dsBuffer); // Read from the device scratchpad //
203214 if (dsBuffer[2 ]^dsBuffer[3 ]==0xFF ) offset = (int8_t )dsBuffer[2 ]; // Use the calibration value //
204215 return (offset); // Return the computed offset //
@@ -221,6 +232,7 @@ void DSFamily_Class::SelectDevice(const uint8_t deviceNumber) { //
221232*******************************************************************************************************************/
222233void DSFamily_Class::GetDeviceROM (const uint8_t deviceNumber, // //
223234 uint8_t ROMBuffer[8 ]) { // Array to hold unique DS ID //
235+ _LastCommandWasConvert = false ; // Set switch to false //
224236 for (uint8_t i=0 ;i<8 ;i++) // loop for each byte in the buffer //
225237 ROMBuffer[i]=EEPROM.read (i+E2END-((deviceNumber+1 )*8 )); // Read the EEPROM byte //
226238} // of method GetDeviceROM() //----------------------------------//
@@ -287,6 +299,7 @@ int16_t DSFamily_Class::AvgTemperature(const uint8_t skipDeviceNumber=UINT8_MAX)
287299void DSFamily_Class::SetDeviceResolution (const uint8_t deviceNumber, // Set resolution to 9,10,11 or 12 b//
288300 uint8_t resolution) { // //
289301 uint8_t dsBuffer[9 ]; // Buffer to hold scratchpad values //
302+ _LastCommandWasConvert = false ; // Set switch to false //
290303 if (resolution<9 || resolution>12 ) resolution = 12 ; // Default to full resolution //
291304 switch (resolution) { // Now select which action to do //
292305 case 12 : // When 12 bits of precision used //
@@ -319,11 +332,12 @@ void DSFamily_Class::SetDeviceResolution(const uint8_t deviceNumber, //
319332** Method SetUserBytes to set the user bytes 1 and 2 to the calibration computed **
320333*******************************************************************************************************************/
321334uint8_t DSFamily_Class::GetDeviceResolution (const uint8_t deviceNumber) { // //
322- uint8_t resolution; // Store the return value //
323- uint8_t dsBuffer[9 ]; // Hold scratchpad return values //
324- Read1WireScratchpad (deviceNumber,dsBuffer); // Read from the device scratchpad //
325- resolution = (dsBuffer[DS_CONFIG_BYTE]>>5 )+9 ; // get bits 6&7 from the config byte//
326- return (resolution); // //
335+ uint8_t resolution; // Store the return value //
336+ uint8_t dsBuffer[9 ]; // Hold scratchpad return values //
337+ _LastCommandWasConvert = false ; // Set switch to false //
338+ Read1WireScratchpad (deviceNumber,dsBuffer); // Read from the device scratchpad //
339+ resolution = (dsBuffer[DS_CONFIG_BYTE]>>5 )+9 ; // get bits 6&7 from the config byte//
340+ return (resolution); // //
327341} // of method GetDeviceResolution() //----------------------------------//
328342
329343/* ******************************************************************************************************************
0 commit comments