From b5250a21edf33f1bf86361804ba367ab1969e73e Mon Sep 17 00:00:00 2001 From: August Quint <49277349+AugustQu@users.noreply.github.com> Date: Wed, 22 Jan 2020 15:51:49 +0100 Subject: [PATCH] added support for SDS011 --- src/payload.cpp | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/payload.cpp b/src/payload.cpp index 323e402b..2624c138 100644 --- a/src/payload.cpp +++ b/src/payload.cpp @@ -489,5 +489,41 @@ void PayloadConvert::addTime(time_t value) { buffer[cursor++] = (byte)((tx_period & 0x000000FF)); #endif } +#endif // PAYLOAD_ENCODER -#endif \ No newline at end of file +void PayloadConvert::addPM10( float value) { +#if (HAS_SDS011) +#if (PAYLOAD_ENCODER == 1) // plain + char tempBuffer[10+1]; + sprintf( tempBuffer, ",%5.1f", value); + addChars(tempBuffer, strlen(tempBuffer)); +#elif (PAYLOAD_ENCODER == 2 ) // packed + writeUint16( (uint16_t) (value*10) ); +#elif (PAYLOAD_ENCODER == 3 ) // Cayenne LPP dynamic + // TODO +#elif (PAYLOAD_ENCODER == 4 ) // Cayenne LPP packed + // TODO +#endif +#endif // HAS_SDS011 +} + +void PayloadConvert::addPM25( float value) { +#if (HAS_SDS011) +#if (PAYLOAD_ENCODER == 1) // plain + char tempBuffer[10+1]; + sprintf( tempBuffer, ",%5.1f", value); + addChars(tempBuffer, strlen(tempBuffer)); +#elif (PAYLOAD_ENCODER == 2 ) // packed + writeUint16( (uint16_t) (value*10) ); +#elif (PAYLOAD_ENCODER == 3 ) // Cayenne LPP dynamic + // TODO +#elif (PAYLOAD_ENCODER == 4 ) // Cayenne LPP packed + // TODO +#endif +#endif // HAS_SDS011 +} + +void PayloadConvert::addChars( char * string, int len) { + for (int i=0; i < len; i++) + addByte(string[i]); +}