BowlerKernel
CounterInputChannel.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.common.ByteList;
20 import com.neuronrobotics.sdk.common.DeviceManager;
21 import com.neuronrobotics.sdk.dyio.DyIO;
22 import com.neuronrobotics.sdk.dyio.DyIOChannel;
23 import com.neuronrobotics.sdk.dyio.DyIOChannelEvent;
24 import com.neuronrobotics.sdk.dyio.DyIOChannelMode;
25 import com.neuronrobotics.sdk.dyio.IChannelEventListener;
26 
27 // TODO: Auto-generated Javadoc
32 
34  private ArrayList<ICounterInputListener> listeners = new ArrayList<ICounterInputListener>();
35 
43  this(((DyIO) DeviceManager.getSpecificDevice(DyIO.class, null)).getChannel(channel));
44  }
45 
53  public CounterInputChannel(DyIO dyio,int channel){
54  this(dyio.getChannel(channel));
55  }
56 
64  this(channel,true);
65  }
66 
73  public CounterInputChannel(DyIOChannel channel,boolean isAsync) {
74  super(channel,DyIOChannelMode.COUNT_IN_INT,isAsync);
75  init(channel,isAsync);
76  }
77 
84  private void init(DyIOChannel channel,boolean isAsync){
87  if(!channel.setMode(mode, isAsync)) {
88  throw new DyIOPeripheralException("Could not set channel " + channel + " to " + mode + " mode.");
89  }
90  channel.resync(true);
91  }
92 
100  if(listeners.contains(l)) {
101  return;
102  }
103 
104  listeners.add(l);
105  }
106 
114  if(!listeners.contains(l)) {
115  return;
116  }
117 
118  listeners.add(l);
119  }
120 
125  listeners.clear();
126  }
127 
133  protected void fireOnCounterInput(int value) {
135  l.onCounterValueChange(this, value);
136  }
137  }
138 
147  }
148 
154  public void setAsync(boolean isAsync) {
156  }
157 
158  /* (non-Javadoc)
159  * @see com.neuronrobotics.sdk.dyio.peripherals.DyIOAbstractPeripheral#setValue(int)
160  */
161 
162  public boolean setValue(int value){
163  ByteList b = new ByteList();
164  b.addAs32(value);
165  return setValue(b);
166  }
167 
168 
169  /* (non-Javadoc)
170  * @see com.neuronrobotics.sdk.dyio.peripherals.DyIOAbstractPeripheral#hasAsync()
171  */
172  public boolean hasAsync() {
173  return true;
174  }
175 }
static Object getSpecificDevice(String name, IDeviceProvider provider)
boolean setMode(DyIOChannelMode mode)
void addChannelEventListener(IChannelEventListener l)
DyIOChannel getChannel(int channel)
Definition: DyIO.java:160