Skip to content

Commit

Permalink
Add current state of led and button to actuator info
Browse files Browse the repository at this point in the history
  • Loading branch information
FDelporte committed Jun 13, 2024
1 parent 5a81ccc commit 7d2fd2c
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.info.Info;
import org.springframework.boot.actuate.info.InfoContributor;
import org.springframework.stereotype.Service;

@Service
public class Pi4JService {
public class Pi4JService implements InfoContributor {

private static final Logger logger = LoggerFactory.getLogger(Pi4JService.class);
private static final int PIN_LED = 22; // PIN 15 = BCM 22
Expand Down Expand Up @@ -51,6 +53,12 @@ public Pi4JService(@Autowired Context pi4j) {
}
}

@Override
public void contribute(Info.Builder builder) {
builder.withDetail("pi4j.status.led", led.state());
builder.withDetail("pi4j.status.button", button.state());
}

private void handleButtonChange(DigitalStateChangeEvent e) {
logger.info("Button state changed to {}", e.state());
}
Expand Down

0 comments on commit 7d2fd2c

Please sign in to comment.