diff --git a/src/main/java/com/pi4j/boardinfoservice/service/Pi4JInfoService.java b/src/main/java/com/pi4j/boardinfoservice/service/Pi4JInfoService.java index 168f2e1..9ce8510 100644 --- a/src/main/java/com/pi4j/boardinfoservice/service/Pi4JInfoService.java +++ b/src/main/java/com/pi4j/boardinfoservice/service/Pi4JInfoService.java @@ -1,7 +1,9 @@ package com.pi4j.boardinfoservice.service; +import com.pi4j.Pi4J; import com.pi4j.boardinfo.definition.BoardModel; import com.pi4j.boardinfo.definition.HeaderPins; +import com.pi4j.context.Context; import org.springframework.stereotype.Service; import java.util.Arrays; @@ -11,6 +13,16 @@ @Service public class Pi4JInfoService { + private final Context pi4j; + + public Pi4JInfoService() { + this.pi4j = Pi4J.newAutoContext(); + } + + public Context getPi4JContext() { + return pi4j; + } + public List getRaspberryPiBoards() { return Arrays.stream(BoardModel.values()).toList(); } diff --git a/src/main/java/com/pi4j/boardinfoservice/views/SystemInfoView.java b/src/main/java/com/pi4j/boardinfoservice/views/SystemInfoView.java index a6c6004..015485a 100644 --- a/src/main/java/com/pi4j/boardinfoservice/views/SystemInfoView.java +++ b/src/main/java/com/pi4j/boardinfoservice/views/SystemInfoView.java @@ -1,6 +1,8 @@ package com.pi4j.boardinfoservice.views; +import com.pi4j.boardinfoservice.service.Pi4JInfoService; import com.pi4j.boardinfoservice.service.SystemInfoService; +import com.pi4j.common.Descriptor; import com.vaadin.flow.component.AttachEvent; import com.vaadin.flow.component.UI; import com.vaadin.flow.component.grid.ColumnTextAlign; @@ -22,10 +24,13 @@ public class SystemInfoView extends VerticalLayout { private final SystemInfoService systemInfoService; + private final Pi4JInfoService pi4JInfoService; private final List infoList = new ArrayList<>(); - public SystemInfoView(@Autowired SystemInfoService systemInfoService) { + public SystemInfoView(@Autowired SystemInfoService systemInfoService, + @Autowired Pi4JInfoService pi4JInfoService) { this.systemInfoService = systemInfoService; + this.pi4JInfoService = pi4JInfoService; setSpacing(false); @@ -90,9 +95,20 @@ public void onAttach(AttachEvent event) { infoList.add(new InfoLine("Board reading", "Temperature (°F)", reading.getTemperatureInFahrenheit())); infoList.add(new InfoLine("Board reading", "Volt", reading.getVolt())); infoList.add(new InfoLine("Board reading", "Volt (value)", reading.getVoltValue())); + + var pi4j = pi4JInfoService.getPi4JContext(); + infoList.add(new InfoLine("Pi4J Context", "Registry", getDescriptor(pi4j.registry().describe()))); + infoList.add(new InfoLine("Pi4J Context", "Platforms", getDescriptor(pi4j.platforms().describe()))); + infoList.add(new InfoLine("Pi4J Context", "Providers", getDescriptor(pi4j.providers().describe()))); + infoList.add(new InfoLine("Pi4J Context", "Properties", getDescriptor(pi4j.properties().describe()))); + }); } + private String getDescriptor(Descriptor descriptor) { + return descriptor.name() + ", " + descriptor.description(); + } + private record InfoLine(String type, String label, Object info) { } }