Polling accelerometer (or doing other timers) faster than per-frame?

,

Curious if I could do something satisfying akin to those old Tomy Pocket Games of the 70s-80s with the accelerometer, I put more accurately scaled acceleration into the AccelerometerTest SDK sample and tacked on tweakable friction and viscous drag when it was clear they were needed.

What I got in the end was surprisingly viable -- you can get something that feels very close to 1:1, there's an object under the glass, like a coin sliding on a hardcover book, if that makes sense. Natural interactions like shifting the Playdate under the object, or tilting slightly and tapping the bottom to release normal forces for an instant, totally work. There is definitely a place for fairly deep gameplay in it.

The one thing that doesn't work perfectly is tapping the edges of the Playdate: the object shifts a bit erratically. I think this is because the 50Hz sampling interval is just too long, and as a result the accelerometer can't properly sample the sequence of shock-rebound forces. I think I need to sample the accelerometer faster -- maybe 100-200Hz -- to smooth this out a bit. But I can't find a means to trigger callbacks out of step with the console's frame refresh. Update() happens per frame, and playdate.timers don't advance till they're explicitly updated with updateTimers() (typically in update()). The physics code I want to do at sub-frame intervals is very, very small: I suspect collision detection/restitution could be tabled until the frame update.

So:

  • Is there some way to goose the Playdate OS to trigger events at sub-frame intervals? To my great embarrassment I am not familiar with Lua coroutines and am not certain if I could just rig my own timer coroutine and get control ceded back to me at all frequently (without tanking the battery, of course).

  • If I could poll the accelerometer faster than 50Hz, would it actually give current data?

  • Does the accelerometer accumulate/average data between pollings or just return an instantaneous value?

(oh and of course simulating a mechanical handheld game is something that could easily be done, and done better, on a phone or tablet, but I would never, ever bother with that noise because of how much crap you have to push through to get code running on a phone, both as a dev and as a user. The ideation-implementation-test-release loop on the Playdate is incredible.)

3 Likes