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 binding for setSerialMessageCallback #327

Merged
merged 6 commits into from
May 1, 2024

Conversation

paulyoung
Copy link
Contributor

Adds bindings and an example for playdate->system->setSerialMessageCallback

Please also see https://devforum.play.date/t/feature-request-add-a-userdata-argument-to-setserialmessagecallback/17333

Thanks!

@github-actions github-actions bot added docs Improvements or additions to documentation api About Playdate API, bindings and all over that. labels Apr 25, 2024
api/system/src/lib.rs Outdated Show resolved Hide resolved
@paulyoung
Copy link
Contributor Author

Relates to #283

@paulyoung paulyoung requested a review from boozook April 27, 2024 19:15
@boozook
Copy link
Owner

boozook commented Apr 27, 2024

Thank you so much! I have to play with it and think about it a little bit.

Copy link
Owner

@boozook boozook left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed your solution as well as entire task and have to say that I was wrong when suggested "typed storage".
There is should be solution dramatically simpler.
Also in my example all callbacks are "oneshot" and removing immediately after call with store.remove::<F>() and later entire storage with clean_store. That's not needed for this case. This is like update callback registering, so we should be able set callback, receive calls multiple times and optionally "unsubscribe".

I've tested it this way:

# Build, install, run:
cargo playdate run -p=playdate-system --example=set-serial-message-callback --features=sys/lang-items,sys/entry-point --device
--no-read

# Then send messages:
pdtool send msg "one" && pdtool read
pdtool send msg "two" && pdtool read
pdtool send msg "three" && pdtool read
# ...

# Output:
# serial_message_callback: one
# PANIC: [api/system/src/storage.rs@24] "missed callback"

I've created PR for your PR ;)

@paulyoung
Copy link
Contributor Author

Strange, I'm running into #326 on this branch despite having pulled in the fixes for that issue.

@paulyoung
Copy link
Contributor Author

paulyoung commented May 1, 2024

For some reason I'm still hitting ERROR: missing field `serial_num` at line 31 column 9

@paulyoung
Copy link
Contributor Author

@boozook thanks for the PR. I was thinking this should be similar to set_update_callback but have been sick for a few days and didn't follow up.

@paulyoung
Copy link
Contributor Author

To clarify, when I run cargo playdate run -p=playdate-system --example=set-serial-message-callback --features=sys/lang-items,sys/entry-point --device --no-read I hit the ERROR: missing field serial_num at line 31 column 9 error but otherwise everything on this branch seems to work for me so I don't think that's related or should hold up merging this PR.

I can try again once it's on main and follow up in #326.

@boozook
Copy link
Owner

boozook commented May 1, 2024

I hope you doing well.

Just to be sure that you're using latest version:
Did you install cargo-playdate from this branch? If not so, plz do cargo run -p=cargo-playdate -- run -p=playdate-system --example=set-serial-message-callback --features=sys/lang-items,sys/entry-point --device --no-read.

@boozook boozook merged commit 28d8ba0 into boozook:main May 1, 2024
27 checks passed
boozook added a commit that referenced this pull request May 1, 2024
@paulyoung paulyoung deleted the paulyoung/serial-message-callback branch May 2, 2024 01:05
@paulyoung
Copy link
Contributor Author

Did you install cargo-playdate from this branch?

@boozook I did. I'll try again now from main and report back in #326

@boozook boozook linked an issue Jun 15, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api About Playdate API, bindings and all over that. docs Improvements or additions to documentation
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Add setSerialMessageCallback
2 participants