Hide _triggerMode under ONE_PIN_ENABLED define

Issue #23 resolved
Egor Panfilov created an issue

Hi, I'm investigating your library for a very long time and found some things that could be made in other way.

Firstly, I think it could be a good idea to hide every occurence of _triggerMode member such as in costructor and in header file because when ONE_PIN_ENABLED is set to false it presence only as an unused variable.

That's all for now. I think I'll found something interesting for you later.

Comments (2)

  1. Tim Eckel repo owner

    Actually, the library uses the _triggerMode member both when ONE_PIN_ENABLED is set to true and when it's set to false. It still needs to set the output pin mode (you don't need to do that in your code as the library does it for you). In NewPing.cpp see lines 41, 129 and 139. Or, do a search for "_triggerMode" and you'll see that it's used for both when it equals true and doesn't equal true.

    If you've been setting the trigger pin mode to output in your code, you're doing it twice, as the library does it for you. Notice how the sample sketches don't set the pin modes.

    Tim

  2. Egor Panfilov reporter

    I found it later, so, it's my mistake. I've made decision too fast.

    But next interesting thing is the order of operations in ping_trigger. Why are you firstly initiating trigger but check echo pin high from last ping only later? Lines 143, 148 and 169, 174.

    Is there any reason for trigger first and only then check for echo HIGH?

    Regards, Egor

  3. Log in to comment