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

Add feature to disable signal echo at runtime. #21

Closed
wants to merge 1 commit into from

Conversation

janLo
Copy link
Contributor

@janLo janLo commented Nov 30, 2017

This adds ESPiLight::setEchoEnabled(bool) to control if the receiver
should be temporary switched off while sending.

@janLo
Copy link
Contributor Author

janLo commented Nov 30, 2017

This is at the moment on top of #21 . I'll rebase it as soon as everything up to #21 got merged.

@@ -154,6 +154,7 @@ ESPiLight::ESPiLight(int8_t outputPin) {
_outputPin = outputPin;
_callback = nullptr;
_rawCallback = nullptr;
_echoEnabled = true;
Copy link
Owner

Choose a reason for hiding this comment

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

Would be fine to have it disable by default. It is basically for debugging only.

Copy link
Owner

@puuu puuu left a comment

Choose a reason for hiding this comment

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

Only minor changes, then ready to merge.

/**
* If set to true, the receiver will temporarely be disabled when sending.
*/
void setEchoEnabled(bool enabled);
Copy link
Owner

Choose a reason for hiding this comment

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

Arduino Style Guide for Writing Libraries says:

Try to avoid boolean arguments. Instead, consider providing two different functions with names the describe the differences between them.

How about: enableEcho() and diableEcho()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, I use this from a config-vaiable that is set to true or false. So for me a setter would be more convinient. I think thats the main reason why a boolean argument might be OK here: Its a setter.

Copy link
Owner

Choose a reason for hiding this comment

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

I see that it is more convenient for you, but the Style guide is clear in this case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think what the style guide means here is that you should not use boolean flags to influence the behaviour of a method. For example instead of

void connect(const String& host, const int port, const bool use_udp) {
... 
  if (use_udp) {
  ...
  }
}

write

void connectTcp(const String& host, const int port) {
  ...
}
void connectUdp(const String& host, const int port) {
  ...
}

Which comes from "Robert C. Martin's Clean Code Tip #12: Eliminate Boolean Arguments" wwich states, that a boolean flag is a sign that a function does more than one thing. As we actually do nothing here than setting a configuration value I would say its better that way.

Copy link
Owner

Choose a reason for hiding this comment

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

Did you have any example of an popular lib that use boolean setter?

Copy link
Contributor Author

Copy link
Owner

Choose a reason for hiding this comment

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

ok

@janLo
Copy link
Contributor Author

janLo commented Dec 4, 2017

Rebased before the API changes

This adds ESPiLight::setEchoEnabled(bool) to control if the receiver
should be temporary switched off while sending.

Signed-off-by: Jan Losinski <losinski@wh2.tu-dresden.de>
@puuu
Copy link
Owner

puuu commented Dec 5, 2017

merged in 799560c .
disable echo by default in 41e11dc .

Thanks!

@puuu puuu closed this Dec 5, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants