0.3.2 DS1821

This commit is contained in:
rob tillaart 2021-05-28 13:24:52 +02:00
parent 4046755f22
commit 837932ce4d
9 changed files with 46 additions and 12 deletions

View File

@ -1,7 +1,7 @@
// //
// FILE: DS1821.cpp // FILE: DS1821.cpp
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.3.1 // VERSION: 0.3.2
// DATE: 2014-10-05 // DATE: 2014-10-05
// PURPOSE: Arduino library for DS1821 temperature sensor // PURPOSE: Arduino library for DS1821 temperature sensor
// URL: https://github.com/RobTillaart/DS1821 // URL: https://github.com/RobTillaart/DS1821
@ -12,10 +12,12 @@
// 0.2.0 2020-08-05 initial release; refactored ad fundum. // 0.2.0 2020-08-05 initial release; refactored ad fundum.
// 0.3.0 2020-08-07 add continuous mode, alarm level, polarity, thermostat etc // 0.3.0 2020-08-07 add continuous mode, alarm level, polarity, thermostat etc
// 0.3.1 2020-12-20 arduino-CI + unit test (frame) // 0.3.1 2020-12-20 arduino-CI + unit test (frame)
// 0.3.2 2021-05-27 arduio-lint fixes
#include "DS1821.h" #include "DS1821.h"
// CONFIG REGISTER MASKS... P7-8 datasheet // CONFIG REGISTER MASKS... P7-8 datasheet
#define DS1821_CONF_1SHOT 0x01 #define DS1821_CONF_1SHOT 0x01
#define DS1821_CONF_POL 0x02 #define DS1821_CONF_POL 0x02
@ -49,7 +51,8 @@ DS1821::DS1821(OneWire *ow)
{ {
_ow = ow; _ow = ow;
_err = DS1821_RESET_OK; _err = DS1821_RESET_OK;
}; }
// P5 - Operation measuring temperature // P5 - Operation measuring temperature
int DS1821::requestTemperature() int DS1821::requestTemperature()
@ -57,7 +60,8 @@ int DS1821::requestTemperature()
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR; if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
_command(START_CONVERT); _command(START_CONVERT);
return DS1821_RESET_OK; return DS1821_RESET_OK;
}; }
int DS1821::requestContinuous() int DS1821::requestContinuous()
{ {
@ -65,6 +69,7 @@ int DS1821::requestContinuous()
return requestTemperature(); return requestTemperature();
} }
int DS1821::stopContinuous() int DS1821::stopContinuous()
{ {
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR; if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
@ -72,10 +77,12 @@ int DS1821::stopContinuous()
return DS1821_RESET_OK; return DS1821_RESET_OK;
} }
int DS1821::conversionReady() int DS1821::conversionReady()
{ {
return _getConfigFlag(DS1821_CONF_DONE); return _getConfigFlag(DS1821_CONF_DONE);
}; }
// P5 - Operation measuring temperature // P5 - Operation measuring temperature
float DS1821::readTemperature() float DS1821::readTemperature()
@ -104,7 +111,8 @@ float DS1821::readTemperature()
countPerC += _readByte(); countPerC += _readByte();
return temperature + 0.5 - (1.0 * countRemain) / countPerC; return temperature + 0.5 - (1.0 * countRemain) / countPerC;
}; }
int DS1821::setLow(int8_t lo) int DS1821::setLow(int8_t lo)
{ {
@ -114,6 +122,7 @@ int DS1821::setLow(int8_t lo)
return DS1821_RESET_OK; return DS1821_RESET_OK;
} }
int DS1821::getLow() int DS1821::getLow()
{ {
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR; if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
@ -121,6 +130,7 @@ int DS1821::getLow()
return _readByte(); return _readByte();
} }
int DS1821::setHigh(int8_t hi) int DS1821::setHigh(int8_t hi)
{ {
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR; if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
@ -129,6 +139,7 @@ int DS1821::setHigh(int8_t hi)
return DS1821_RESET_OK; return DS1821_RESET_OK;
} }
int DS1821::getHigh() int DS1821::getHigh()
{ {
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR; if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
@ -136,21 +147,25 @@ int DS1821::getHigh()
return _readByte(); return _readByte();
} }
int DS1821::getHighFlag() int DS1821::getHighFlag()
{ {
return _getConfigFlag(DS1821_CONF_THF); return _getConfigFlag(DS1821_CONF_THF);
} }
int DS1821::clrHighFlag() int DS1821::clrHighFlag()
{ {
return _clrConfigFlag(DS1821_CONF_THF); return _clrConfigFlag(DS1821_CONF_THF);
} }
int DS1821::getLowFlag() int DS1821::getLowFlag()
{ {
return _getConfigFlag(DS1821_CONF_TLF); return _getConfigFlag(DS1821_CONF_TLF);
} }
int DS1821::clrLowFlag() int DS1821::clrLowFlag()
{ {
return _clrConfigFlag(DS1821_CONF_TLF); return _clrConfigFlag(DS1821_CONF_TLF);
@ -184,17 +199,20 @@ int DS1821::setOneWireMode(uint8_t VDD, uint8_t DQ)
return _clrConfigFlag(DS1821_CONF_TR); return _clrConfigFlag(DS1821_CONF_TR);
} }
int DS1821::setPolarity(int activstate) int DS1821::setPolarity(int activstate)
{ {
if (activstate == HIGH) return _setConfigFlag(DS1821_CONF_POL); if (activstate == HIGH) return _setConfigFlag(DS1821_CONF_POL);
return _clrConfigFlag(DS1821_CONF_POL); return _clrConfigFlag(DS1821_CONF_POL);
} }
int DS1821::getPolarity() int DS1821::getPolarity()
{ {
return _getConfigFlag(DS1821_CONF_POL); return _getConfigFlag(DS1821_CONF_POL);
} }
int DS1821::setThermostatMode() int DS1821::setThermostatMode()
{ {
int rv = _setConfigFlag(DS1821_CONF_TR); int rv = _setConfigFlag(DS1821_CONF_TR);
@ -215,6 +233,7 @@ int DS1821::_getConfigFlag(uint8_t flag)
return ((_readConfig() & flag) > 0); // true = 1 / false = 0 return ((_readConfig() & flag) > 0); // true = 1 / false = 0
} }
// See page 4 datasheet // See page 4 datasheet
uint8_t DS1821::_waitForNVB() uint8_t DS1821::_waitForNVB()
{ {
@ -228,6 +247,7 @@ uint8_t DS1821::_waitForNVB()
return config; return config;
} }
int DS1821::_setConfigFlag(uint8_t flag) int DS1821::_setConfigFlag(uint8_t flag)
{ {
uint8_t config = _waitForNVB(); uint8_t config = _waitForNVB();
@ -235,6 +255,7 @@ int DS1821::_setConfigFlag(uint8_t flag)
return _writeConfig(config); return _writeConfig(config);
} }
int DS1821::_clrConfigFlag(uint8_t flag) int DS1821::_clrConfigFlag(uint8_t flag)
{ {
uint8_t config = _waitForNVB(); uint8_t config = _waitForNVB();
@ -242,6 +263,7 @@ int DS1821::_clrConfigFlag(uint8_t flag)
return _writeConfig(config); return _writeConfig(config);
} }
int DS1821::_readConfig() int DS1821::_readConfig()
{ {
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR; if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
@ -249,6 +271,7 @@ int DS1821::_readConfig()
return _readByte(); return _readByte();
} }
int DS1821::_writeConfig(uint8_t val) int DS1821::_writeConfig(uint8_t val)
{ {
while (_getConfigFlag(DS1821_CONF_NVB)) delay(1); while (_getConfigFlag(DS1821_CONF_NVB)) delay(1);

View File

@ -2,7 +2,7 @@
// //
// FILE: DS1821.h // FILE: DS1821.h
// AUTHOR: Rob Tillaart // AUTHOR: Rob Tillaart
// VERSION: 0.3.1 // VERSION: 0.3.2
// DATE: 2014-10-05 // DATE: 2014-10-05
// PURPOSE: Arduino library for DS1821 temperature sensor // PURPOSE: Arduino library for DS1821 temperature sensor
// URL: https://github.com/RobTillaart/DS1821 // URL: https://github.com/RobTillaart/DS1821
@ -17,10 +17,12 @@
// \ o | 3 VCC // \ o | 3 VCC
// \---+ // \---+
#include "Arduino.h" #include "Arduino.h"
#include "OneWire.h" #include "OneWire.h"
#define DS1821_H_LIB_VERSION "0.3.1"
#define DS1821_H_LIB_VERSION (F("0.3.2"))
#define DS1821_RESET_OK 0 #define DS1821_RESET_OK 0
#define DS1821_RESET_ERROR -999 #define DS1821_RESET_ERROR -999
@ -60,7 +62,6 @@ public:
int getPolarity(); int getPolarity();
int setThermostatMode(); int setThermostatMode();
private: private:
OneWire * _ow; OneWire * _ow;
int _err; int _err;
@ -78,4 +79,5 @@ private:
uint8_t _DQ; uint8_t _DQ;
}; };
// -- END OF FILE -- // -- END OF FILE --

