GY-63_MS5611/libraries/DS18B20_RT/DS18B20.h

71 lines
1.4 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: DS18B20.h
// AUTHOR: Rob.Tillaart@gmail.com
2023-02-03 08:06:12 -05:00
// VERSION: 0.1.14
2021-01-29 06:31:58 -05:00
// DATE: 2017-07-25
// PUPROSE: library for DS18B20 temperature sensor with minimal footprint
2021-12-17 05:59:45 -05:00
// URL: https://github.com/RobTillaart/DS18B20_RT
2021-01-29 06:31:58 -05:00
//
2022-11-02 10:21:25 -04:00
// BOTTOM VIEW
2021-01-29 06:31:58 -05:00
//
2022-11-02 10:21:25 -04:00
// PIN MEANING
// /---+
// / o | 1 GND
// | o | 2 DATA
// \ o | 3 VCC
// \---+
2021-01-29 06:31:58 -05:00
//
2021-12-17 05:59:45 -05:00
2023-02-03 08:06:12 -05:00
#define DS18B20_LIB_VERSION (F("0.1.14"))
2021-01-29 06:31:58 -05:00
#include <OneWire.h>
2022-11-02 10:21:25 -04:00
// Error Code
2021-01-29 06:31:58 -05:00
#define DEVICE_DISCONNECTED -127
#define DEVICE_CRC_ERROR -128
2022-11-02 10:21:25 -04:00
// config codes
2021-01-29 06:31:58 -05:00
#define DS18B20_CLEAR 0x00
#define DS18B20_CRC 0x01
typedef uint8_t DeviceAddress[8];
typedef uint8_t ScratchPad[9];
class DS18B20
{
public:
2021-12-17 05:59:45 -05:00
explicit DS18B20(OneWire * ow);
2021-06-23 10:41:54 -04:00
bool begin(uint8_t retries = 3);
2023-02-03 08:06:12 -05:00
2021-01-29 06:31:58 -05:00
void requestTemperatures(void);
bool isConversionComplete(void);
2023-02-03 08:06:12 -05:00
float getTempC(void);
2021-12-17 05:59:45 -05:00
bool getAddress(uint8_t * buf);
2021-01-29 06:31:58 -05:00
2023-02-03 08:06:12 -05:00
bool setResolution(uint8_t resolution = 9);
uint8_t getResolution();
void setConfig(uint8_t config);
uint8_t getConfig();
2021-01-29 06:31:58 -05:00
private:
void readScratchPad(uint8_t *, uint8_t);
DeviceAddress _deviceAddress;
2021-12-17 05:59:45 -05:00
OneWire* _oneWire;
bool _addressFound;
2023-02-03 08:06:12 -05:00
uint8_t _resolution;
2021-01-29 06:31:58 -05:00
uint8_t _config;
};
2021-12-17 05:59:45 -05:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2021-12-17 05:59:45 -05:00