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

95 lines
2.1 KiB
C
Raw Normal View History

#pragma once
//
// FILE: AM232X.h
// AUTHOR: Rob Tillaart
// PURPOSE: AM232X library for Arduino
2021-10-19 05:51:07 -04:00
// VERSION: 0.3.3
// HISTORY: See AM232X.cpp
// URL: https://github.com/RobTillaart/AM232X
//
2021-02-03 11:20:20 -05:00
// Bottom view
2021-01-29 06:31:58 -05:00
// +---+
// VDD |o |
// SDA |o |
// GND |o |
// SCL |o |
// +---+
#include "Arduino.h"
2021-01-29 06:31:58 -05:00
#include "Wire.h"
2021-10-19 05:51:07 -04:00
#define AM232X_LIB_VERSION (F("0.3.3"))
2021-01-29 06:31:58 -05:00
#define AM232X_OK 0
#define AM232X_ERROR_UNKNOWN -10
#define AM232X_ERROR_CONNECT -11
#define AM232X_ERROR_FUNCTION -12
#define AM232X_ERROR_ADDRESS -13
#define AM232X_ERROR_REGISTER -14
#define AM232X_ERROR_CRC_1 -15
#define AM232X_ERROR_CRC_2 -16
#define AM232X_ERROR_WRITE_DISABLED -17
#define AM232X_ERROR_WRITE_COUNT -18
#define AM232X_MISSING_BYTES -19
/*
2021-02-03 11:20:20 -05:00
from datasheet
0x80: not support function code
0x81: Read an illegal address
0x82: write data beyond the scope
0x83: CRC checksum error
0x84: Write disabled
*/
class AM232X
{
2021-04-07 07:31:22 -04:00
public:
2021-02-03 11:20:20 -05:00
explicit AM232X(TwoWire *wire = &Wire);
2021-01-29 06:31:58 -05:00
2020-11-27 05:10:47 -05:00
#if defined (ESP8266) || defined(ESP32)
2021-02-03 11:20:20 -05:00
bool begin(uint8_t sda, uint8_t scl);
2020-11-27 05:10:47 -05:00
#endif
2021-02-03 11:20:20 -05:00
bool begin();
2021-04-07 07:31:22 -04:00
// datasheet 8.2 - wake up is min 800 us max 3000 us
bool isConnected(uint16_t timeout = 3000);
2021-02-03 11:20:20 -05:00
int read();
int getModel();
int getVersion();
uint32_t getDeviceID();
int getStatus();
int getUserRegisterA();
int getUserRegisterB();
int setStatus(uint8_t value);
int setUserRegisterA(int value);
int setUserRegisterB(int value);
inline float getHumidity() { return humidity; };
inline float getTemperature() { return temperature; };
2021-04-07 07:31:22 -04:00
bool wakeUp() { return isConnected(); };
private:
uint8_t bits[8];
float humidity;
float temperature;
2021-02-03 11:20:20 -05:00
int _readRegister(uint8_t reg, uint8_t cnt);
int _writeRegister(uint8_t reg, uint8_t cnt, int16_t value);
int _getData(uint8_t length);
uint16_t _crc16(uint8_t *ptr, uint8_t len);
2021-04-07 07:31:22 -04:00
TwoWire* _wire;
};
2020-11-27 05:10:47 -05:00
// -- END OF FILE --