001package jmri.jmrix.pi.simulator;
002
003import com.pi4j.io.gpio.*;
004import com.pi4j.io.gpio.event.GpioPinListener;
005
006import java.util.concurrent.*;
007
008import java.util.*;
009/**
010 * Simulates GpioPinDigitalOutput.
011 *
012 * @author Daniel Bergqvist Copyright (C) 2022
013 * @author Bob Jacobsen Copyright (C) 2023
014 */
015public class GpioPinDigitalOutputSimulator implements GpioPinDigitalOutput {
016
017//    private final Pin pin;
018    private String name;
019//    private final PinPullResistance ppr;
020    private PinState pinState = PinState.LOW;
021    private PinMode pinMode = PinMode.DIGITAL_INPUT;
022    private PinPullResistance pinPullResistance = PinPullResistance.OFF;
023
024    private final List<GpioPinListener> listeners = new ArrayList<>();
025
026    public GpioPinDigitalOutputSimulator(Pin pin, String string) {
027//        this.pin = pin;
028        this.name = string;
029//        this.ppr = ppr;
030    }
031
032    @Override
033    public boolean isHigh() {
034        return pinState.isHigh();
035    }
036
037    @Override
038    public boolean isLow() {
039        return pinState.isLow();
040    }
041
042    @Override
043    public PinState getState() {
044        return pinState;
045    }
046
047    @Override
048    public void setState(boolean state) {
049        pinState = PinState.getState(state);
050    }
051
052    @Override
053    public void high() {
054        pinState = PinState.getState(true);
055    }
056
057    @Override
058    public void low() {
059        pinState = PinState.getState(false);
060    }
061
062    @Override
063    public void setState(PinState state) {
064        pinState = state;
065    }
066
067    @Override
068    public void toggle() {
069        pinState = PinState.getState(!isHigh());
070    }
071    
072    @Override
073    public boolean isState(PinState ps) {
074        return pinState == ps;
075    }
076
077    @Override
078    public Future<?> blink(long delay, long duration) {
079        throw new UnsupportedOperationException("Not supported");
080    }
081
082    @Override
083    public Future<?> blink(long delay, long duration, PinState pulseState) {
084        throw new UnsupportedOperationException("Not supported");
085    }
086
087    @Override
088    public Future<?> blink(long delay, long duration, PinState pulseState, TimeUnit unit) {
089        throw new UnsupportedOperationException("Not supported");
090    }
091
092    @Override
093    public Future<?> blink(long delay, long duration, TimeUnit unit) {
094        throw new UnsupportedOperationException("Not supported");
095    }
096
097    @Override
098    public Future<?> blink(long duration, PinState pulseState) {
099        throw new UnsupportedOperationException("Not supported");
100    }
101
102    @Override
103    public Future<?> blink(long duration) {
104        throw new UnsupportedOperationException("Not supported");
105    }
106
107    @Override
108    public Future<?> blink(long duration, PinState pulseState, TimeUnit unit) {
109        throw new UnsupportedOperationException("Not supported");
110    }
111
112    @Override
113    public Future<?> blink(long duration, TimeUnit unit) {
114        throw new UnsupportedOperationException("Not supported");
115    }
116
117    @Override
118    public Future<?> pulse(long duration) {
119        throw new UnsupportedOperationException("Not supported");
120    }
121
122    @Override
123    public Future<?> pulse(long duration, boolean blocking) {
124        throw new UnsupportedOperationException("Not supported");
125    }
126
127    @Override
128    public Future<?> pulse(long duration, boolean blocking, 
129                            Callable<Void> callback) {
130        throw new UnsupportedOperationException("Not supported");
131    }
132
133    @Override
134    public Future<?> pulse(long duration, Callable<Void> callback) {
135        throw new UnsupportedOperationException("Not supported");
136    }
137
138    @Override
139    public Future<?> pulse(long duration, PinState pulseState) {
140        throw new UnsupportedOperationException("Not supported");
141    }
142
143    @Override
144    public Future<?> pulse(long duration, PinState pulseState, boolean blocking) {
145        throw new UnsupportedOperationException("Not supported");
146    }
147
148    @Override
149    public Future<?> pulse(long duration, PinState pulseState, boolean blocking, 
150                            Callable<Void> callback) {
151        throw new UnsupportedOperationException("Not supported");
152    }
153
154    @Override
155    public Future<?> pulse(long duration, PinState pulseState, 
156                            Callable<Void> callback) {
157        throw new UnsupportedOperationException("Not supported");
158    }
159
160    @Override
161    public Future<?> pulse(long duration, PinState pulseState, boolean blocking, 
162                            TimeUnit unit) {
163        throw new UnsupportedOperationException("Not supported");
164    }
165
166    @Override
167    public Future<?> pulse(long duration, PinState pulseState,
168                            Callable<Void> callback, TimeUnit unit) {
169        throw new UnsupportedOperationException("Not supported");
170    }
171
172    @Override
173    public Future<?> pulse(long duration, PinState pulseState, TimeUnit unit) {
174        throw new UnsupportedOperationException("Not supported");
175    }
176
177    @Override
178    public Future<?> pulse(long duration, boolean blocking, 
179                            Callable<Void> callback, TimeUnit unit) {
180        throw new UnsupportedOperationException("Not supported");
181    }
182
183    @Override
184    public Future<?> pulse(long duration, boolean blocking, 
185                            TimeUnit unit) {
186        throw new UnsupportedOperationException("Not supported");
187    }
188
189    @Override
190    public Future<?> pulse(long duration,
191                            Callable<Void> callback, TimeUnit unit) {
192        throw new UnsupportedOperationException("Not supported");
193    }
194
195    @Override
196    public Future<?> pulse(long duration, PinState pulseState, boolean blocking, 
197                            Callable<Void> callback, TimeUnit unit) {
198        throw new UnsupportedOperationException("Not supported");
199    }
200
201    @Override
202    public Future<?> pulse(long duration, TimeUnit unit) {
203        throw new UnsupportedOperationException("Not supported");
204    }
205
206    @Override
207    public GpioProvider getProvider() {
208        throw new UnsupportedOperationException("Not supported");
209    }
210
211    @Override
212    public Pin getPin() {
213        throw new UnsupportedOperationException("Not supported");
214    }
215
216    @Override
217    public void setName(String string) {
218        name = string;
219    }
220
221    @Override
222    public String getName() {
223        return name;
224    }
225
226    @Override
227    public void setTag(Object o) {
228        throw new UnsupportedOperationException("Not supported");
229    }
230
231    @Override
232    public Object getTag() {
233        throw new UnsupportedOperationException("Not supported");
234    }
235
236    @Override
237    public void setProperty(String string, String string1) {
238        throw new UnsupportedOperationException("Not supported");
239    }
240
241    @Override
242    public boolean hasProperty(String string) {
243        throw new UnsupportedOperationException("Not supported");
244    }
245
246    @Override
247    public String getProperty(String string) {
248        throw new UnsupportedOperationException("Not supported");
249    }
250
251    @Override
252    public String getProperty(String string, String string1) {
253        throw new UnsupportedOperationException("Not supported");
254    }
255
256    @Override
257    public Map<String, String> getProperties() {
258        throw new UnsupportedOperationException("Not supported");
259    }
260
261    @Override
262    public void removeProperty(String string) {
263        throw new UnsupportedOperationException("Not supported");
264    }
265
266    @Override
267    public void clearProperties() {
268        throw new UnsupportedOperationException("Not supported");
269    }
270
271    @Override
272    public void export(PinMode pm) {
273        throw new UnsupportedOperationException("Not supported");
274    }
275
276    @Override
277    public void export(PinMode pm, PinState ps) {
278        throw new UnsupportedOperationException("Not supported");
279    }
280
281    @Override
282    public void unexport() {
283        throw new UnsupportedOperationException("Not supported");
284    }
285
286    @Override
287    public boolean isExported() {
288        throw new UnsupportedOperationException("Not supported");
289    }
290
291    @Override
292    public void setMode(PinMode pm) {
293        this.pinMode = pm;
294        // We should probably call all the listeners here????
295        throw new UnsupportedOperationException("Not supported");
296    }
297
298    @Override
299    public PinMode getMode() {
300        return pinMode;
301    }
302
303    @Override
304    public boolean isMode(PinMode pm) {
305        return pinMode == pm;
306    }
307
308    @Override
309    public void setPullResistance(PinPullResistance ppr) {
310        pinPullResistance = ppr;
311    }
312
313    @Override
314    public PinPullResistance getPullResistance() {
315        return pinPullResistance;
316    }
317
318    @Override
319    public boolean isPullResistance(PinPullResistance ppr) {
320        return pinPullResistance == ppr;
321    }
322
323    @Override
324    public Collection<GpioPinListener> getListeners() {
325        throw new UnsupportedOperationException("Not supported");
326    }
327
328    @Override
329    public void addListener(GpioPinListener... gls) {
330        for (GpioPinListener gl : gls) {
331            listeners.add(gl);
332        }
333    }
334
335    @Override
336    public void addListener(List<? extends GpioPinListener> list) {
337        listeners.addAll(list);
338    }
339
340    @Override
341    public boolean hasListener(GpioPinListener... gls) {
342        throw new UnsupportedOperationException("Not supported");
343    }
344
345    @Override
346    public void removeListener(GpioPinListener... gls) {
347        for (GpioPinListener gl : gls) {
348            listeners.remove(gl);
349        }
350    }
351
352    @Override
353    public void removeListener(List<? extends GpioPinListener> list) {
354        listeners.removeAll(list);
355    }
356
357    @Override
358    public void removeAllListeners() {
359        listeners.clear();
360    }
361
362    @Override
363    public GpioPinShutdown getShutdownOptions() {
364        throw new UnsupportedOperationException("Not supported");
365    }
366
367    @Override
368    public void setShutdownOptions(GpioPinShutdown gps) {
369//        throw new UnsupportedOperationException("Not supported");
370    }
371
372    @Override
373    public void setShutdownOptions(Boolean bln) {
374//        throw new UnsupportedOperationException("Not supported");
375    }
376
377    @Override
378    public void setShutdownOptions(Boolean bln, PinState ps) {
379//        throw new UnsupportedOperationException("Not supported");
380    }
381
382    @Override
383    public void setShutdownOptions(Boolean bln, PinState ps, PinPullResistance ppr) {
384//        throw new UnsupportedOperationException("Not supported");
385    }
386
387    @Override
388    public void setShutdownOptions(Boolean bln, PinState ps, PinPullResistance ppr, PinMode pm) {
389//        throw new UnsupportedOperationException("Not supported");
390    }
391
392}