From 7d2fd2ce3630548c75b4b5a7eb4b794773728537 Mon Sep 17 00:00:00 2001 From: Frank Delporte Date: Thu, 13 Jun 2024 18:25:00 +0200 Subject: [PATCH] Add current state of led and button to actuator info --- .../spring/boot/sample/app/service/Pi4JService.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pi4j-spring-boot-starter-sample-app/src/main/java/com/pi4j/spring/boot/sample/app/service/Pi4JService.java b/pi4j-spring-boot-starter-sample-app/src/main/java/com/pi4j/spring/boot/sample/app/service/Pi4JService.java index 4853575..f595857 100644 --- a/pi4j-spring-boot-starter-sample-app/src/main/java/com/pi4j/spring/boot/sample/app/service/Pi4JService.java +++ b/pi4j-spring-boot-starter-sample-app/src/main/java/com/pi4j/spring/boot/sample/app/service/Pi4JService.java @@ -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 @@ -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()); }