Skip to content

Commit

Permalink
Add Pi4J info
Browse files Browse the repository at this point in the history
  • Loading branch information
FDelporte committed May 27, 2024
1 parent 91e2bcf commit bdc8b04
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<BoardModel> getRaspberryPiBoards() {
return Arrays.stream(BoardModel.values()).toList();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -22,10 +24,13 @@
public class SystemInfoView extends VerticalLayout {

private final SystemInfoService systemInfoService;
private final Pi4JInfoService pi4JInfoService;
private final List<InfoLine> infoList = new ArrayList<>();

public SystemInfoView(@Autowired SystemInfoService systemInfoService) {
public SystemInfoView(@Autowired SystemInfoService systemInfoService,
@Autowired Pi4JInfoService pi4JInfoService) {
this.systemInfoService = systemInfoService;
this.pi4JInfoService = pi4JInfoService;

setSpacing(false);

Expand Down Expand Up @@ -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) {
}
}

0 comments on commit bdc8b04

Please sign in to comment.