001package jmri.jmrix.pi.simulator; 002 003import com.pi4j.io.gpio.*; 004import com.pi4j.io.gpio.event.GpioPinListener; 005import com.pi4j.io.gpio.trigger.GpioTrigger; 006 007import java.util.*; 008/** 009 * Simulates GpioPinDigitalInput. 010 * 011 * @author Daniel Bergqvist Copyright (C) 2022 012 */ 013public class GpioPinDigitalInputSimulator implements GpioPinDigitalInput { 014 015// private final Pin pin; 016 private String name; 017// private final PinPullResistance ppr; 018 private PinState pinState = PinState.LOW; 019 private PinMode pinMode = PinMode.DIGITAL_INPUT; 020 private PinPullResistance pinPullResistance = PinPullResistance.OFF; 021 022 private final List<GpioPinListener> listeners = new ArrayList<>(); 023 024 public GpioPinDigitalInputSimulator(Pin pin, String string, PinPullResistance ppr) { 025// this.pin = pin; 026 this.name = string; 027// this.ppr = ppr; 028 } 029 030 @Override 031 public boolean hasDebounce(PinState ps) { 032 throw new UnsupportedOperationException("Not supported"); 033 } 034 035 @Override 036 public int getDebounce(PinState ps) { 037 throw new UnsupportedOperationException("Not supported"); 038 } 039 040 @Override 041 public void setDebounce(int i) { 042 throw new UnsupportedOperationException("Not supported"); 043 } 044 045 @Override 046 public void setDebounce(int i, PinState... pss) { 047 throw new UnsupportedOperationException("Not supported"); 048 } 049 050 @Override 051 public boolean isHigh() { 052 return pinState.isHigh(); 053 } 054 055 @Override 056 public boolean isLow() { 057 return pinState.isLow(); 058 } 059 060 @Override 061 public PinState getState() { 062 return pinState; 063 } 064 065 @Override 066 public boolean isState(PinState ps) { 067 return pinState == ps; 068 } 069 070 @Override 071 public GpioProvider getProvider() { 072 throw new UnsupportedOperationException("Not supported"); 073 } 074 075 @Override 076 public Pin getPin() { 077 throw new UnsupportedOperationException("Not supported"); 078 } 079 080 @Override 081 public void setName(String string) { 082 name = string; 083 } 084 085 @Override 086 public String getName() { 087 return name; 088 } 089 090 @Override 091 public void setTag(Object o) { 092 throw new UnsupportedOperationException("Not supported"); 093 } 094 095 @Override 096 public Object getTag() { 097 throw new UnsupportedOperationException("Not supported"); 098 } 099 100 @Override 101 public void setProperty(String string, String string1) { 102 throw new UnsupportedOperationException("Not supported"); 103 } 104 105 @Override 106 public boolean hasProperty(String string) { 107 throw new UnsupportedOperationException("Not supported"); 108 } 109 110 @Override 111 public String getProperty(String string) { 112 throw new UnsupportedOperationException("Not supported"); 113 } 114 115 @Override 116 public String getProperty(String string, String string1) { 117 throw new UnsupportedOperationException("Not supported"); 118 } 119 120 @Override 121 public Map<String, String> getProperties() { 122 throw new UnsupportedOperationException("Not supported"); 123 } 124 125 @Override 126 public void removeProperty(String string) { 127 throw new UnsupportedOperationException("Not supported"); 128 } 129 130 @Override 131 public void clearProperties() { 132 throw new UnsupportedOperationException("Not supported"); 133 } 134 135 @Override 136 public void export(PinMode pm) { 137 throw new UnsupportedOperationException("Not supported"); 138 } 139 140 @Override 141 public void export(PinMode pm, PinState ps) { 142 throw new UnsupportedOperationException("Not supported"); 143 } 144 145 @Override 146 public void unexport() { 147 throw new UnsupportedOperationException("Not supported"); 148 } 149 150 @Override 151 public boolean isExported() { 152 throw new UnsupportedOperationException("Not supported"); 153 } 154 155 @Override 156 public void setMode(PinMode pm) { 157 this.pinMode = pm; 158 // We should probably call all the listeners here???? 159 throw new UnsupportedOperationException("Not supported"); 160 } 161 162 @Override 163 public PinMode getMode() { 164 return pinMode; 165 } 166 167 @Override 168 public boolean isMode(PinMode pm) { 169 return pinMode == pm; 170 } 171 172 @Override 173 public void setPullResistance(PinPullResistance ppr) { 174 pinPullResistance = ppr; 175 } 176 177 @Override 178 public PinPullResistance getPullResistance() { 179 return pinPullResistance; 180 } 181 182 @Override 183 public boolean isPullResistance(PinPullResistance ppr) { 184 return pinPullResistance == ppr; 185 } 186 187 @Override 188 public Collection<GpioPinListener> getListeners() { 189 throw new UnsupportedOperationException("Not supported"); 190 } 191 192 @Override 193 public void addListener(GpioPinListener... gls) { 194 for (GpioPinListener gl : gls) { 195 listeners.add(gl); 196 } 197 } 198 199 @Override 200 public void addListener(List<? extends GpioPinListener> list) { 201 listeners.addAll(list); 202 } 203 204 @Override 205 public boolean hasListener(GpioPinListener... gls) { 206 throw new UnsupportedOperationException("Not supported"); 207 } 208 209 @Override 210 public void removeListener(GpioPinListener... gls) { 211 for (GpioPinListener gl : gls) { 212 listeners.remove(gl); 213 } 214 } 215 216 @Override 217 public void removeListener(List<? extends GpioPinListener> list) { 218 listeners.removeAll(list); 219 } 220 221 @Override 222 public void removeAllListeners() { 223 listeners.clear(); 224 } 225 226 @Override 227 public GpioPinShutdown getShutdownOptions() { 228 throw new UnsupportedOperationException("Not supported"); 229 } 230 231 @Override 232 public void setShutdownOptions(GpioPinShutdown gps) { 233// throw new UnsupportedOperationException("Not supported"); 234 } 235 236 @Override 237 public void setShutdownOptions(Boolean bln) { 238// throw new UnsupportedOperationException("Not supported"); 239 } 240 241 @Override 242 public void setShutdownOptions(Boolean bln, PinState ps) { 243// throw new UnsupportedOperationException("Not supported"); 244 } 245 246 @Override 247 public void setShutdownOptions(Boolean bln, PinState ps, PinPullResistance ppr) { 248// throw new UnsupportedOperationException("Not supported"); 249 } 250 251 @Override 252 public void setShutdownOptions(Boolean bln, PinState ps, PinPullResistance ppr, PinMode pm) { 253// throw new UnsupportedOperationException("Not supported"); 254 } 255 256 @Override 257 public Collection<GpioTrigger> getTriggers() { 258 throw new UnsupportedOperationException("Not supported"); 259 } 260 261 @Override 262 public void addTrigger(GpioTrigger... gts) { 263 throw new UnsupportedOperationException("Not supported"); 264 } 265 266 @Override 267 public void addTrigger(List<? extends GpioTrigger> list) { 268 throw new UnsupportedOperationException("Not supported"); 269 } 270 271 @Override 272 public void removeTrigger(GpioTrigger... gts) { 273 throw new UnsupportedOperationException("Not supported"); 274 } 275 276 @Override 277 public void removeTrigger(List<? extends GpioTrigger> list) { 278 throw new UnsupportedOperationException("Not supported"); 279 } 280 281 @Override 282 public void removeAllTriggers() { 283 throw new UnsupportedOperationException("Not supported"); 284 } 285 286}