001package com.pi4j.io.gpio;
002
003/*
004 * #%L
005 * **********************************************************************
006 * ORGANIZATION  :  Pi4J
007 * PROJECT       :  Pi4J :: Java Library (Core)
008 * FILENAME      :  GpioController.java
009 *
010 * This file is part of the Pi4J project. More information about
011 * this project can be found here:  http://www.pi4j.com/
012 * **********************************************************************
013 * %%
014 * Copyright (C) 2012 - 2016 Pi4J
015 * %%
016 * This program is free software: you can redistribute it and/or modify
017 * it under the terms of the GNU Lesser General Public License as
018 * published by the Free Software Foundation, either version 3 of the
019 * License, or (at your option) any later version.
020 *
021 * This program is distributed in the hope that it will be useful,
022 * but WITHOUT ANY WARRANTY; without even the implied warranty of
023 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
024 * GNU General Lesser Public License for more details.
025 *
026 * You should have received a copy of the GNU General Lesser Public
027 * License along with this program.  If not, see
028 * <http://www.gnu.org/licenses/lgpl-3.0.html>.
029 * #L%
030 */
031
032import com.pi4j.io.gpio.event.GpioPinListener;
033import com.pi4j.io.gpio.trigger.GpioTrigger;
034
035import java.util.Collection;
036
037/**
038 * Gpio controller interface. This interface describes all operations over GPIO.
039 *
040 * @author Robert Savage (<a
041 *         href="http://www.savagehomeautomation.com">http://www.savagehomeautomation.com</a>)
042 */
043@SuppressWarnings("unused")
044public interface GpioController {
045
046    void export(PinMode mode, PinState defaultState, GpioPin... pin);
047    void export(PinMode mode, GpioPin... pin);
048    boolean isExported(GpioPin... pin);
049
050    /**
051     * Unexport a GPIO pin by Pin instance.
052     * This method will explicitly unexport any Pin whether it has been
053     * provisioned in Pi4J or not.
054     *
055     * @param pin GPIO pin instance (i.e. RaspiPin.GPIO_00)
056     */
057    void unexport(Pin... pin);
058
059    /**
060     * Unexport a GPIO pin by GpioPin instance.
061     * This method will unexport an existing provisoned pin
062     *
063     * @param pin provisioned GPIO pin instance
064     */
065    void unexport(GpioPin... pin);
066
067    /**
068     * Unexport all GPIO pins that have been provisioned by Pi4J
069     * in the context of this program.
070     */
071    void unexportAll();
072
073    void setMode(PinMode mode, GpioPin... pin);
074    PinMode getMode(GpioPin pin);
075    boolean isMode(PinMode mode, GpioPin... pin);
076
077    void setPullResistance(PinPullResistance resistance, GpioPin... pin);
078    PinPullResistance getPullResistance(GpioPin pin);
079    boolean isPullResistance(PinPullResistance resistance, GpioPin... pin);
080
081    void high(GpioPinDigitalOutput... pin);
082    boolean isHigh(GpioPinDigital... pin);
083
084    void low(GpioPinDigitalOutput... pin);
085    boolean isLow(GpioPinDigital... pin);
086
087    void setState(PinState state, GpioPinDigitalOutput... pin);
088    void setState(boolean state, GpioPinDigitalOutput... pin);
089    boolean isState(PinState state, GpioPinDigital... pin);
090    PinState getState(GpioPinDigital pin);
091
092    void toggle(GpioPinDigitalOutput... pin);
093    void pulse(long milliseconds, GpioPinDigitalOutput... pin);
094
095    void setValue(double value, GpioPinAnalogOutput... pin);
096    double getValue(GpioPinAnalog pin);
097
098    void addListener(GpioPinListener listener, GpioPinInput... pin);
099    void addListener(GpioPinListener[] listeners, GpioPinInput... pin);
100    void removeListener(GpioPinListener listener, GpioPinInput... pin);
101    void removeListener(GpioPinListener[] listeners, GpioPinInput... pin);
102    void removeAllListeners();
103
104    void addTrigger(GpioTrigger trigger, GpioPinInput... pin);
105    void addTrigger(GpioTrigger[] triggers, GpioPinInput... pin);
106    void removeTrigger(GpioTrigger trigger, GpioPinInput... pin);
107    void removeTrigger(GpioTrigger[] triggers, GpioPinInput... pin);
108    void removeAllTriggers();
109
110    GpioPinDigitalMultipurpose provisionDigitalMultipurposePin(GpioProvider provider, Pin pin, String name, PinMode mode, PinPullResistance resistance);
111    GpioPinDigitalMultipurpose provisionDigitalMultipurposePin(GpioProvider provider, Pin pin, PinMode mode, PinPullResistance resistance);
112    GpioPinDigitalMultipurpose provisionDigitalMultipurposePin(GpioProvider provider, Pin pin, String name, PinMode mode);
113    GpioPinDigitalMultipurpose provisionDigitalMultipurposePin(GpioProvider provider, Pin pin, PinMode mode);
114    GpioPinDigitalMultipurpose provisionDigitalMultipurposePin(Pin pin, String name, PinMode mode, PinPullResistance resistance);
115    GpioPinDigitalMultipurpose provisionDigitalMultipurposePin(Pin pin, PinMode mode, PinPullResistance resistance);
116    GpioPinDigitalMultipurpose provisionDigitalMultipurposePin(Pin pin, String name, PinMode mode);
117    GpioPinDigitalMultipurpose provisionDigitalMultipurposePin(Pin pin, PinMode mode);
118
119    GpioPinDigitalInput provisionDigitalInputPin(GpioProvider provider, Pin pin, String name, PinPullResistance resistance);
120    GpioPinDigitalInput provisionDigitalInputPin(GpioProvider provider, Pin pin, PinPullResistance resistance);
121    GpioPinDigitalInput provisionDigitalInputPin(GpioProvider provider, Pin pin, String name);
122    GpioPinDigitalInput provisionDigitalInputPin(GpioProvider provider, Pin pin);
123    GpioPinDigitalInput provisionDigitalInputPin(Pin pin, String name, PinPullResistance resistance);
124    GpioPinDigitalInput provisionDigitalInputPin(Pin pin, PinPullResistance resistance);
125    GpioPinDigitalInput provisionDigitalInputPin(Pin pin, String name);
126    GpioPinDigitalInput provisionDigitalInputPin(Pin pin);
127
128    GpioPinDigitalOutput provisionDigitalOutputPin(GpioProvider provider, Pin pin, String name, PinState defaultState);
129    GpioPinDigitalOutput provisionDigitalOutputPin(GpioProvider provider, Pin pin, PinState defaultState);
130    GpioPinDigitalOutput provisionDigitalOutputPin(GpioProvider provider, Pin pin, String name);
131    GpioPinDigitalOutput provisionDigitalOutputPin(GpioProvider provider, Pin pin);
132    GpioPinDigitalOutput provisionDigitalOutputPin(Pin pin, String name, PinState defaultState);
133    GpioPinDigitalOutput provisionDigitalOutputPin(Pin pin, PinState defaultState);
134    GpioPinDigitalOutput provisionDigitalOutputPin(Pin pin, String name);
135    GpioPinDigitalOutput provisionDigitalOutputPin(Pin pin);
136
137    GpioPinAnalogInput provisionAnalogInputPin(GpioProvider provider, Pin pin, String name);
138    GpioPinAnalogInput provisionAnalogInputPin(GpioProvider provider, Pin pin);
139    GpioPinAnalogInput provisionAnalogInputPin(Pin pin, String name);
140    GpioPinAnalogInput provisionAnalogInputPin(Pin pin);
141
142    GpioPinAnalogOutput provisionAnalogOutputPin(GpioProvider provider, Pin pin, String name, double defaultValue);
143    GpioPinAnalogOutput provisionAnalogOutputPin(GpioProvider provider, Pin pin, double defaultValue);
144    GpioPinAnalogOutput provisionAnalogOutputPin(GpioProvider provider, Pin pin, String name);
145    GpioPinAnalogOutput provisionAnalogOutputPin(GpioProvider provider, Pin pin);
146    GpioPinAnalogOutput provisionAnalogOutputPin(Pin pin, String name, double defaultValue);
147    GpioPinAnalogOutput provisionAnalogOutputPin(Pin pin, double defaultValue);
148    GpioPinAnalogOutput provisionAnalogOutputPin(Pin pin, String name);
149    GpioPinAnalogOutput provisionAnalogOutputPin(Pin pin);
150
151    GpioPinPwmOutput provisionPwmOutputPin(GpioProvider provider, Pin pin, String name, int defaultValue);
152    GpioPinPwmOutput provisionPwmOutputPin(GpioProvider provider, Pin pin, int defaultValue);
153    GpioPinPwmOutput provisionPwmOutputPin(GpioProvider provider, Pin pin, String name);
154    GpioPinPwmOutput provisionPwmOutputPin(GpioProvider provider, Pin pin);
155    GpioPinPwmOutput provisionPwmOutputPin(Pin pin, String name, int defaultValue);
156    GpioPinPwmOutput provisionPwmOutputPin(Pin pin, int defaultValue);
157    GpioPinPwmOutput provisionPwmOutputPin(Pin pin, String name);
158    GpioPinPwmOutput provisionPwmOutputPin(Pin pin);
159
160    GpioPinPwmOutput provisionSoftPwmOutputPin(GpioProvider provider, Pin pin, String name, int defaultValue);
161    GpioPinPwmOutput provisionSoftPwmOutputPin(GpioProvider provider, Pin pin, int defaultValue);
162    GpioPinPwmOutput provisionSoftPwmOutputPin(GpioProvider provider, Pin pin, String name);
163    GpioPinPwmOutput provisionSoftPwmOutputPin(GpioProvider provider, Pin pin);
164    GpioPinPwmOutput provisionSoftPwmOutputPin(Pin pin, String name, int defaultValue);
165    GpioPinPwmOutput provisionSoftPwmOutputPin(Pin pin, int defaultValue);
166    GpioPinPwmOutput provisionSoftPwmOutputPin(Pin pin, String name);
167    GpioPinPwmOutput provisionSoftPwmOutputPin(Pin pin);
168
169    GpioPin provisionPin(GpioProvider provider, Pin pin, String name, PinMode mode, PinState defaultState);
170    GpioPin provisionPin(GpioProvider provider, Pin pin, String name, PinMode mode);
171    GpioPin provisionPin(GpioProvider provider, Pin pin, PinMode mode);
172    GpioPin provisionPin(Pin pin, String name, PinMode mode);
173    GpioPin provisionPin(Pin pin, PinMode mode);
174
175    void setShutdownOptions(GpioPinShutdown options, GpioPin... pin);
176    void setShutdownOptions(Boolean unexport, GpioPin... pin);
177    void setShutdownOptions(Boolean unexport, PinState state, GpioPin... pin);
178    void setShutdownOptions(Boolean unexport, PinState state, PinPullResistance resistance, GpioPin... pin);
179    void setShutdownOptions(Boolean unexport, PinState state, PinPullResistance resistance, PinMode mode, GpioPin... pin);
180
181    Collection<GpioPin> getProvisionedPins();
182    GpioPin getProvisionedPin(Pin pin);
183    GpioPin getProvisionedPin(String name);
184
185    void unprovisionPin(GpioPin... pin);
186    boolean isShutdown();
187    void shutdown();
188}