View File

@ -7,6 +7,7 @@
Arduino library for DS1821 temperature sensor (experimental) Arduino library for DS1821 temperature sensor (experimental)
## Description ## Description
The DS1821 is a temperature sensor that uses the oneWire protocol. The DS1821 is a temperature sensor that uses the oneWire protocol.
@ -15,6 +16,7 @@ As this library is tested minimally please consider it experimental.
The sensor is hard to get however still available on internet. The sensor is hard to get however still available on internet.
## Interface (temperature sensor) ## Interface (temperature sensor)
The interface of the library is an async interface so there are no blocking calls. The interface of the library is an async interface so there are no blocking calls.
@ -73,6 +75,7 @@ a fan or a motor. Activstate defines which value is ON and OFF.
The Low / High values set in sensor mode gives the DS1821 the thresholds The Low / High values set in sensor mode gives the DS1821 the thresholds
to toggle the DQ line in the thermostat mode. to toggle the DQ line in the thermostat mode.
## Future ## Future
- Get new sensors to test test test... - Get new sensors to test test test...

View File

@ -7,6 +7,7 @@
// URL: https://github.com/RobTillaart/DS1821 // URL: https://github.com/RobTillaart/DS1821
// //
#include "DS1821.h" #include "DS1821.h"
OneWire ds(10); // change pin if needed OneWire ds(10); // change pin if needed

