Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/#26 Support for GPIO Digital Multipurpose pins (INPUT & OUTPUT) #30

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions pi4j-core/src/main/java/com/pi4j/internal/ProviderAliases.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.pi4j.io.gpio.analog.AnalogInputProvider;
import com.pi4j.io.gpio.analog.AnalogOutputProvider;
import com.pi4j.io.gpio.digital.DigitalInputProvider;
import com.pi4j.io.gpio.digital.DigitalMultipurposeProvider;
import com.pi4j.io.gpio.digital.DigitalOutputProvider;
import com.pi4j.io.i2c.I2CProvider;
import com.pi4j.io.pwm.PwmProvider;
Expand Down Expand Up @@ -109,6 +110,17 @@ default <T extends DigitalOutputProvider> T dout() throws ProviderException{
return digitalOutput();
}

/**
* <p>dmulti.</p>
*
* @param <T> a T object.
* @return a T object.
* @throws ProviderException if any.
*/
default <T extends DigitalMultipurposeProvider> T dmulti() throws ProviderException{
return digitalMultipurpose();
}

/**
* <p>analogInput.</p>
*
Expand Down Expand Up @@ -153,6 +165,17 @@ default <T extends DigitalOutputProvider> T digitalOutput() throws ProviderExcep
return this.provider(IOType.DIGITAL_OUTPUT);
}

/**
* <p>digitalMultipurpose.</p>
*
* @param <T> a T object.
* @return a T object.
* @throws ProviderException if any.
*/
default <T extends DigitalMultipurposeProvider> T digitalMultipurpose() throws ProviderException{
return this.provider(IOType.DIGITAL_MULTIPURPOSE);
}

/**
* <p>pwm.</p>
*
Expand Down
19 changes: 10 additions & 9 deletions pi4j-core/src/main/java/com/pi4j/io/IOType.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public enum IOType {
ANALOG_OUTPUT(AnalogOutputProvider.class, AnalogOutput.class, AnalogOutputConfig.class, AnalogOutputConfigBuilder.class),
DIGITAL_INPUT(DigitalInputProvider.class, DigitalInput.class, DigitalInputConfig.class, DigitalInputConfigBuilder.class),
DIGITAL_OUTPUT(DigitalOutputProvider.class, DigitalOutput.class, DigitalOutputConfig.class, DigitalOutputConfigBuilder.class),
DIGITAL_MULTIPURPOSE(DigitalMultipurposeProvider.class, DigitalMultipurpose.class, DigitalMultipurposeConfig.class, DigitalMultipurposeConfigBuilder.class),
PWM(PwmProvider.class, Pwm.class, PwmConfig.class, PwmConfigBuilder.class),
I2C(I2CProvider.class, com.pi4j.io.i2c.I2C.class, I2CConfig.class, I2CConfigBuilder.class),
SPI(SpiProvider.class, Spi.class, I2CConfig.class, I2CConfigBuilder.class),
Expand Down Expand Up @@ -302,6 +303,15 @@ public static IOType parse(String ioType) throws IOException {
if(ioType.startsWith("digital o")) return DIGITAL_OUTPUT;
if(ioType.equalsIgnoreCase("dout")) return DIGITAL_OUTPUT;

// DIGITAL MULTIPURPOSE
if(ioType.startsWith("digital.m")) return DIGITAL_MULTIPURPOSE;
if(ioType.startsWith("digital-m")) return DIGITAL_MULTIPURPOSE;
if(ioType.startsWith("digital_m")) return DIGITAL_MULTIPURPOSE;
if(ioType.startsWith("digital m")) return DIGITAL_MULTIPURPOSE;
if(ioType.equalsIgnoreCase("dmulti")) return DIGITAL_MULTIPURPOSE;
if(ioType.equalsIgnoreCase("dmultipurpose")) return DIGITAL_MULTIPURPOSE;
if(ioType.equalsIgnoreCase("dmulti-purpose")) return DIGITAL_MULTIPURPOSE;

// PWM
if(ioType.equalsIgnoreCase("pwm")) return PWM;
if(ioType.equalsIgnoreCase("p.w.m")) return PWM;
Expand Down Expand Up @@ -340,12 +350,3 @@ public static IOType parse(String ioType) throws IOException {
throw new IOException("Unknown IO TYPE: " + ioType);
}
}

// ANALOG_INPUT(AnalogInputProvider.class, AnalogInput.class, AnalogInputConfig.class, AnalogInputConfigBuilder.class),
// ANALOG_OUTPUT(AnalogOutputProvider.class, AnalogOutput.class, AnalogOutputConfig.class, AnalogOutputConfigBuilder.class),
// DIGITAL_INPUT(DigitalInputProvider.class, DigitalInput.class, DigitalInputConfig.class, DigitalInputConfigBuilder.class),
// DIGITAL_OUTPUT(DigitalOutputProvider.class, DigitalOutput.class, DigitalOutputConfig.class, DigitalOutputConfigBuilder.class),
// PWM(PwmProvider.class, Pwm.class, PwmConfig.class, PwmConfigBuilder.class),
// I2C(I2CProvider.class, com.pi4j.io.i2c.I2C.class, I2CConfig.class, I2CConfigBuilder.class),
// SPI(SpiProvider.class, Spi.class, I2CConfig.class, I2CConfigBuilder.class),
// SERIAL(SerialProvider.class, Serial.class, SerialConfig.class, SerialConfigBuilder.class);
39 changes: 39 additions & 0 deletions pi4j-core/src/main/java/com/pi4j/io/InputOutput.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.pi4j.io;

/*-
* #%L
* **********************************************************************
* ORGANIZATION : Pi4J
* PROJECT : Pi4J :: LIBRARY :: Java Library (CORE)
* FILENAME : InputOutput.java
*
* This file is part of the Pi4J project. More information about
* this project can be found here: https://pi4j.com/
* **********************************************************************
* %%
* Copyright (C) 2012 - 2020 Pi4J
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/


/**
* <p>Input interface.</p>
*
* @author Robert Savage (<a href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
* @version $Id: $Id
*/
public interface InputOutput extends Input, Output {
// MARKER INTERFACE
}
61 changes: 61 additions & 0 deletions pi4j-core/src/main/java/com/pi4j/io/exception/IOModeException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.pi4j.io.exception;

