GY-63_MS5611/libraries/MCP9808_RT/mcp9808.h

97 lines
2.4 KiB
C
Raw Normal View History

2021-01-29 06:31:58 -05:00
#pragma once
//
// FILE: mcp9808.h
// AUTHOR: Rob Tillaart
2021-12-21 11:44:18 -05:00
// VERSION: 0.2.1
2021-01-29 06:31:58 -05:00
// PURPOSE: Arduino Library for I2C mcp9808 temperature sensor
// DATE: 2020-05-03
// URL: https://github.com/RobTillaart/MCP9808_RT
//
2021-11-08 14:21:36 -05:00
2021-01-29 06:31:58 -05:00
#include "Arduino.h"
#include "Wire.h"
// VALID ADDRESSES,
// max 8 sensors on one bus
// 24..31 == 0x18..0x1F
2021-12-21 11:44:18 -05:00
#define MCP9808_LIB_VERSION (F("0.2.1"))
2021-11-08 14:21:36 -05:00
// CONFIGURATION REGISTER MASKS
2021-01-29 06:31:58 -05:00
// check the datasheet for exact usage
2021-12-21 11:44:18 -05:00
#define MCP9808_THYSTERESIS 0x0600
#define MCP9808_SHUTDOWN 0x0100
#define MCP9808_CRIT_LOCK 0x0080
#define MCP9808_WIN_LOCK 0x0040
#define MCP9808_INT_CLEAR 0x0020
#define MCP9808_ALERT_STATUS 0x0010
#define MCP9808_ALERT_CTRL 0x0008
#define MCP9808_ALERT_SELECT 0x0004
#define MCP9808_ALERT_POLAR 0x0002
#define MCP9808_ALERT_MODE 0x0001
2021-01-29 06:31:58 -05:00
class MCP9808
{
public:
#if defined(ESP8266) || defined(ESP32)
// dataPin and clockPin can be used for ESP8266
MCP9808(const uint8_t address, const uint8_t dataPin = 255, const uint8_t clockPin = 255);
#else
MCP9808(const uint8_t address);
#endif
2021-11-08 14:21:36 -05:00
bool setAddress(const uint8_t address, TwoWire *wire = &Wire);
2021-01-29 06:31:58 -05:00
bool isConnected();
2021-11-08 14:21:36 -05:00
void setConfigRegister(uint16_t configuration);
2021-01-29 06:31:58 -05:00
uint16_t getConfigRegister();
2021-11-08 14:21:36 -05:00
void setTupper(float temperature);
2021-01-29 06:31:58 -05:00
float getTupper();
2021-11-08 14:21:36 -05:00
void setTlower(float temperature);
2021-01-29 06:31:58 -05:00
float getTlower();
2021-11-08 14:21:36 -05:00
void setTcritical(float temperature);
2021-01-29 06:31:58 -05:00
float getTcritical();
2021-11-08 14:21:36 -05:00
void setOffset(float offset = 0.0);
2021-01-29 06:31:58 -05:00
float getOffset();
float getTemperature();
2021-11-08 14:21:36 -05:00
2021-01-29 06:31:58 -05:00
// getStatus() returns 0..7
// to get latest status, getTemperature() must be called first
2021-11-08 14:21:36 -05:00
uint8_t getStatus();
2021-01-29 06:31:58 -05:00
2021-11-08 14:21:36 -05:00
void setResolution(uint8_t resolution = 3);
2021-01-29 06:31:58 -05:00
uint8_t getResolution();
uint16_t getManufacturerID();
uint8_t getDeviceID();
uint8_t getRevision();
// Reserved Register, not used
uint16_t getRFU();
private:
float _offset = 0;
uint8_t _status = 0; // 0..7
uint8_t _address;
TwoWire* _wire;
void writeFloat(uint8_t reg, float f);
float readFloat(uint8_t reg);
void writeReg8(uint8_t reg, uint8_t value);
uint8_t readReg8(uint8_t reg);
void writeReg16(uint8_t reg, uint16_t value);
uint16_t readReg16(uint8_t reg);
};
2021-11-08 14:21:36 -05:00
2021-01-29 06:31:58 -05:00
// -- END OF FILE --
2021-11-08 14:21:36 -05:00