GY-63_MS5611/libraries/DS1821/DS1821.h

86 lines
2.0 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: DS1821.h
// AUTHOR: Rob Tillaart
2022-11-02 14:58:31 -04:00
// VERSION: 0.3.4
2021-01-29 06:31:58 -05:00
// DATE: 2014-10-05
// PURPOSE: Arduino library for DS1821 temperature sensor
// URL: https://github.com/RobTillaart/DS1821
//
2022-11-02 14:58:31 -04:00
// BOTTOM VIEW
2021-01-29 06:31:58 -05:00
//
2022-11-02 14:58:31 -04:00
// PIN MEANING
// /---+
// / o | 1 GND
// | o | 2 DATA
// \ o | 3 VCC
// \---+
2021-01-29 06:31:58 -05:00
2021-05-28 07:24:52 -04:00
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
#include "OneWire.h"
2021-05-28 07:24:52 -04:00
2022-11-02 14:58:31 -04:00
#define DS1821_H_LIB_VERSION (F("0.3.4"))
2021-01-29 06:31:58 -05:00
#define DS1821_RESET_OK 0
#define DS1821_RESET_ERROR -999
class DS1821
{
public:
DS1821(OneWire* ow);
2022-11-02 14:58:31 -04:00
// THERMOMETER MODE
2021-01-29 06:31:58 -05:00
int requestTemperature();
int requestContinuous();
int stopContinuous();
int conversionReady();
float readTemperature();
int error() { int e = _error; _error = 0; return e; };
2021-01-29 06:31:58 -05:00
2022-11-02 14:58:31 -04:00
// High and low temperature 'alarm' flags.
2021-01-29 06:31:58 -05:00
int setLow(int8_t lo);
int getLow();
int setHigh(int8_t hi);
int getHigh();
2022-11-02 14:58:31 -04:00
// flags in configuration register => 1 = triggered since clear
2021-01-29 06:31:58 -05:00
int getHighFlag();
int clrHighFlag();
int getLowFlag();
int clrLowFlag();
2022-11-02 14:58:31 -04:00
// THERMOSTAT CONFIG
// - be sure to read datasheet first!
// - check the example
// - DQ pin must be same the oneWire pin!
2021-01-29 06:31:58 -05:00
int setOneWireMode(uint8_t VDD, uint8_t DQ);
2022-11-02 14:58:31 -04:00
int setPolarity(int activeState); // HIGH or LOW
2021-01-29 06:31:58 -05:00
int getPolarity();
int setThermostatMode();
private:
OneWire * _oneWire;
int _error;
int _reset() { _error = _oneWire->reset(); return _error; };
void _command(uint8_t cmd) { _oneWire->write(cmd); };
uint8_t _readByte() { return _oneWire->read(); };
2021-01-29 06:31:58 -05:00
uint8_t _waitForNVB();
int _getConfigFlag(uint8_t flag);
int _setConfigFlag(uint8_t flag);
int _clrConfigFlag(uint8_t flag);
int _readConfig();
int _writeConfig(uint8_t val);
uint8_t _VDD;
uint8_t _DQ;
};
2021-05-28 07:24:52 -04:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2022-11-02 14:58:31 -04:00