Skip to content

Commit

Permalink
Bump to Pi4J with integrated BoardInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Delporte committed Apr 25, 2024
1 parent 8c506b2 commit c46d4b7
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 22 deletions.
8 changes: 4 additions & 4 deletions pi4j-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
<groupId>com.pi4j</groupId>
<artifactId>pi4j-core</artifactId>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-board-info</artifactId>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-raspberrypi</artifactId>
Expand All @@ -35,6 +31,10 @@
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-linuxfs</artifactId>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-gpiod</artifactId>
</dependency>

<!-- Spring Boot dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public ContextConditions() {
super(ConfigurationPhase.REGISTER_BEAN);
}

/**
* TODO are these still needed? Can't we use Pi4jActuatorConfiguration.boardInfo ?
*/
@ConditionalOnProperty(prefix = "os", name = "arch", havingValue = "armv6l")
static class Armv6l {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@
@ConditionalOnClass(Context.class)
public class ContextConfiguration {

private final Context pi4j;

public ContextConfiguration() {
this.pi4j = Pi4J.newAutoContext();
}

@Bean
@Conditional(ContextConditions.class)
@ConditionalOnMissingBean
Context context() {
return Pi4J.newAutoContext();
return pi4j;
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.pi4j.spring.boot;

import com.pi4j.boardinfo.model.DetectedBoard;
import com.pi4j.boardinfo.util.BoardModelDetection;
import com.pi4j.boardinfo.model.BoardInfo;
import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.context.Context;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -17,7 +17,7 @@
public class Pi4jActuatorConfiguration implements InfoContributor {

private final Context context;
private final DetectedBoard detectedBoard;
private final BoardInfo boardInfo;
private final Logger logger = LoggerFactory.getLogger(Pi4jActuatorConfiguration.class);

/**
Expand All @@ -27,14 +27,33 @@ public class Pi4jActuatorConfiguration implements InfoContributor {
*/
public Pi4jActuatorConfiguration(Context context) {
this.context = context;
this.detectedBoard = BoardModelDetection.getDetectedBoard();
this.boardInfo = BoardInfoHelper.current();
}

@Override
public void contribute(Builder builder) {
builder.withDetail("os", detectedBoard.getOperatingSystem());
builder.withDetail("board", detectedBoard.getBoardModel());
builder.withDetail("java", detectedBoard.getJavaInfo());
var os = boardInfo.getOperatingSystem();
builder.withDetail("os.name", os.getName());
builder.withDetail("os.architecture", os.getArchitecture());
builder.withDetail("os.version", os.getVersion());
builder.withDetail("os.architecture", os.getArchitecture());
var boardModel = boardInfo.getBoardModel();
builder.withDetail("board.name", boardModel.getName());
builder.withDetail("board.description", boardModel.getLabel());
builder.withDetail("board.model.label", boardModel.getModel().getLabel());
builder.withDetail("board.cpu.label", boardModel.getCpu().getLabel());
builder.withDetail("board.soc", boardModel.getSoc().name());
var java = boardInfo.getJavaInfo();
builder.withDetail("java.version", java.getVersion());
builder.withDetail("java.runtime", java.getRuntime());
builder.withDetail("java.vendor", java.getVendor());
builder.withDetail("java.vendor.version", java.getVendorVersion());
var boardReading = BoardInfoHelper.getBoardReading();
builder.withDetail("reading.volt.value", boardReading.getVoltValue());
builder.withDetail("reading.temperature.celsius", boardReading.getTemperatureInCelsius());
builder.withDetail("reading.temperature.fahrenheit", boardReading.getTemperatureInFahrenheit());
builder.withDetail("reading.uptime", boardReading.getUptimeInfo());

try {
// TODO https://github.com/Pi4J/pi4j-springboot/issues/11
//builder.withDetail("pi4jPlatforms", context.platforms().all());
Expand Down
31 changes: 21 additions & 10 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.0</version>
<version>3.2.5</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

Expand All @@ -19,9 +19,8 @@

<properties>
<java.version>17</java.version>
<spring-boot.version>3.1.0</spring-boot.version>
<pi4j.version>2.3.0</pi4j.version>
<pi4j.boardinfo.version>0.2.0</pi4j.boardinfo.version>
<spring-boot.version>3.2.5</spring-boot.version>
<pi4j.version>2.6.0-SNAPSHOT</pi4j.version>

<!-- Plugins -->
<jacoco-maven-plugin.version>0.8.10</jacoco-maven-plugin.version>
Expand All @@ -40,6 +39,20 @@
<module>pi4j-spring-boot-starter-sample-app</module>
</modules>

<repositories>
<repository>
<id>oss-snapshots-repo</id>
<name>Sonatype OSS Maven Repository</name>
<url>https://oss.sonatype.org/content/groups/public</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>

</dependencies>
Expand Down Expand Up @@ -69,16 +82,14 @@
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-mock</artifactId>
<artifactId>pi4j-plugin-gpiod</artifactId>
<version>${pi4j.version}</version>
<scope>test</scope>
</dependency>

<!-- Pi4J Board Info library -->
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-board-info</artifactId>
<version>${pi4j.boardinfo.version}</version>
<artifactId>pi4j-plugin-mock</artifactId>
<version>${pi4j.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down

0 comments on commit c46d4b7

Please sign in to comment.