playdate.getCrankPosition() can return 360.0

Docs for playdate.getCrankPosition():

Returns the absolute position of the crank (in degrees). Zero is pointing straight up parallel to the device. Turning the crank clockwise (when looking at the right edge of an upright device) increases the angle, up to a maximum value 359.9999. The value then resets back to zero as the crank continues its rotation.

Multiple times, on the Simulator, I’ve gotten this function to return 360.
I assume this is a simulator only issue while rapidly scrolling with mac trackpad.

Successive calls to playdate.getCrankPosition() return:

  0.0000000000000000
 72.0000000000000000
144.0000000000000000
216.0000000000000000
288.0000000000000000
360.0000000000000000
 72.0000000000000000
144.0000000000000000
216.0000000000000000
288.0000000000000000
360.0000000000000000
 72.0000000000000000...

Trivial reproduction program:

import "CoreLibs/crank"
local last = nil
function playdate.update()
    local next = playdate.getCrankPosition()
    if last ~= next then
        print(string.format("%.16f", next))
        last = next
    end
end

I assume somewhere there's a if (angle > 360) { angle = angle % 360) } that should be >= 360.

1 Like