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

Bluetooth packet timing #158

Open
BareTuna opened this issue Sep 5, 2024 · 0 comments
Open

Bluetooth packet timing #158

BareTuna opened this issue Sep 5, 2024 · 0 comments

Comments

@BareTuna
Copy link

BareTuna commented Sep 5, 2024

Hi, I've been trying my hand at making a bluetooth controller, but I seem to be struggling to get the timings right. Sometimes the switch eats my input, and sometimes it holds a button longer than I pressed it. Does anyone know what's going on?

I thought at first, that when you increment the timer byte, the switch reads the next packet, and ignores subsequent ones. It worked in manual testing, but it didn't work as well when speeding it up.

My goal is to achieve one full button press in 4/60ths of a second, or 2/60ths spent holding, 2/60ths spend releasing. I've tried a few ideas below, but nothing seems to help make it fully consistent.

Quantizing

  • Always sleep 1/60th second before sending (no quantizing)
  • Wait to send packet at the next 1/60th second

Adding vs Measuring elapsed

  • Adding: += whatever the elapsed time was from now to previous send
  • Measuring: Start an epoch after pairing, and measure elapsed time, convert to ticks

The difference between these methods are subtle. If in a perfect world the controller sent packets 16.7ms, 16.7ms, 16.7ms, then the adding method goes 16, 32, 48. But the measuring method goes 16, 33, 50.

Setting tick rate

  • 60 tps (ticks per second)
    • In a perfect world where every packet is sent 1/60th per second, this would increment by one every packet
  • 200 tps
  • 4000 tps
  • 222.61 tps
  • 60 × 256 tps
    • Just for fun
    • In a perfect world where every packet is sent 1/60th per second apart, this would appear to increment by one, but if it is off slightly, it gives a totally different number

Given any combination of these, I get the same/similar results. I'm rapid firing 10 full buttons presses in a row on the Test Controller Buttons screen. I often get all 10 presses, sometimes 9 or 8, and rarely 7 or fewer.

Any thoughts?

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

No branches or pull requests

1 participant