diff --git a/README.md b/README.md index 9556f83..0f12e4a 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/pi4j-spring-boot/pom.xml b/pi4j-spring-boot/pom.xml index 3e7d236..a14d716 100644 --- a/pi4j-spring-boot/pom.xml +++ b/pi4j-spring-boot/pom.xml @@ -35,6 +35,10 @@ com.pi4j pi4j-plugin-gpiod + + com.pi4j + pi4j-plugin-mock + diff --git a/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/ContextConfiguration.java b/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/ContextConfiguration.java index e28a161..e26b383 100644 --- a/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/ContextConfiguration.java +++ b/pi4j-spring-boot/src/main/java/com/pi4j/spring/boot/ContextConfiguration.java @@ -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; @@ -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()); } diff --git a/pom.xml b/pom.xml index a68f740..3c1ace8 100644 --- a/pom.xml +++ b/pom.xml @@ -75,7 +75,6 @@ com.pi4j pi4j-plugin-mock ${pi4j.version} - test