mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-19 16:46:11 -04:00
0.3.2 DS1821
This commit is contained in:
parent
4046755f22
commit
837932ce4d
@ -1,7 +1,7 @@
|
||||
//
|
||||
// FILE: DS1821.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.1
|
||||
// VERSION: 0.3.2
|
||||
// DATE: 2014-10-05
|
||||
// PURPOSE: Arduino library for DS1821 temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DS1821
|
||||
@ -12,10 +12,12 @@
|
||||
// 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.1 2020-12-20 arduino-CI + unit test (frame)
|
||||
// 0.3.2 2021-05-27 arduio-lint fixes
|
||||
|
||||
|
||||
#include "DS1821.h"
|
||||
|
||||
|
||||
// CONFIG REGISTER MASKS... P7-8 datasheet
|
||||
#define DS1821_CONF_1SHOT 0x01
|
||||
#define DS1821_CONF_POL 0x02
|
||||
@ -49,7 +51,8 @@ DS1821::DS1821(OneWire *ow)
|
||||
{
|
||||
_ow = ow;
|
||||
_err = DS1821_RESET_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// P5 - Operation measuring temperature
|
||||
int DS1821::requestTemperature()
|
||||
@ -57,7 +60,8 @@ int DS1821::requestTemperature()
|
||||
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
|
||||
_command(START_CONVERT);
|
||||
return DS1821_RESET_OK;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
int DS1821::requestContinuous()
|
||||
{
|
||||
@ -65,6 +69,7 @@ int DS1821::requestContinuous()
|
||||
return requestTemperature();
|
||||
}
|
||||
|
||||
|
||||
int DS1821::stopContinuous()
|
||||
{
|
||||
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
|
||||
@ -72,10 +77,12 @@ int DS1821::stopContinuous()
|
||||
return DS1821_RESET_OK;
|
||||
}
|
||||
|
||||
|
||||
int DS1821::conversionReady()
|
||||
{
|
||||
return _getConfigFlag(DS1821_CONF_DONE);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
// P5 - Operation measuring temperature
|
||||
float DS1821::readTemperature()
|
||||
@ -104,7 +111,8 @@ float DS1821::readTemperature()
|
||||
countPerC += _readByte();
|
||||
|
||||
return temperature + 0.5 - (1.0 * countRemain) / countPerC;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
int DS1821::setLow(int8_t lo)
|
||||
{
|
||||
@ -114,6 +122,7 @@ int DS1821::setLow(int8_t lo)
|
||||
return DS1821_RESET_OK;
|
||||
}
|
||||
|
||||
|
||||
int DS1821::getLow()
|
||||
{
|
||||
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
|
||||
@ -121,6 +130,7 @@ int DS1821::getLow()
|
||||
return _readByte();
|
||||
}
|
||||
|
||||
|
||||
int DS1821::setHigh(int8_t hi)
|
||||
{
|
||||
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
|
||||
@ -129,6 +139,7 @@ int DS1821::setHigh(int8_t hi)
|
||||
return DS1821_RESET_OK;
|
||||
}
|
||||
|
||||
|
||||
int DS1821::getHigh()
|
||||
{
|
||||
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
|
||||
@ -136,21 +147,25 @@ int DS1821::getHigh()
|
||||
return _readByte();
|
||||
}
|
||||
|
||||
|
||||
int DS1821::getHighFlag()
|
||||
{
|
||||
return _getConfigFlag(DS1821_CONF_THF);
|
||||
}
|
||||
|
||||
|
||||
int DS1821::clrHighFlag()
|
||||
{
|
||||
return _clrConfigFlag(DS1821_CONF_THF);
|
||||
}
|
||||
|
||||
|
||||
int DS1821::getLowFlag()
|
||||
{
|
||||
return _getConfigFlag(DS1821_CONF_TLF);
|
||||
}
|
||||
|
||||
|
||||
int DS1821::clrLowFlag()
|
||||
{
|
||||
return _clrConfigFlag(DS1821_CONF_TLF);
|
||||
@ -184,17 +199,20 @@ int DS1821::setOneWireMode(uint8_t VDD, uint8_t DQ)
|
||||
return _clrConfigFlag(DS1821_CONF_TR);
|
||||
}
|
||||
|
||||
|
||||
int DS1821::setPolarity(int activstate)
|
||||
{
|
||||
if (activstate == HIGH) return _setConfigFlag(DS1821_CONF_POL);
|
||||
return _clrConfigFlag(DS1821_CONF_POL);
|
||||
}
|
||||
|
||||
|
||||
int DS1821::getPolarity()
|
||||
{
|
||||
return _getConfigFlag(DS1821_CONF_POL);
|
||||
}
|
||||
|
||||
|
||||
int DS1821::setThermostatMode()
|
||||
{
|
||||
int rv = _setConfigFlag(DS1821_CONF_TR);
|
||||
@ -215,6 +233,7 @@ int DS1821::_getConfigFlag(uint8_t flag)
|
||||
return ((_readConfig() & flag) > 0); // true = 1 / false = 0
|
||||
}
|
||||
|
||||
|
||||
// See page 4 datasheet
|
||||
uint8_t DS1821::_waitForNVB()
|
||||
{
|
||||
@ -228,6 +247,7 @@ uint8_t DS1821::_waitForNVB()
|
||||
return config;
|
||||
}
|
||||
|
||||
|
||||
int DS1821::_setConfigFlag(uint8_t flag)
|
||||
{
|
||||
uint8_t config = _waitForNVB();
|
||||
@ -235,6 +255,7 @@ int DS1821::_setConfigFlag(uint8_t flag)
|
||||
return _writeConfig(config);
|
||||
}
|
||||
|
||||
|
||||
int DS1821::_clrConfigFlag(uint8_t flag)
|
||||
{
|
||||
uint8_t config = _waitForNVB();
|
||||
@ -242,6 +263,7 @@ int DS1821::_clrConfigFlag(uint8_t flag)
|
||||
return _writeConfig(config);
|
||||
}
|
||||
|
||||
|
||||
int DS1821::_readConfig()
|
||||
{
|
||||
if (_reset() != DS1821_RESET_OK) return DS1821_RESET_ERROR;
|
||||
@ -249,6 +271,7 @@ int DS1821::_readConfig()
|
||||
return _readByte();
|
||||
}
|
||||
|
||||
|
||||
int DS1821::_writeConfig(uint8_t val)
|
||||
{
|
||||
while (_getConfigFlag(DS1821_CONF_NVB)) delay(1);
|
||||
|
@ -2,7 +2,7 @@
|
||||
//
|
||||
// FILE: DS1821.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.3.1
|
||||
// VERSION: 0.3.2
|
||||
// DATE: 2014-10-05
|
||||
// PURPOSE: Arduino library for DS1821 temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DS1821
|
||||
@ -17,10 +17,12 @@
|
||||
// \ o | 3 VCC
|
||||
// \---+
|
||||
|
||||
|
||||
#include "Arduino.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_ERROR -999
|
||||
@ -60,7 +62,6 @@ public:
|
||||
int getPolarity();
|
||||
int setThermostatMode();
|
||||
|
||||
|
||||
private:
|
||||
OneWire * _ow;
|
||||
int _err;
|
||||
@ -78,4 +79,5 @@ private:
|
||||
uint8_t _DQ;
|
||||
};
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
Arduino library for DS1821 temperature sensor (experimental)
|
||||
|
||||
|
||||
## Description
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## Interface (temperature sensor)
|
||||
|
||||
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
|
||||
to toggle the DQ line in the thermostat mode.
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- Get new sensors to test test test...
|
||||
|
@ -7,6 +7,7 @@
|
||||
// URL: https://github.com/RobTillaart/DS1821
|
||||
//
|
||||
|
||||
|
||||
#include "DS1821.h"
|
||||
|
||||
OneWire ds(10); // change pin if needed
|
||||
|
@ -7,6 +7,7 @@
|
||||
// URL: https://github.com/RobTillaart/DS1821
|
||||
//
|
||||
|
||||
|
||||
#include "DS1821.h"
|
||||
|
||||
OneWire ds(10); // change pin if needed
|
||||
|
@ -66,6 +66,7 @@ void setup()
|
||||
Serial.println("\nConfiguration done...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
Serial.print("ThermoStat:\t");
|
||||
@ -73,4 +74,5 @@ void loop()
|
||||
delay(100);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -15,7 +15,8 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DS1821"
|
||||
},
|
||||
"version":"0.3.1",
|
||||
"version": "0.3.2",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
name=DS1821
|
||||
version=0.3.1
|
||||
version=0.3.2
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for DS1821 temperature sensor
|
||||
paragraph=experimental
|
||||
category=Sensor
|
||||
category=Sensors
|
||||
url=https://github.com/RobTillaart/DS1821
|
||||
architectures=*
|
||||
includes=DS1821.h
|
||||
|
@ -28,11 +28,11 @@
|
||||
#include "DS1821.h"
|
||||
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
unittest_teardown()
|
||||
{
|
||||
}
|
||||
@ -49,6 +49,7 @@ unittest(test_constructor)
|
||||
assertEqual(1, 1);
|
||||
}
|
||||
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
||||
|
Loading…
Reference in New Issue
Block a user