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

139 lines
3.4 KiB
C
Raw Normal View History

2024-01-26 15:42:18 -05:00
#pragma once
//
// FILE: DS2438.h
// AUTHOR: Rob Tillaart
2024-01-27 11:16:37 -05:00
// VERSION: 0.1.1
2024-01-26 15:42:18 -05:00
// DATE: 2023-07-28
// PURPOSE: Arduino Library for DS2438 battery monitor
// URL: https://github.com/RobTillaart/DS2438
2024-01-27 11:16:37 -05:00
//
// DS2438
// +------------------+
// | 1 GND |
// | 2 Vsense+ |
// | 3 Vsense- |
// | 4 VAD |
// | 5 VDD |
// | 6 NC |
// | 7 NC |
// | 8 DQ |
// +------------------+
//
// | Pin | Description | Connect to |
// |:--------:|:------------------------------------|:-------------|
// | DQ | Data In/Out | processor |
// | VAD | General A/D input | |
// | VSENS+ | Battery current monitor input (+) | Battery |
// | VSENS- | Battery current monitor input (-) | Battery |
// | VDD | Power Supply (2.4V to 10.0V) | +5V |
// | GND | Ground | processor |
// | NC | No connect | - |
2024-01-26 15:42:18 -05:00
#include "Arduino.h"
#include "OneWire.h"
2024-01-27 11:16:37 -05:00
#define DS2438_LIB_VERSION (F("0.1.1"))
2024-01-26 15:42:18 -05:00
#define DS2438_INVALID -999
typedef uint8_t DeviceAddress[8];
class DS2438
{
public:
DS2438(OneWire * ow);
bool begin(uint8_t retries = 3);
bool isConnected(uint8_t retries = 3);
// TEMPERATURE
2024-01-27 11:16:37 -05:00
// unit is degrees Celsius
float readTemperature();
2024-01-26 15:42:18 -05:00
float getTemperature();
// VOLTAGE
2024-01-27 11:16:37 -05:00
// unit is Volts
float readVDD();
float getVDD();
float readVAD();
float getVAD();
2024-01-26 15:42:18 -05:00
// CURRENT
void setResistor(float resistor = 0.01); // in OHM
void enableCurrentMeasurement();
void disableCurrentMeasurement();
2024-01-27 11:16:37 -05:00
// unit is Ampere
float readCurrent();
2024-01-26 15:42:18 -05:00
float getCurrent();
void writeCurrentOffset(int value);
int readCurrentOffset();
2024-01-27 11:16:37 -05:00
// ICA + THRESHOLD
// Integrated Current Accumulator.
float readRemaining();
2024-01-26 15:42:18 -05:00
void writeThreshold(uint8_t value);
uint8_t readThreshold();
// only 4 values used.
// | value | THRESHOLD |
// |:-------:|:----------------:|
// | 0x00 | None (default) |
// | 0x40 | ±2 LSB |
// | 0x80 | ±4 LSB |
// | 0xC0 | ±8 LSB |
// TIME
void writeElapsedTimeMeter(uint32_t seconds);
uint32_t readElapsedTimeMeter();
2024-01-27 11:16:37 -05:00
uint32_t readDisconnectTime();
uint32_t readEndOfChargeTime();
2024-01-26 15:42:18 -05:00
// EEPROM
void writeEEPROM(uint8_t address, uint8_t value);
uint8_t readEEPROM(uint8_t address);
2024-01-27 11:16:37 -05:00
// CCA / DCA
// Charging + Discharge Current Accumulator
// unit = mVHr
void enableCCA();
void disableCCA();
float readCCA();
float readDCA();
2024-01-26 15:42:18 -05:00
// CONFIG REGISTER
void setConfigBit(uint8_t bit);
void clearConfigBit(uint8_t bit);
2024-01-27 11:16:37 -05:00
uint8_t getConfigRegister();
2024-01-26 15:42:18 -05:00
private:
OneWire * _oneWire;
uint8_t _scratchPad[9];
uint8_t _address[8];
bool _addressFound;
float _temperature;
2024-01-27 11:16:37 -05:00
float _vad;
float _vdd;
2024-01-26 15:42:18 -05:00
float _current;
float _inverseR; // 1/(4096*resistor) optimized.
void readScratchPad(uint8_t page);
void writeScratchPad(uint8_t page);
};
// -- END OF FILE --