avaldebe / PMserial

Arduino library for PM sensors with serial interface
MIT License
53 stars 21 forks source link

add NO_SW_SERIAL_REQUIRED define for software serial compatibility #24

Closed pintert3 closed 2 years ago

pintert3 commented 2 years ago

I was having a problem with using this library alongside those that use software serial. If I deliberately wanted to avoid using Software serial in order to avoid clashes with other libraries like the Arduino-SDI-12, but needed this, I couldn't previously. This was my solution which worked.

It's 5months old though, I forgot to offer it earlier. But it's probably still relevant given that I see no new commits of recent.

pintert3 commented 2 years ago

Oh btw, this would mean making changes to the example code. I'm guessing the SoftwareSerial code would expecially suffer since it would expect it to already be imported. Could add that too.

pintert3 commented 2 years ago

Actually, on second thought, I might close this as I see it's a pretty minor problem with many ways to solve it. The HAS_SW_SERIAL should be enough of a hint to anyone having it in my opinion. I'll leave it for some days to see if any useful comments show up and then close.

avaldebe commented 2 years ago

Hi @pintert3

Thanks for the PR. The CI failed, but it seems the be unrelated.

I need to fix the CI before going forward. In the meantime, I would like you to address the the following points:

As fare as I can tell SW_REQUIRED is undefined by default. This changes the default behaviour of the library. In order to keep the default behaviour of the library, the compiling directive should be some thing like:

#if (defined(__AVR__) || defined(ESP8266)) && !defined(NO_SW_REQUIRED)
#define HAS_SW_SERIAL
#include <SoftwareSerial.h>
#endif

Also, could you add a line or two about it to this option README.md? A code snippet showing how to load the library would be just the thing.

pintert3 commented 2 years ago

Sorry for the delayed response, been quite busy in the last few months. I've changed the behaviour to NO_SW_SERIAL_REQUIRED and added a note in the readme.