Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 3 additions & 23 deletions pi4j-core/src/main/java/com/pi4j/io/gpio/digital/DigitalBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ protected DigitalBase(CONFIG_TYPE config, Consumer<?> onClose) {
(listener, event) -> listener.onDigitalStateChange(event));
}

@Override
public Consumer<Boolean> addConsumer(Consumer<Boolean> listener) {
DigitalState on = onState();
addListener(new ConsumerAdapter(listener, on != null ? on : DigitalState.HIGH));
return listener;
}

@Override
public void removeConsumer(Consumer<Boolean> listener) {
stateChangeEventManager.remove(
Expand Down Expand Up @@ -91,24 +84,11 @@ public void close() {
super.close();
}

@Override
public boolean isOn() {
DigitalState on = onState();
return state().equals(on != null ? on : DigitalState.HIGH);
}

/**
* Returns the configured on-state for this digital I/O instance.
*
* @return the configured {@link DigitalState}
*/
public abstract DigitalState onState();

private static class ConsumerAdapter implements DigitalStateChangeListener {
private final Consumer<Boolean> consumer;
protected static class ConsumerAdapter implements DigitalStateChangeListener {
final Consumer<Boolean> consumer;
private final DigitalState onState;

private ConsumerAdapter(Consumer<Boolean> consumer, DigitalState onState) {
protected ConsumerAdapter(Consumer<Boolean> consumer, DigitalState onState) {
this.consumer = consumer;
this.onState = onState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ protected DigitalInputBase(DigitalInputConfig config, Consumer<?> onClose){
}

@Override
public DigitalState onState() {
return config().onState();
public Consumer<Boolean> addConsumer(Consumer<Boolean> listener) {
DigitalState on = config().onState();
addListener(new ConsumerAdapter(listener, on != null ? on : DigitalState.HIGH));
return listener;
}

@Override
public boolean isOn() {
DigitalState on = config().onState();
return state().equals(on != null ? on : DigitalState.HIGH);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,16 @@ protected DigitalOutputBase(DigitalOutputConfig config, Consumer<?> onClose) {
}

@Override
public DigitalState onState() {
return config().onState();
public Consumer<Boolean> addConsumer(Consumer<Boolean> listener) {
DigitalState on = config().onState();
addListener(new ConsumerAdapter(listener, on != null ? on : DigitalState.HIGH));
return listener;
}

@Override
public boolean isOn() {
DigitalState on = config().onState();
return state().equals(on != null ? on : DigitalState.HIGH);
}

/**
Expand Down
Loading