View File

@ -7,6 +7,7 @@
// URL: https://github.com/RobTillaart/DS1821 // URL: https://github.com/RobTillaart/DS1821
// //
#include "DS1821.h" #include "DS1821.h"
OneWire ds(10); // change pin if needed OneWire ds(10); // change pin if needed

View File

@ -66,6 +66,7 @@ void setup()
Serial.println("\nConfiguration done..."); Serial.println("\nConfiguration done...");
} }
void loop() void loop()
{ {
Serial.print("ThermoStat:\t"); Serial.print("ThermoStat:\t");
@ -73,4 +74,5 @@ void loop()
delay(100); delay(100);
} }
// -- END OF FILE -- // -- END OF FILE --

View File

@ -15,7 +15,8 @@
"type": "git", "type": "git",
"url": "https://github.com/RobTillaart/DS1821" "url": "https://github.com/RobTillaart/DS1821"
}, },
"version":"0.3.1", "version": "0.3.2",
"license": "MIT",
"frameworks": "arduino", "frameworks": "arduino",
"platforms": "*" "platforms": "*"
} }

View File

@ -1,10 +1,10 @@
name=DS1821 name=DS1821
version=0.3.1 version=0.3.2
author=Rob Tillaart <rob.tillaart@gmail.com> author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com> maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for DS1821 temperature sensor sentence=Arduino library for DS1821 temperature sensor
paragraph=experimental paragraph=experimental
category=Sensor category=Sensors
url=https://github.com/RobTillaart/DS1821 url=https://github.com/RobTillaart/DS1821
architectures=* architectures=*
includes=DS1821.h includes=DS1821.h

View File

@ -28,11 +28,11 @@
#include "DS1821.h" #include "DS1821.h"
unittest_setup() unittest_setup()
{ {
} }
unittest_teardown() unittest_teardown()
{ {
} }
@ -49,6 +49,7 @@ unittest(test_constructor)
assertEqual(1, 1); assertEqual(1, 1);
} }
unittest_main() unittest_main()
// -------- // --------