BowlerKernel
DigitalInputChannel.java
Go to the documentation of this file.
1 /*******************************************************************************
2  * Copyright 2010 Neuron Robotics, LLC
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  ******************************************************************************/
15 package com.neuronrobotics.sdk.dyio.peripherals;
16 
17 import java.util.ArrayList;
18 
19 import com.neuronrobotics.sdk.dyio.DyIO;
20 import com.neuronrobotics.sdk.dyio.DyIOChannel;
21 import com.neuronrobotics.sdk.dyio.DyIOChannelEvent;
22 import com.neuronrobotics.sdk.dyio.DyIOChannelMode;
23 import com.neuronrobotics.sdk.common.DeviceManager;
24 import com.neuronrobotics.sdk.dyio.IChannelEventListener;
25 
26 // TODO: Auto-generated Javadoc
31 
33  private ArrayList<IDigitalInputListener> listeners = new ArrayList<IDigitalInputListener>();
34 
43  public DigitalInputChannel(DyIOChannel channel, boolean async){
44  super(channel,DyIOChannelMode.DIGITAL_IN,async);
46  if(!setMode( async)) {
47  throw new DyIOPeripheralException("Could not set channel " + getChannel() + " to " + DyIOChannelMode.DIGITAL_IN + " mode.");
48  }
49  }
50 
58  this(((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(channel));
59  }
60 
68  public DigitalInputChannel(DyIO dyio,int channel){
69  this(dyio.getChannel(channel));
70  }
71 
79  this(channel,true);
80  }
81 
87  public boolean isHigh() {
88  return getValue() != 0;
89  }
90 
96  public void setAsync(boolean isAsync) {
98  }
99 
104  listeners.clear();
105  }
106 
114  if(!listeners.contains(l)) {
115  return;
116  }
117 
118  listeners.remove(l);
119  }
120 
128  if(listeners.contains(l)) {
129  return;
130  }
131 
132  listeners.add(l);
133  }
134 
140  private void fireValueChanged(boolean value) {
142  l.onDigitalValueChange(this, value);
143  }
144  }
145 
146  /* (non-Javadoc)
147  * @see com.neuronrobotics.sdk.dyio.IChannelEventListener#onChannelEvent(com.neuronrobotics.sdk.dyio.DyIOChannelEvent)
148  */
149 
152  }
153 
154 
155  /* (non-Javadoc)
156  * @see com.neuronrobotics.sdk.dyio.peripherals.DyIOAbstractPeripheral#hasAsync()
157  */
158  public boolean hasAsync() {
159  return true;
160  }
161 }
static Object getSpecificDevice(String name, IDeviceProvider provider)
void addChannelEventListener(IChannelEventListener l)
DyIOChannel getChannel(int channel)
Definition: DyIO.java:160