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

DigitalInput::wait() optimizations #21

Merged
merged 3 commits into from
Feb 10, 2022
Merged

DigitalInput::wait() optimizations #21

merged 3 commits into from
Feb 10, 2022

Conversation

necroware
Copy link
Owner

Trying to get some higher performance by reducing the time spent in the DigitalInput::wait() function. Hopefully this will provide a little bit more time to read the bits from the data lines in time. Unfortunately even higher optimization would require a complete rewrite of the data reading structures. This is a try to fix the bug but keep the code simple.

@necroware necroware added bug Something isn't working enhancement New feature or request labels Feb 7, 2022
@necroware necroware self-assigned this Feb 7, 2022
@necroware necroware linked an issue Feb 7, 2022 that may be closed by this pull request
@necroware necroware merged commit 3d215c8 into main Feb 10, 2022
@creopard
Copy link
Contributor

creopard commented Jun 20, 2022

Unfortunately this fix in DigitalPin.h does not seem to work.
The lines:

if (edge == Edge::falling) {
  return waitImpl(timeout, [](uint8_t a, uint8_t) {return a;});
}
if (edge == Edge::rising) {
  return waitImpl(timeout, [](uint8_t, uint8_t b) {return b;});
}
// edge == Edge::rising
return waitImpl(timeout, [](uint8_t a, uint8_t b) {return a|b;});

will break the Sidewinder 3D implementation and the Sidewinder will then be recognized as 2 axis, 2 button joystick

replacing that section
uint8_t read() const {
with
bool read() const {

and replacing the coding with the original implementation (and the renamed method "read()") fixes that again:

auto last = read();
for (; timeout; timeout--) {
  const auto next = read();
  if (last == next) {
    continue;
  }
  switch (edge) {
    case Edge::falling:
      if (last > next) {
        return timeout;
      }
      break;
    case Edge::rising:
      if (last < next) {
        return timeout;
      }
      break;
    case Edge::any:
      return timeout;
  }
  last = next;
}
return 0u;

This may also be applicable for the Logitech implementation.
Sorry, I had no time to investigate further, but at the current state the Sidewinder 3D implementation is broken (the last release v0.2.1 is of course not affected by this)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sidewinder 3-bit data reading is too slow
2 participants