pi4j-v2 icon indicating copy to clipboard operation
pi4j-v2 copied to clipboard

Unmapping/remapping pins

Open svnhub opened this issue 4 years ago • 2 comments

If I create an IO config for a pin with

config = DigitalInput.newConfigBuilder(rpi4j).provider("pigpio-digital-input").id("pin-"+pinNumber).address(pinNumber)....
pin = rpi4j.create(config);

the name "pinX" is registered in the Registry and the pin works accordingly.

If I then want to disconnect the pin I call pin.shutdown(rpi4j); which seems to forward the disconnect to pigpio but doesn't unregister the IO in the Registry.

Any attempt to then create a new config with the same id creates an exception:

com.pi4j.io.exception.IOAlreadyExistsException: IO instance [pin14] already exists in the Pi4J runtime context; unable to create a new instance using this reserved id.
	at com.pi4j.provider.impl.ProviderProxyHandler.invoke(ProviderProxyHandler.java:99)
	at com.sun.proxy.$Proxy2.create(Unknown Source)
	at com.pi4j.context.Context.create(Context.java:309)
	at com.pi4j.internal.IOCreator.create(IOCreator.java:60)
	at com.pi4j.internal.IOCreator.create(IOCreator.java:101)
	at com.pi4j.internal.IOCreator.create(IOCreator.java:189)
        ...

The registry on the autoContext doesn't seem to have a way to remove things from it (it is a DefaultRegistry not RuntimeRegistry)

svnhub avatar Nov 17 '20 14:11 svnhub

This is a good point. I just ran into it myself.

eitch avatar Jan 19 '21 12:01 eitch

Is there is a possibility to support you to solve the issue?

beulenbilly avatar Jan 30 '22 10:01 beulenbilly

Does this thread alive?

homiodev avatar Nov 17 '22 11:11 homiodev

I see @eitch did a commit https://github.com/Pi4J/pi4j-v2/pull/198/files related to this topic.

FDelporte avatar Nov 17 '22 11:11 FDelporte

I merged a PR, and i think it should be fine now since v2.2.0

eitch avatar Nov 17 '22 13:11 eitch