From 340974cd31697978cbc61a977637606dc944b498 Mon Sep 17 00:00:00 2001 From: FuseTim Date: Sun, 14 Apr 2024 17:58:27 +0200 Subject: [PATCH] fix(io): IOBase constructor do not update the fields id, name & description The classes extending IOBase were already updating those fields (except SerialBase). SerialBase was the only class missing this change. These changes allow the user to use multiple Serial interface at the same time. It was impossible before, as Pi4J would throws IOAlreadyExistsException. This commit "moves" the fixes for the similar issues in the SPI interface. Ref: #244, #257 Closes: #257 --- pi4j-core/src/main/java/com/pi4j/io/IOBase.java | 3 +++ pi4j-core/src/main/java/com/pi4j/io/gpio/GpioBase.java | 3 --- pi4j-core/src/main/java/com/pi4j/io/i2c/I2CBase.java | 3 --- pi4j-core/src/main/java/com/pi4j/io/pwm/PwmBase.java | 3 --- pi4j-core/src/main/java/com/pi4j/io/spi/SpiBase.java | 3 --- 5 files changed, 3 insertions(+), 12 deletions(-) diff --git a/pi4j-core/src/main/java/com/pi4j/io/IOBase.java b/pi4j-core/src/main/java/com/pi4j/io/IOBase.java index b8e1181e..462b80d4 100644 --- a/pi4j-core/src/main/java/com/pi4j/io/IOBase.java +++ b/pi4j-core/src/main/java/com/pi4j/io/IOBase.java @@ -60,6 +60,9 @@ public PROVIDER_TYPE provider(){ */ public IOBase(PROVIDER_TYPE provider, CONFIG_TYPE config){ super(); + this.id = config.id; + this.name = config.name; + this.description = config.description; this.provider = provider; this.config = config; } diff --git a/pi4j-core/src/main/java/com/pi4j/io/gpio/GpioBase.java b/pi4j-core/src/main/java/com/pi4j/io/gpio/GpioBase.java index b86bbaa5..d48349b1 100644 --- a/pi4j-core/src/main/java/com/pi4j/io/gpio/GpioBase.java +++ b/pi4j-core/src/main/java/com/pi4j/io/gpio/GpioBase.java @@ -47,9 +47,6 @@ public abstract class GpioBase implem */ public I2CBase(I2CProvider provider, I2CConfig config) { super(provider, config); - this.name = config.name(); - this.id = config.id(); - this.description = config.description(); this.isOpen = true; } diff --git a/pi4j-core/src/main/java/com/pi4j/io/pwm/PwmBase.java b/pi4j-core/src/main/java/com/pi4j/io/pwm/PwmBase.java index 4a91c148..ffd01e38 100644 --- a/pi4j-core/src/main/java/com/pi4j/io/pwm/PwmBase.java +++ b/pi4j-core/src/main/java/com/pi4j/io/pwm/PwmBase.java @@ -57,9 +57,6 @@ public abstract class PwmBase extends IOBase implem */ public PwmBase(PwmProvider provider, PwmConfig config) { super(provider, config); - this.name = config.name(); - this.id = config.id(); - this.description = config.description(); for(PwmPreset preset : config.presets()){ this.presets.put(preset.name().toLowerCase().trim(), preset); } diff --git a/pi4j-core/src/main/java/com/pi4j/io/spi/SpiBase.java b/pi4j-core/src/main/java/com/pi4j/io/spi/SpiBase.java index 751bc801..80f807ee 100644 --- a/pi4j-core/src/main/java/com/pi4j/io/spi/SpiBase.java +++ b/pi4j-core/src/main/java/com/pi4j/io/spi/SpiBase.java @@ -48,9 +48,6 @@ public abstract class SpiBase extends IOBase implem */ public SpiBase(SpiProvider provider, SpiConfig config) { super(provider, config); - this.name = config.name(); - this.id = config.id(); - this.description = config.description(); } /** {@inheritDoc} */