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

122 lines
2.7 KiB
C
Raw Normal View History

2021-08-23 13:33:25 -04:00
#pragma once
//
// FILE: MTP40C.h
// AUTHOR: Rob Tillaart
// DATE: 2021-08-20
2022-11-18 08:05:26 -05:00
// VERSION: 0.2.2
2021-09-02 01:40:38 -04:00
// PURPOSE: Arduino library for MTP40C + MTP40D CO2 sensor
2021-08-23 13:33:25 -04:00
// URL: https://github.com/RobTillaart/MTP40C
//
2022-11-18 08:05:26 -05:00
// HISTORY: see changelog.md
2021-08-23 13:33:25 -04:00
//
// Based upon datasheet June 2020, version 2.0
//
#include "Arduino.h"
2022-11-18 08:05:26 -05:00
#define MTP40_LIB_VERSION (F("0.2.2"))
2021-08-23 13:33:25 -04:00
2021-12-22 05:36:50 -05:00
#define MTP40_DEFAULT_ADDRESS 0x64
2021-08-23 13:33:25 -04:00
2021-12-22 05:36:50 -05:00
#define MTP40_OK 0x00
#define MTP40_INVALID_AIR_PRESSURE 0x01
#define MTP40_INVALID_GAS_LEVEL 0x02
#define MTP40_INVALID_ADDRESS 0xFF
2021-09-02 01:40:38 -04:00
class MTP40
2021-08-23 13:33:25 -04:00
{
public:
2021-09-02 01:40:38 -04:00
MTP40(Stream * str);
2021-08-23 13:33:25 -04:00
bool begin(uint8_t address = 0x64);
bool isConnected();
uint8_t getAddress();
2021-09-02 01:40:38 -04:00
bool setAddress(uint8_t address = 0x64); // default
2021-08-23 13:33:25 -04:00
2021-09-02 01:40:38 -04:00
float getAirPressureReference();
2021-08-23 13:33:25 -04:00
bool setAirPressureReference(float apr);
2021-09-02 01:40:38 -04:00
uint16_t getGasConcentration(); // returns PPM
void suppressError(bool se) { _suppressError = se; };
bool getSuppressError() { return _suppressError; };
2021-08-23 13:33:25 -04:00
// CALIBRATION FUNCTIONS
// READ DATASHEET !!
bool setSinglePointCorrection(float spc);
bool getSinglePointCorrectionReady();
bool openSelfCalibration();
bool closeSelfCalibration();
uint8_t getSelfCalibrationStatus();
bool setSelfCalibrationHours(uint16_t hrs);
uint16_t getSelfCalibrationHours();
void setGenericAddress() { _useAddress = false; };
void setSpecificAddress() { _useAddress = true; };
bool useSpecificAddress() { return _useAddress; };
2022-11-18 08:05:26 -05:00
// set timeout of serial communication.
2021-08-23 13:33:25 -04:00
void setTimeout(uint32_t to = 100) { _timeout = to; };
uint32_t getTimeout() { return _timeout; };
uint32_t lastRead() { return _lastRead; };
2022-11-18 08:05:26 -05:00
// 2 = MTP40C
// 3 = MTP40D
2021-09-02 01:40:38 -04:00
uint8_t getType() { return _type; };
int lastError();
2021-08-23 13:33:25 -04:00
/////////////////////////
2021-09-02 01:40:38 -04:00
protected:
2021-08-23 13:33:25 -04:00
Stream * _ser;
2021-09-02 01:40:38 -04:00
uint8_t _buffer[24]; // should be big enough.
uint8_t _address = 64;
2021-08-23 13:33:25 -04:00
2021-09-02 01:40:38 -04:00
bool _useAddress = false;
uint32_t _timeout = 100;
uint32_t _lastRead = 0;
2021-08-23 13:33:25 -04:00
2021-09-02 01:40:38 -04:00
float _airPressureReference = 0;
uint16_t _gasLevel = 0;
uint8_t _type = 0xFF;
bool _suppressError = false;
int _lastError = MTP40_OK;
2021-08-23 13:33:25 -04:00
bool request(uint8_t *data, uint8_t cmdlen, uint8_t anslen);
uint16_t CRC(uint8_t *data, uint16_t len);
2021-09-02 01:40:38 -04:00
};
2021-08-23 13:33:25 -04:00
2021-09-02 01:40:38 -04:00
/////////////////////////////////////////////////////////////
//
// DERIVED CLASSES
//
class MTP40C : public MTP40
{
public:
MTP40C(Stream * str);
2021-08-23 13:33:25 -04:00
};
2021-09-02 01:40:38 -04:00
class MTP40D : public MTP40
{
public:
MTP40D(Stream * str);
// TODO
// I2C interface
// PWM interface
};
2021-08-23 13:33:25 -04:00
2021-09-02 01:40:38 -04:00
// -- END OF FILE --
2021-12-22 05:36:50 -05:00