2020-05-07 03:53:25 -04:00
|
|
|
#pragma once
|
2017-12-12 07:16:58 -05:00
|
|
|
//
|
|
|
|
// FILE: AM232X.h
|
|
|
|
// AUTHOR: Rob Tillaart
|
2020-05-07 03:53:25 -04:00
|
|
|
// PURPOSE: AM232X library for Arduino
|
|
|
|
// VERSION: 0.2.1
|
2017-12-12 07:16:58 -05:00
|
|
|
// HISTORY: See AM232X.cpp
|
2020-05-07 03:53:25 -04:00
|
|
|
// URL: https://github.com/RobTillaart/AM232X
|
2017-12-12 07:16:58 -05:00
|
|
|
//
|
|
|
|
|
|
|
|
#include "Wire.h"
|
|
|
|
#include "Arduino.h"
|
|
|
|
|
2020-05-07 03:53:25 -04:00
|
|
|
#define AM232X_LIB_VERSION "0.2.1"
|
2017-12-12 07:16:58 -05:00
|
|
|
|
|
|
|
#define AM232X_OK 0
|
2017-12-12 10:28:41 -05:00
|
|
|
#define AM232X_ERROR_UNKNOWN -10
|
2017-12-12 07:16:58 -05:00
|
|
|
#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
|
2017-12-12 10:28:41 -05:00
|
|
|
#define AM232X_ERROR_WRITE_COUNT -18
|
|
|
|
#define AM232X_MISSING_BYTES -19
|
2017-12-12 07:16:58 -05:00
|
|
|
/*
|
2020-05-07 03:53:25 -04: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
|
2017-12-12 07:16:58 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
class AM232X
|
|
|
|
{
|
|
|
|
public:
|
2017-12-22 07:05:31 -05:00
|
|
|
#ifdef ESP8266
|
|
|
|
void begin(uint8_t sda, uint8_t scl);
|
|
|
|
#endif
|
|
|
|
void begin();
|
2017-12-12 07:16:58 -05:00
|
|
|
|
|
|
|
int read();
|
|
|
|
int getModel();
|
|
|
|
int getVersion();
|
|
|
|
uint32_t getDeviceID();
|
|
|
|
|
|
|
|
int getStatus();
|
|
|
|
int getUserRegisterA();
|
|
|
|
int getUserRegisterB();
|
|
|
|
|
2017-12-12 10:28:41 -05:00
|
|
|
int setStatus(uint8_t value);
|
2017-12-12 07:16:58 -05:00
|
|
|
int setUserRegisterA(int value);
|
|
|
|
int setUserRegisterB(int value);
|
|
|
|
|
2020-05-07 03:53:25 -04:00
|
|
|
inline float getHumidity() { return humidity; };
|
|
|
|
inline float getTemperature() { return temperature; };
|
2017-12-12 07:16:58 -05:00
|
|
|
|
|
|
|
private:
|
2020-05-07 03:53:25 -04:00
|
|
|
|
2017-12-12 07:16:58 -05:00
|
|
|
uint8_t bits[8];
|
2020-05-07 03:53:25 -04:00
|
|
|
float humidity;
|
|
|
|
float temperature;
|
|
|
|
|
2017-12-12 10:28:41 -05:00
|
|
|
int _readRegister(uint8_t reg, uint8_t cnt);
|
|
|
|
int _writeRegister(uint8_t reg, uint8_t cnt, int16_t value);
|
2017-12-12 07:16:58 -05:00
|
|
|
uint16_t crc16(uint8_t *ptr, uint8_t len);
|
|
|
|
};
|
|
|
|
|
2020-05-07 03:53:25 -04:00
|
|
|
// END OF FILE
|