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

ADD getRefreshRate #95

Merged
merged 1 commit into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions src/playdate/bindings/display.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import utils

sdktype:
type PlaydateDisplay* {.importc: "const struct playdate_display", header: "pd_api.h".} = object
# directly mapped to C api
getWidth {.importsdk.}: proc (): cint
getHeight {.importsdk.}: proc (): cint
setRefreshRate {.importsdk.}: proc (rate: cfloat)
setInverted {.importc: "setInverted".}: proc (flag: cint) {.cdecl, raises: [].}
setScale {.importsdk.}: proc (s: cuint)
setMosaic {.importsdk.}: proc (x: cuint; y: cuint)
setFlipped {.importc: "setFlipped".}: proc (x: cint; y: cint) {.cdecl, raises: [].}
setOffset {.importsdk.}: proc (x: cint; y: cint)
setOffset* {.importsdk.}: proc (x: cint; y: cint)

# Called from Nim (src/playdate/display.nim)
setRefreshRate {.importc: "setRefreshRate".}: proc (rate: cfloat) {.cdecl, raises: [].}
setInverted {.importc: "setInverted".}: proc (flag: cint) {.cdecl, raises: [].}
setFlipped {.importc: "setFlipped".}: proc (x: cint; y: cint) {.cdecl, raises: [].}
16 changes: 15 additions & 1 deletion src/playdate/display.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,24 @@ export display
{.hint[DuplicateModuleImport]: off.}
import bindings/display {.all.}

var
refreshRate = 30f
## bookkeeping variable for refresh rate, because API does not provide a getter.
## Initial value is the rate that is set on device boot

proc setInverted* (this: ptr PlaydateDisplay, inverted: bool) =
privateAccess(PlaydateDisplay)
this.setInverted(if inverted: 1 else: 0)

proc setFlipped* (this: ptr PlaydateDisplay, x: bool, y: bool) =
privateAccess(PlaydateDisplay)
this.setFlipped(if x: 1 else: 0, if y: 1 else: 0)
this.setFlipped(if x: 1 else: 0, if y: 1 else: 0)


proc getRefreshRate* (this: ptr PlaydateDisplay): float32 =
refreshRate

proc setRefreshRate* (this: ptr PlaydateDisplay, rate: float32) =
privateAccess(PlaydateDisplay)
refreshRate = rate
this.setRefreshRate(rate)
Loading