@@ -155,7 +155,6 @@ void DallasTemperature::writeScratchPad(const uint8_t* deviceAddress, const uint
155
155
if (deviceAddress[0 ] != DS18S20MODEL) _wire->write (scratchPad[CONFIGURATION]);
156
156
157
157
_wire->reset ();
158
- _wire->select (deviceAddress);
159
158
160
159
// save the newly written values to eeprom
161
160
_wire->select (deviceAddress);
@@ -189,14 +188,20 @@ void DallasTemperature::setResolution(uint8_t newResolution){
189
188
for (int i=0 ; i<devices; i++)
190
189
{
191
190
getAddress (deviceAddress, i);
192
- setResolution (deviceAddress, bitResolution);
191
+ setResolution (deviceAddress, bitResolution, true );
193
192
}
194
193
195
194
}
196
195
197
196
// set resolution of a device to 9, 10, 11, or 12 bits
198
197
// if new resolution is out of range, 9 bits is used.
199
- bool DallasTemperature::setResolution (const uint8_t * deviceAddress, uint8_t newResolution){
198
+ bool DallasTemperature::setResolution (const uint8_t * deviceAddress, uint8_t newResolution, bool skipGlobalBitResolutionCalculation){
199
+
200
+ // ensure same behavior as setResolution(uint8_t newResolution)
201
+ newResolution = constrain (newResolution, 9 , 12 );
202
+
203
+ // return when stored value == new value
204
+ if (getResolution (deviceAddress) == newResolution) return true ;
200
205
201
206
ScratchPad scratchPad;
202
207
if (isConnected (deviceAddress, scratchPad)){
@@ -220,6 +225,19 @@ bool DallasTemperature::setResolution(const uint8_t* deviceAddress, uint8_t newR
220
225
break ;
221
226
}
222
227
writeScratchPad (deviceAddress, scratchPad);
228
+
229
+ // without calculation we can always set it to max
230
+ bitResolution = max (bitResolution, newResolution);
231
+
232
+ if (!skipGlobalBitResolutionCalculation && (bitResolution > newResolution)){
233
+ bitResolution = newResolution;
234
+ DeviceAddress deviceAddr;
235
+ for (int i=0 ; i<devices; i++)
236
+ {
237
+ getAddress (deviceAddr, i);
238
+ bitResolution = max (bitResolution, getResolution (deviceAddr));
239
+ }
240
+ }
223
241
}
224
242
return true ; // new value set
225
243
}
@@ -499,6 +517,9 @@ bool DallasTemperature::isParasitePowerMode(void){
499
517
// note if device is not connected it will fail writing the data.
500
518
void DallasTemperature::setUserData (const uint8_t * deviceAddress, int16_t data)
501
519
{
520
+ // return when stored value == new value
521
+ if (getUserData (deviceAddress) == data) return ;
522
+
502
523
ScratchPad scratchPad;
503
524
if (isConnected (deviceAddress, scratchPad))
504
525
{
@@ -594,6 +615,9 @@ the next temperature conversion.
594
615
// after a decimal point. valid range is -55C - 125C
595
616
void DallasTemperature::setHighAlarmTemp (const uint8_t * deviceAddress, char celsius){
596
617
618
+ // return when stored value == new value
619
+ if (getHighAlarmTemp (deviceAddress) == celsius) return ;
620
+
597
621
// make sure the alarm temperature is within the device's range
598
622
if (celsius > 125 ) celsius = 125 ;
599
623
else if (celsius < -55 ) celsius = -55 ;
@@ -610,6 +634,10 @@ void DallasTemperature::setHighAlarmTemp(const uint8_t* deviceAddress, char cels
610
634
// accepts a float, but the alarm resolution will ignore anything
611
635
// after a decimal point. valid range is -55C - 125C
612
636
void DallasTemperature::setLowAlarmTemp (const uint8_t * deviceAddress, char celsius){
637
+
638
+ // return when stored value == new value
639
+ if (getLowAlarmTemp (deviceAddress) == celsius) return ;
640
+
613
641
// make sure the alarm temperature is within the device's range
614
642
if (celsius > 125 ) celsius = 125 ;
615
643
else if (celsius < -55 ) celsius = -55 ;
@@ -803,4 +831,4 @@ void DallasTemperature::operator delete(void* p){
803
831
free (p); // Free the memory
804
832
}
805
833
806
- #endif
834
+ #endif
0 commit comments