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

125 lines
2.7 KiB
C
Raw Normal View History

2020-11-27 05:10:47 -05:00
#pragma once
//
// FILE: AD524X.h
// AUTHOR: Rob Tillaart
2024-03-16 17:06:10 -04:00
// VERSION: 0.5.1
// PURPOSE: I2C digital PotentioMeter AD5241 AD5242
// DATE: 2013-10-12
2020-11-27 05:10:47 -05:00
// URL: https://github.com/RobTillaart/AD524X
2023-01-11 10:35:57 -05:00
#include "Arduino.h"
2020-11-27 05:10:47 -05:00
#include "Wire.h"
2024-03-16 17:06:10 -04:00
#define AD524X_LIB_VERSION (F("0.5.1"))
2021-01-29 06:31:58 -05:00
2021-12-10 08:52:27 -05:00
#define AD524X_OK 0
#define AD524X_ERROR 100
2021-01-29 06:31:58 -05:00
2023-01-11 10:35:57 -05:00
#define AD524X_MIDPOINT 127
class AD524X
{
public:
2023-02-26 11:03:39 -05:00
AD524X(const uint8_t address, TwoWire *wire = &Wire);
2021-01-29 06:31:58 -05:00
bool begin();
bool isConnected();
2024-03-16 17:06:10 -04:00
uint8_t getAddress();
2022-08-13 13:31:52 -04:00
2023-01-11 10:35:57 -05:00
// RESET
uint8_t reset(); // reset both channels to AD524X_MIDPOINT and O1/O2 to LOW
uint8_t zeroAll(); // set both channels to 0 and O1/O2 to LOW
2021-01-29 06:31:58 -05:00
2023-01-11 10:35:57 -05:00
// READ WRITE
2021-01-29 06:31:58 -05:00
uint8_t read(const uint8_t rdac);
uint8_t write(const uint8_t rdac, const uint8_t value);
uint8_t write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2);
2023-01-11 10:35:57 -05:00
// IO LINES
2022-10-25 11:57:23 -04:00
uint8_t setO1(const uint8_t value = HIGH); // HIGH (default) / LOW
uint8_t setO2(const uint8_t value = HIGH); // HIGH (default) / LOW
2021-01-29 06:31:58 -05:00
uint8_t getO1();
uint8_t getO2();
uint8_t midScaleReset(const uint8_t rdac);
2023-01-11 10:35:57 -05:00
uint8_t pmCount();
2021-01-29 06:31:58 -05:00
2023-01-11 10:35:57 -05:00
// DEBUGGING
2022-10-25 11:57:23 -04:00
uint8_t readBackRegister(); // returns the last value written in register.
2021-01-29 06:31:58 -05:00
2022-10-25 11:57:23 -04:00
// experimental - to be tested - use at own risk
uint8_t shutDown(); // datasheet P15
2021-01-29 06:31:58 -05:00
2023-01-11 10:35:57 -05:00
2021-01-29 06:31:58 -05:00
protected:
uint8_t _pmCount = 0;
2021-10-16 15:39:45 -04:00
uint8_t send(const uint8_t cmd, const uint8_t value);
2021-01-29 06:31:58 -05:00
uint8_t _address;
uint8_t _lastValue[2];
uint8_t _O1;
uint8_t _O2;
2023-12-05 09:50:43 -05:00
TwoWire * _wire;
};
2021-01-29 06:31:58 -05:00
2021-10-16 15:39:45 -04:00
//////////////////////////////////////////////////////////////
//
2023-12-05 09:50:43 -05:00
// DERIVED CLASSES AD5241 AD5242
2022-08-13 13:31:52 -04:00
//
2021-01-29 06:31:58 -05:00
class AD5241 : public AD524X
{
public:
AD5241(const uint8_t address, TwoWire *wire = &Wire);
2023-02-26 11:03:39 -05:00
uint8_t write(const uint8_t value);
uint8_t write(const uint8_t value, const uint8_t O1, const uint8_t O2);
uint8_t write(const uint8_t rdac, const uint8_t value);
uint8_t write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2);
2021-01-29 06:31:58 -05:00
};
2021-10-16 15:39:45 -04:00
2021-01-29 06:31:58 -05:00
class AD5242 : public AD524X
{
public:
AD5242(const uint8_t address, TwoWire *wire = &Wire);
};
2023-12-05 09:50:43 -05:00
//////////////////////////////////////////////////////////////
//
// DERIVED CLASSES AD5280 AD5282
//
class AD5280 : public AD524X
{
public:
AD5280(const uint8_t address, TwoWire *wire = &Wire);
uint8_t write(const uint8_t value);
uint8_t write(const uint8_t value, const uint8_t O1, const uint8_t O2);
uint8_t write(const uint8_t rdac, const uint8_t value);
uint8_t write(const uint8_t rdac, const uint8_t value, const uint8_t O1, const uint8_t O2);
};
class AD5282 : public AD524X
{
public:
AD5282(const uint8_t address, TwoWire *wire = &Wire);
};
2023-02-03 02:41:34 -05:00
// -- END OF FILE --
2022-08-13 13:31:52 -04:00