Skip to content

Commit

Permalink
optimied to save space
Browse files Browse the repository at this point in the history
Opimized to save space.
  • Loading branch information
ShaggyDog18 committed Sep 13, 2020
1 parent 3aa549f commit e7553a2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
23 changes: 6 additions & 17 deletions SD_MHZ19B.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,6 @@ uint16_t SD_MHZ19B::getDetectionRange(void) { // last byte is a pre-calculated
}


// returns temperature in degrees Celcium. Should be called after getPPM() function; otherwise, will return a previous value.
int8_t SD_MHZ19B::getTemp(void) {
return ((int8_t)_unionFrame.MHZ19B.temperature - 40); // corrected temperature
}


// undocumented features
// returns status of the module. Should be called after getPPM() function; otherwise, will return a previous value.
uint8_t SD_MHZ19B::getStatus(void) {
return _unionFrame.MHZ19B.status;
}


/*
// returns `Warming` status of the module (not documented, does not work).
bool SD_MHZ19::isWarming(void) {
Expand Down Expand Up @@ -212,10 +199,12 @@ bool SD_MHZ19B::_readData(void) {
#endif

// re-sort the buffer: swap high and low bytes since they are not in the "machine" order
uint8_t tmp;
tmp = _unionFrame.buffer[2];
_unionFrame.buffer[2] = _unionFrame.buffer[3];
_unionFrame.buffer[3] = tmp;
{
uint8_t tmp; // tmp does not exist outside of the {} scope
tmp = _unionFrame.buffer[2];
_unionFrame.buffer[2] = _unionFrame.buffer[3];
_unionFrame.buffer[3] = tmp;
}

// Debug - print received buffer
#ifdef DEBUG
Expand Down
12 changes: 9 additions & 3 deletions SD_MHZ19B.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Reads data from the module, fills in an internal data structure;
Returns PPM value, verified and valid (validate by calculating checkSum of the data received).
Return zero (false) if error during data read or CRC is not valid.
*/
uint16_t getPPM();
uint16_t getPPM(void);


/*
Expand All @@ -122,17 +122,23 @@ Returns temperature value in degrees Celcium, verified and valid (validate by ca
The value is available after successful getPPM() reading only; otherwise, returns previous value; to be called after getPPM() only.
Rather inaccurate ±3*C; is used for internal compensation.
*/
int8_t getTemp(void);
int8_t getTemp(void) const {
return ((int8_t)_unionFrame.MHZ19B.temperature - 40); // corrected temperature
}

// just to ensure compatibility
#define getTemperature() getTemp()


/*
Reads module status - not documented, always return 0
Returns status, verified and valid (validate by calculating checkSum of the data received).
The value is available after successful getPPM() reading only; otherwise, will return previous value; to be called after getPPM() only.
*/
uint8_t getStatus(void);
// undocumented features
uint8_t getStatus(void) const {
return _unionFrame.MHZ19B.status;
}


// experimental; undocumented; work in ptogress
Expand Down

0 comments on commit e7553a2

Please sign in to comment.