Skip to content

Commit

Permalink
Avoid error message on PC
Browse files Browse the repository at this point in the history
  • Loading branch information
FDelporte committed Jun 3, 2024
1 parent 41d484e commit 9731454
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 95 deletions.
120 changes: 27 additions & 93 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,99 +93,33 @@ $ sudo ~/.sdkman/candidates/java/19.0.2-zulu/bin/java -jar pi4j-spring-boot-star
```
* Open browser with http://{RASPBERRY_PI_IP_ADDRESS}:8080/actuator/info
* Actual output on a Raspberry Pi 4 (but truncated the pins-section):
```json
{
"os": {
"name": "Linux",
"version": "6.1.21-v8+",
"architecture": "aarch64"
},
"board": {
"label": "Raspberry Pi 4 Model B",
"boardType": {},
"boardCodes": [
"a03111",
"b03111",
"b03112",
"b03114",
"b03115",
"c03111",
"c03112",
"c03114",
"c03115",
"d03114",
"d03115"
],
"model": {
"label": "Model B",
"description": "With ethernet connector"
},
"headerVersion": {
"label": "Type 3",
"description": "Used on Model A+, B+, Pi Zero, Pi Zero W, Pi2B, Pi3B, Pi4B",
"headerPins": [
{
"label": "40pin header",
"pins": [
{
"pinNumber": 1,
"pinType": {
"label": "Power",
"color": 10027008
},
"name": "3.3 VDC",
"remark": ""
},
...
]
}
]
},
"releaseDate": "2019-06-24",
"soc": {
"instructionSet": {
"label": "ARMv8"
}
},
"cpu": {
"label": "Cortex-A72"
},
"numberOfCpu": 4,
"versionsProcessorSpeedInMhz": [
1500,
1800
],
"versionsMemoryInKb": [
1048576,
2097152,
4194304,
8388608
],
"remarks": [],
"name": "MODEL_4_B",
"versionsMemoryInMb": [
1024,
2048,
4096,
8192
],
"versionsMemoryInGb": [
1,
2,
4,
8
]
},
"java": {
"version": "17.0.6",
"runtime": "17.0.6+10-Debian-1deb11u1",
"vendor": "Debian"
},
"pi4jRegistry": {}
}
```
* Output on a PC:
pins-section):
```json
{
"os.name":"Mac OS X",
"os.architecture":"aarch64",
"os.version":"14.5",
"board.name":"UNKNOWN",
"board.description":"Unknown",
"board.model.label":"Unknown",
"board.cpu.label":"Unknown",
"board.soc":"UNKNOWN",
"java.version":"22",
"java.runtime":"22+36",
"java.vendor":"Azul Systems, Inc.",
"java.vendor.version":"Zulu22.28+91-CA",
"reading.volt.value":0.0,
"reading.temperature.celsius":0.0,
"reading.temperature.fahrenheit":32.0,
"reading.uptime":"16:26 up 13 days, 3:35, 1 user, load averages: 2.63 3.45 3.32",
"pi4jRegistry":{}
}
```
* Output on a Raspberry Pi 4 (but truncated the pins-section):
```json
TODO
```
## Notes
Expand Down
4 changes: 4 additions & 0 deletions pi4j-spring-boot/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-gpiod</artifactId>
</dependency>
<dependency>
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-mock</artifactId>
</dependency>

<!-- Spring Boot dependencies -->
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
package com.pi4j.spring.boot;

import com.pi4j.Pi4J;
import com.pi4j.boardinfo.definition.BoardModel;
import com.pi4j.boardinfo.util.BoardInfoHelper;
import com.pi4j.context.Context;
import com.pi4j.plugin.mock.platform.MockPlatform;
import com.pi4j.plugin.mock.provider.gpio.analog.MockAnalogInputProvider;
import com.pi4j.plugin.mock.provider.gpio.analog.MockAnalogOutputProvider;
import com.pi4j.plugin.mock.provider.gpio.digital.MockDigitalInputProvider;
import com.pi4j.plugin.mock.provider.gpio.digital.MockDigitalOutputProvider;
import com.pi4j.plugin.mock.provider.i2c.MockI2CProvider;
import com.pi4j.plugin.mock.provider.pwm.MockPwmProvider;
import com.pi4j.plugin.mock.provider.serial.MockSerialProvider;
import com.pi4j.plugin.mock.provider.spi.MockSpiProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
Expand All @@ -18,7 +29,21 @@ public class ContextConfiguration {

public ContextConfiguration() {
try {
this.pi4j = Pi4J.newAutoContext();
if ( BoardInfoHelper.current().getBoardModel() == BoardModel.UNKNOWN) {
this.pi4j = Pi4J.newContextBuilder()
.add(new MockPlatform())
.add(MockAnalogInputProvider.newInstance(),
MockAnalogOutputProvider.newInstance(),
MockSpiProvider.newInstance(),
MockPwmProvider.newInstance(),
MockSerialProvider.newInstance(),
MockI2CProvider.newInstance(),
MockDigitalInputProvider.newInstance(),
MockDigitalOutputProvider.newInstance())
.build();
} else {
this.pi4j = Pi4J.newAutoContext();
}
} catch (Error e) { // TODO Temporary fix for https://github.com/Pi4J/pi4j-v2/issues/354
logger.error("Pi4J library failed to load: {}", e.getMessage());
}
Expand Down
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
<groupId>com.pi4j</groupId>
<artifactId>pi4j-plugin-mock</artifactId>
<version>${pi4j.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
Expand Down

0 comments on commit 9731454

Please sign in to comment.