/*
* #%L
* **********************************************************************
* ORGANIZATION : Pi4J
* PROJECT : Pi4J :: LIBRARY :: Java Library (CORE)
* FILENAME : IOModeException.java
*
* This file is part of the Pi4J project. More information about
* this project can be found here: https://pi4j.com/
* **********************************************************************
* %%
* Copyright (C) 2012 - 2020 Pi4J
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/


/**
* <p>
* This exception is thrown if a platform assignment is attempted when a
* platform instance has already been assigned.
* </p>
*
* @see <a href="http://www.pi4j.com/">http://www.pi4j.com/</a>
* @author Robert Savage (<a
* href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
* @version $Id: $Id
*/
public class IOModeException extends IOException {

/**
* Default Constructor
*
* @param message a {@link String} object.
*/
public IOModeException(String message){
super(message);
}

/**
* Alternate Constructor
*
* @param error a int.
*/
public IOModeException(int error){
super("I/O MODE ERROR: " + error);
}
}
6 changes: 6 additions & 0 deletions pi4j-core/src/main/java/com/pi4j/io/gpio/digital/Digital.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public interface Digital<DIGITAL_TYPE extends Digital<DIGITAL_TYPE, CONFIG_TYPE,
Bindable<DIGITAL_TYPE, DigitalBinding>
{

/**
* Get digital mode (input|output)
* @return digital mode (input|output)
*/
DigitalMode mode();

/**
* <p>state.</p>
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,10 @@ static DigitalInputConfigBuilder newConfigBuilder(Context context){
* @return a {@link com.pi4j.io.gpio.digital.PullResistance} object.
*/
default PullResistance pull() { return config().pull(); }

/**
* Get digital mode (input|output)
* @return INPUT
*/
default DigitalMode mode() { return DigitalMode.INPUT; }
}
Loading