Skip to content

Commit

Permalink
Update comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Erriez committed Aug 31, 2020
1 parent 3dbd05a commit c3f163d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
Binary file modified ErriezMHZ19B.pdf
Binary file not shown.
30 changes: 15 additions & 15 deletions src/ErriezMHZ19B.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ ErriezMHZ19B::~ErriezMHZ19B()
* \retval true
* Sensor detected.
* \retval false
* Sensor not detected.
* Sensor not detected, check wiring/power.
*/
bool ErriezMHZ19B::detect()
{
Expand Down Expand Up @@ -125,7 +125,10 @@ bool ErriezMHZ19B::isWarmingUp()
* \brief Check minimum interval between CO2 reads
* \details
* Not described in the datasheet, but it is the same frequency as the built-in LED blink.
* \return
* \retval true
* Ready to call readCO2().
* \retval false
* Conversion not completed.
*/
bool ErriezMHZ19B::isReady()
{
Expand Down Expand Up @@ -164,6 +167,7 @@ int16_t ErriezMHZ19B::readCO2()

// Check result
if (result == MHZ19B_RESULT_OK) {
// 16-bit CO2 value in response Bytes 2 and 3
result = (rxBuffer[2] << 8) | rxBuffer[3];
}

Expand Down Expand Up @@ -201,8 +205,9 @@ int8_t ErriezMHZ19B::getVersion(char *version, uint8_t versionLen)
if (result == MHZ19B_RESULT_OK) {
// Copy 4 ASCII characters to version array like "0443"
for (uint8_t i = 0; i < 4; i++) {
// Version in response Bytes 2..5
version[i] = rxBuffer[i + 2];
};
}
}

return result;
Expand Down Expand Up @@ -283,9 +288,9 @@ int8_t ErriezMHZ19B::setAutoCalibration(bool calibrationOn)
* \brief Get status automatic calibration (NOT DOCUMENTED)
* \retval <0
* MH-Z19B response error codes.
* \retval true
* \retval 1
* Automatic calibration on.
* \retval false
* \retval 0
* Automatic calibration off.
*/
int8_t ErriezMHZ19B::getAutoCalibration()
Expand All @@ -297,14 +302,8 @@ int8_t ErriezMHZ19B::getAutoCalibration()

// Check result
if (result == MHZ19B_RESULT_OK) {
// Response is located in Byte 7
if (rxBuffer[7] == 0x01) {
// On
result = 1;
} else if (rxBuffer[7] == 0x00) {
// Off
result = 0;
}
// Response is located in Byte 7: 0 = off, 1 = on
result = rxBuffer[7] & 0x01;
}

return result;
Expand All @@ -328,7 +327,8 @@ int8_t ErriezMHZ19B::startZeroCalibration()
/*!
* \brief Send serial command to sensor and read response
* \details
* Send command to sensor and read response, protected with a receive timeout.
* Send command to sensor and read response, protected with a receive timeout.\n
* Result is available in public rxBuffer[9].
* \param cmd
* Command Byte
* \param b3
Expand Down Expand Up @@ -370,7 +370,7 @@ int8_t ErriezMHZ19B::sendCommand(uint8_t cmd, byte b3, byte b4, byte b5, byte b6
// Clear receive buffer
memset(rxBuffer, 0, sizeof(rxBuffer));

// Wait until all data received from sensor
// Wait until all data received from sensor with receive timeout protection
tStart = millis();
while (_serial->available() < MHZ19B_SERIAL_RX_BYTES) {
if ((millis() - tStart) >= MHZ19B_SERIAL_RX_TIMEOUT_MS) {
Expand Down
14 changes: 7 additions & 7 deletions src/ErriezMHZ19B.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class ErriezMHZ19B
// Detect sensor by checking range response
bool detect();

// Is warming-up (minimum wait time after power-on)
// Minimum wait time after power-on
bool isWarmingUp();

// Minimum wait time between CO2 reads
Expand All @@ -109,14 +109,14 @@ class ErriezMHZ19B
// Get firmware version (NOT DOCUMENTED)
int8_t getVersion(char *version, uint8_t versionLen);

// Set/get CO2 range
// Set/get CO2 range, default 5000ppm)
int8_t setRange2000ppm();
int8_t setRange5000ppm();
int16_t getRange(); // (NOT DOCUMENTED)

// Set and get ABC (Automatic Baseline Correction)
// Set and get ABC, default on (Automatic Baseline Correction)
int8_t setAutoCalibration(bool calibrationOn);
int8_t getAutoCalibration(); // (NOT DOCUMENTED)
int8_t getAutoCalibration(); // (NOT DOCUMENTED)

// Start Zero Point Calibration manually at 400ppm
int8_t startZeroCalibration();
Expand All @@ -128,10 +128,10 @@ class ErriezMHZ19B
uint8_t rxBuffer[MHZ19B_SERIAL_RX_BYTES];

private:
Stream *_serial;
unsigned long _tLastReadCO2;
Stream *_serial; //!< Serial Stream pointer
unsigned long _tLastReadCO2; //!< Timestamp between readCO2() calls

// Serial communication functions
// CRC check on serial transmit/receive buffer
uint8_t calcCRC(uint8_t *data);
};

Expand Down

0 comments on commit c3f163d

Please sign in to comment.