Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct issue #16 #17

Merged
merged 3 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/PMserial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,15 @@ void SerialPM::decodeBuffer(bool tsi_mode, bool truncated_num)
hcho = buff2word(28) * 1e-3;
break;
case PMS5003T:
temp = int8_t(n5p0) * 1e-1; // cast to signed integer
rhum = n10p0 * 1e-1;
temp = int16_t(n5p0) * 1e-1 + temp_offset; // cast to signed integer 16bits
rhum = n10p0 * 1e-1 + rhum_offset;
n5p0 = 0;
n10p0 = 0;
break;
case PMS5003ST:
hcho = buff2word(28) * 1e-3;
temp = int8_t(buff2word(30)) * 1e-1; // cast to signed integer
rhum = buff2word(32) * 1e-1;
temp = int16_t(buff2word(30)) * 1e-1 + temp_offset; // cast to signed integer 16bits
rhum = buff2word(32) * 1e-1 + rhum_offset;
break;
default:
break;
Expand Down
11 changes: 11 additions & 0 deletions src/PMserial.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ class SerialPM
inline bool has_number_concentration() { return (status == OK) && (pms != PMS3003); }
inline bool has_temperature_humidity() { return (status == OK) && ((pms == PMS5003T) || (pms == PMS5003ST)); }
inline bool has_formaldehyde() { return (status == OK) && ((pms == PMS5003S) || (pms == PMS5003ST)); }

// adding offsets works well in normal range
// might introduce under- or overflow at the ends of the sensor range
void set_rhum_offset(float offset) { rhum_offset = offset; };
void set_temp_offset(float offset) { temp_offset = offset; };
float get_rhum_offset() { return rhum_offset; };
float get_temp_offset() { return temp_offset; };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that this methods could be inline-ed
Also, I see the need for set_rhum_offset/set_temp_offset but I'm not so sure about get_rhum_offset/get_temp_offset

#ifdef PMS_DEBUG
#ifdef HAS_HW_SERIAL
inline void print_buffer(Stream &term, const char *fmt)
Expand All @@ -154,6 +161,10 @@ class SerialPM
uint8_t rx, tx; // Serial1 pins on ESP32
#endif

// Correct Temperature & Humidity
float temp_offset = 0.0;
float rhum_offset = 0.0;

// utility functions
STATUS trigRead();
bool checkBuffer(size_t bufferLen);
Expand Down