Pi4J / pi4j-v1

DEPRECATED Java I/O library for Raspberry Pi (GPIO, I2C, SPI, UART)
http://www.pi4j.com
Apache License 2.0
1.31k stars 448 forks source link

The implemented blink method in GpioPinDigitalOutput shows wrong state after blinking #534

Closed bilderkiste closed 3 years ago

bilderkiste commented 3 years ago

I did not find any documentation about this method, but I guess that the third argument of the method blink defines the pin state after blinking.

I wrote this line

pin27.blink(delay, duration, PinState.LOW);

But the LED keeps on. It should goes out after blinking.

pin27.blink(delay, duration, PinState.HIGH);

the LED goes out, that means pin state is low. I think it should be the other way, shouldn't it.

savageautomate commented 3 years ago

Which Pi4J version are you using?
I don't think blink() has been implemented in Pi4J version 2 yet.

https://github.com/Pi4J/pi4j-v2/blob/f866d6ac1a562969b4a3689ab7d3c57c09707e64/pi4j-core/src/main/java/com/pi4j/io/gpio/digital/DigitalOutputBase.java#L130-L142

bilderkiste commented 3 years ago

Hi. I am using version 1.2. And I think it is implemented

https://github.com/Pi4J/pi4j/blob/master/pi4j-core/src/main/java/com/pi4j/io/gpio/impl/GpioPinImpl.java and https://github.com/Pi4J/pi4j/blob/master/pi4j-core/src/main/java/com/pi4j/io/gpio/impl/GpioScheduledExecutorImpl.java

Have a nice evening!

savageautomate commented 3 years ago

Moved this issue to Pi4J v1.x repository.

@bilderkiste

Yes it is implemented in all versions of Pi4J v1.x.


It looks like the blinkState argument is intended to set the START state for the blink operation to begin with.
See: https://github.com/Pi4J/pi4j/blob/5f7bc33d6bbc76e77da44408e915c36b316765ec/pi4j-core/src/main/java/com/pi4j/io/gpio/impl/GpioScheduledExecutorImpl.java#L157-L162

And it looks like it purposefully sets the inverse of the state argument provided when the blink stops after a given duration interval period.

https://github.com/Pi4J/pi4j/blob/5f7bc33d6bbc76e77da44408e915c36b316765ec/pi4j-core/src/main/java/com/pi4j/io/gpio/impl/GpioScheduledExecutorImpl.java#L176-L178

If the blink operation is manually stopped, I don't think there is any behavior to enforce the final state.