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

Allow the message timeout value to be set at run-time. #294

Merged
merged 1 commit into from
Aug 5, 2017

Conversation

crankyoldgit
Copy link
Owner

Ensure the timeout value won't allow a value larger than we can store.

Copy link
Collaborator

@roidayan roidayan left a comment

Choose a reason for hiding this comment

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

Beside my comment about definition s hta will add readability looks good to me.

src/IRrecv.cpp Outdated
irparams.recvpin = recvpin;
irparams.bufsize = bufsize;
// Ensure we are going to be able to store all possible values in the
// capture buffer.
irparams.timeout = std::min(timeout, (uint8_t) (RAWTICK * UINT16_MAX / 1000));
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest to have a definition for the maximum allowed. I.e. MAX_TIMEOUT

Copy link
Collaborator

Choose a reason for hiding this comment

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

MAX_TIMEOUT_MS for consistency

src/IRrecv.cpp Outdated
DPRINTLN(")]");
// We really should never get a value of 0, except as the last value
// in the buffer. If that is the case, then assume infinity and return true.
if (measured == 0) return true;
return measured >= ticksLow(std::min(desired, TIMEOUT_MS * 1000),
return measured >= ticksLow(std::min(desired,
(uint32_t) (irparams.timeout * 1000)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't there MS_TO_USEC ? If not can add for readability and it doesn't cost

@crankyoldgit
Copy link
Owner Author

crankyoldgit commented Aug 4, 2017 via email

@crankyoldgit
Copy link
Owner Author

Changes done.

src/IRrecv.h Outdated
@@ -18,6 +18,7 @@
#define HEADER 2U // Usual nr. of header entries.
#define FOOTER 2U // Usual nr. of footer (stop bits) entries.
#define OFFSET_START 1U // Usual rawbuf entry to start processing from.
#define MS_TO_USEC 1000U // Convert milli-Seconds to micro-Seconds.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I suggest here

#define MS_TO_USEC(x) (x *1000)

Then usage is

MS_TO_USEC(irparams.timeout)

Copy link
Owner Author

Choose a reason for hiding this comment

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

even better ;-)

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done (again).

Copy link
Collaborator

@roidayan roidayan left a comment

Choose a reason for hiding this comment

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

All good. Just asking if casting is redundant or causing warning if it's not there.

src/IRrecv.cpp Outdated
@@ -427,17 +432,18 @@ bool IRrecv::matchAtLeast(uint32_t measured, uint32_t desired,
DPRINT(". Matching: ");
DPRINT(measured);
DPRINT(" >= ");
DPRINT(ticksLow(std::min(desired, TIMEOUT_MS * 1000), tolerance));
DPRINT(ticksLow(std::min(desired, (uint32_t) MS_TO_USEC(irparams.timeout)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't casting redundant here?

Copy link
Owner Author

Choose a reason for hiding this comment

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

No. Lint and compiler error/warnings otherwise. The later parameter defaults to an int.

src/IRrecv.cpp Outdated
return measured >= ticksLow(std::min(desired, TIMEOUT_MS * 1000),
tolerance);
return measured >= ticksLow(
std::min(desired, (uint32_t) MS_TO_USEC(irparams.timeout)), tolerance);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Isn't casting redundant here?

Copy link
Owner Author

Choose a reason for hiding this comment

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

No. Lint and compiler error/warnings otherwise. The later parameter defaults to an int.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok so all looks good to me.

Copy link
Owner Author

Choose a reason for hiding this comment

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

But now with the macro/function, it doesn't. So castings removed.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Updated. 3rd time is the charm. I hope.

Ensure the timeout value won't allow a value larger than we can store.
@crankyoldgit crankyoldgit merged commit 7642970 into master Aug 5, 2017
@crankyoldgit crankyoldgit deleted the set_timeout branch August 5, 2017 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants