Skip to content

Commit

Permalink
Merge pull request #1 from MEBoo/issue/Pi4J#26
Browse files Browse the repository at this point in the history
Issue/Pi4J#26
  • Loading branch information
MEBoo authored Jul 1, 2022
2 parents 76c6147 + 7d11038 commit ea0846c
Show file tree
Hide file tree
Showing 37 changed files with 3,009 additions and 12 deletions.
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 @@ -29,6 +29,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 @@ -107,6 +108,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 @@ -151,6 +163,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 @@ -58,6 +58,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) {
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) {
throw new IllegalArgumentException("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 @@ -44,6 +44,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 @@ -55,4 +55,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

0 comments on commit ea0846c

Please sign in to comment.