golemparts / rppal

A Rust library that provides access to the Raspberry Pi's GPIO, I2C, PWM, SPI and UART peripherals.
MIT License
1.21k stars 96 forks source link

Add an example of graceful shutdown when SIGINT (GPIO) #144

Closed Eduardo-RFarias closed 5 months ago

Eduardo-RFarias commented 5 months ago

I’m new to Rust, and I’m really struggling to implement code that properly drops GPIO pins when Ctrl + C (SIGINT) is pressed. The documentation states that Rust doesn’t automatically call the drop method when a SIGINT signal is received. However, I would greatly appreciate an example of how to handle this situation.

golemparts commented 5 months ago

Welcome to Rust @Eduardo-RFarias 😁 . There's an example in the examples folder that shows you how to handle signals using the simple-signal crate. Check out gpio_blinkled_signals.rs.

Hope that helps!