flipperzero-rs / flipperzero

Rust on the Flipper Zero
MIT License
501 stars 32 forks source link

Notification_messages example? #31

Closed ASoldo closed 1 year ago

ASoldo commented 1 year ago

Hi, can we get simple example how to use notification/notification_messages in rust? So far demo with DialogMessageButtons is only way we can interact with key presses. I am new to Rust and Flipper Zero and would really appropriate sample how to achieve this. Simple key input check and log message. Also GPIO would also be great to have some guides. Thank you!

dcoles commented 1 year ago

Hi @ASoldo,

Nice to hear that you're using the Flipper Zero as a way of learning Rust!

Sadly the flipperzero crate doesn't currently expose GPIO or notifications, but it's not too painful to do so using the low-level flipperzero-sys crate.

I've just added a notification example showing how this can be done. I still need to take a look at what GPIO would require.

ASoldo commented 1 year ago

That is great, thank you. If you could take a look at GPIO and simple toggle open pin/close pin, I will have more than enough to start playing. Since I do have all that in C. But I kinda like Rust and would like to switch to it 100%. This would help me a lot. Also, I can share demos faster and document stuff myself.

dcoles commented 1 year ago

I dug out the breadboard and was able to get a GPIO example working.

flipperzero-gpio

The biggest issue I found is that a number of the furi_hal_gpio_ functions are defined inline, thus there's no implementation in the SDK. Hence the need for reimplementing gpio_write.

Let me know if that's enough to get you unblocked. Happy hacking!

ASoldo commented 1 year ago

Thank you for your quick response, I do appreciate time and effort. I will try it right now (ERRATA: Works great!). I have one question rn, since you mention that gpio_write needs re implementation, is that something that will take some time to do or that could be done fairly easy? Just to know for future reference when I get back for more examples, will this example work or I will need to use exposed api.

dcoles commented 1 year ago

Awesome! Glad that it works for you!

Here's my implementation of gpio_write. It's almost a 1:1 port of furi_hal_gpio_write to Rust. The gpio_read function would be quite similar.

These functions should be good to go "as-is". The only real risk is if the C API has a breaking change.

Now that I've implemented these once with flipperzero-sys, it shouldn't be too much work to turn them into safe bindings. I'd like to do that before I release 0.6.0.