RaspISteve
Posts: 98
Joined: Wed Oct 24, 2012 9:15 pm
Location: Cheltenham, UK

Terminating WiringPI

Thu Dec 03, 2015 11:23 pm

Guys,
I'm sure I've read it somewhere but now cannot find out what I should do once my program has finished with WiringPi. Being a bit old fashioned I expect to give all the GPIO thingys back or make them safe when I've finished with them. As I'm also using the interrupt extentions I also feel these really should be handled correctly and at least turned off.

I've looked repeatedly at the WiringPi pages, still think I've read that I should do something but I'm stuffed if I can find anything. I would expect to find something in the Setup reference page but it only includes what I should do when/before I start.

I've also checked through a number of (but not all) of the WiringPi examples but found nothing.

So, clever people, what am I missing?
Share and Enjoy.

User avatar
rpdom
Posts: 15567
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Terminating WiringPI

Fri Dec 04, 2015 6:06 am

Isn't that something like gpio.cleanup() ?

User avatar
buja
Posts: 507
Joined: Wed Dec 31, 2014 8:21 am
Location: Netherlands

Re: Terminating WiringPI

Fri Dec 04, 2015 6:32 am

RaspISteve wrote:...
So, clever people, what am I missing?
I think you are missing the fact that there is no closing statement in wiringpi, which is suprising. I did a very quick check on the examples on the wiringpi website, but I didn't see any closing statement.

asandford
Posts: 1997
Joined: Mon Dec 31, 2012 12:54 pm
Location: Waterlooville

Re: Terminating WiringPI

Fri Dec 04, 2015 7:14 pm

rpdom wrote:Isn't that something like gpio.cleanup() ?
Not implemented in WP, you have to 'rollback' any chaanges you made.
Clean up after yourself
So it’s a good idea to leave things tidy. The best way to do that is to switch off and set all the ports you’ve used back to inputs again at the end.

RaspISteve
Posts: 98
Joined: Wed Oct 24, 2012 9:15 pm
Location: Cheltenham, UK

Re: Terminating WiringPI

Fri Dec 04, 2015 8:21 pm

Guys,
I understand the roll-back of GPIOs, that's easy, but looking for suggestions on doing this with the interrupt functions. Where do they go when you're not there? Segmentation fault on the next unexpected event? Not ideal.

<SPECULATION> The only action that might be useful is to re-call the interrupt functions using a NULL pointer and hope the setting function is smart enough to work out what the caller is trying to do and pull the plug on the hardware.</SPECULATION>

Having to power-cycle while debugging is never ideal unless you're off out or off to bed.
Share and Enjoy.

User avatar
joan
Posts: 14468
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Terminating WiringPI

Fri Dec 04, 2015 8:33 pm

RaspISteve wrote:Guys,
I understand the roll-back of GPIOs, that's easy, but looking for suggestions on doing this with the interrupt functions. Where do they go when you're not there? Segmentation fault on the next unexpected event? Not ideal.
...
Linux will cancel any polls (interrupt handlers) when the process terminates. The worse that is going to happen is that a GPIO will be left exported which is no more than an inconvenience.

Personally I hold the view that if a user didn't want a GPIO left in a certain state then they should do something about that before ending the program.

Return to “Automation, sensing and robotics”