aboutsummaryrefslogtreecommitdiffstats
path: root/Java/com/phidgets/BridgePhidget.java
blob: 2d0e28d0e78410a5379a7de651ecfbbf3fd05d74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/*
 * Copyright 2012 Phidgets Inc.  All rights reserved.
 */

package com.phidgets;
import java.util.Iterator;
import java.util.LinkedList;
import com.phidgets.event.*;
/**
 * This class represents a Phidget Bridge. All methods
 * to manipulate the Phidget Bridge are implemented in this class.
 * See your device's User Guide for more specific API details, 
 * technical information, and revision details. The User Guide, along with other resources, can be found on 
 * the product page for your device.
 * <p>
 * 
 * @author Phidgets Inc.
 */
public final class BridgePhidget extends Phidget
{
	public BridgePhidget () throws PhidgetException
	{
		super (create ());
	}
	private static native long create () throws PhidgetException;
	/**
	 * 1 Gain. This is used with {@link #getGain(int) getGain} and {@link #setGain(int, int) setGain}
	 */
	public static final int PHIDGET_BRIDGE_GAIN_1 = 1;
	/**
	 * 8 Gain. This is used with {@link #getGain(int) getGain} and {@link #setGain(int, int) setGain}
	 */
	public static final int PHIDGET_BRIDGE_GAIN_8 = 2;
	/**
	 * 16 Gain. This is used with {@link #getGain(int) getGain} and {@link #setGain(int, int) setGain}
	 */
	public static final int PHIDGET_BRIDGE_GAIN_16 = 3;
	/**
	 * 32 Gain. This is used with {@link #getGain(int) getGain} and {@link #setGain(int, int) setGain}
	 */
	public static final int PHIDGET_BRIDGE_GAIN_32 = 4;
	/**
	 * 64 Gain. This is used with {@link #getGain(int) getGain} and {@link #setGain(int, int) setGain}
	 */
	public static final int PHIDGET_BRIDGE_GAIN_64 = 5;
	/**
	 * 128 Gain. This is used with {@link #getGain(int) getGain} and {@link #setGain(int, int) setGain}
	 */
	public static final int PHIDGET_BRIDGE_GAIN_128 = 6;
	/**
	 * Unknown Gain. This is used with {@link #getGain(int) getGain} and {@link #setGain(int, int) setGain}
	 */
	public static final int PHIDGET_BRIDGE_GAIN_UNKNOWN = 7;
	/**
	 * Returns the number of bridges.
	 * @return Number of bridges
	 */
	public native int getInputCount () throws PhidgetException;
	/**
	 * Returns the value of the selected input, in mV/V. If the input is not enabled, an EPHIDGET_UNKNOWNVAL exception will be thrown. If the bridge is saturated
	 *, this will be equal to BridgeMax or BridgeMin and an error event will be fired - in this case, gain should be reduced if possible.
	 * @param index Index of the bridge
	 * @return bridge value
	 * @throws PhidgetException If this Phidget is not opened and attached, or if the index is out of range. 
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native double getBridgeValue (int index) throws PhidgetException;
		/**
	 * Returns the minimum value that the selected bridge can measure, in mV/V. This value will depend on the selected gain. At a gain of 1, BridgeMin == -1000 mV/V.
	 * @param index Index of the bridge
	 * @return minimum value 
	 * @throws PhidgetException If this Phidget is not opened and attached, or if the index is out of range. 
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native double getBridgeMin (int index) throws PhidgetException;
	/**
	 * Returns the maximum value that the selected bridge can measure, in mV/V. This value will depend on the selected gain. At a gain of 1, BridgeMin == 1000 mV/V.
	 * @param index Index of the bridge
	 * @return maximum value 
	 * @throws PhidgetException If this Phidget is not opened and attached, or if the index is out of range. 
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native double getBridgeMax (int index) throws PhidgetException;
	/**
	 * Returns the enabled state of the specified bridge. This applies power between +5v and Ground, and starts measuring the differential on the +/- pins. By default, all bridges are 
	 * disabled, and need to be explicitly enabled on startup.
	 * @param index Index of the bridge
	 * @return state of the specified bridge
	 * @throws PhidgetException If this Phidget is not opened and attached, or if the index is invalid. 
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native boolean getEnabled (int index) throws PhidgetException;
	/**
	 * Sets the enabled state of the specified bridge. This applies power between +5v and Ground, and starts measuring the differential on the +/- pins. By default, all bridges are 
	 * disabled, and need to be explicitly enabled on startup.
	 * @param index Index of the bridge
	 * @param state new state of the specified bridge
	 * @throws PhidgetException If this Phidget is not opened and attached, or if the index is invalid. 
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native void setEnabled (int index, boolean state) throws PhidgetException;
	/**
	 * Returns the gain for the selected bridge.  Note that increasing the gains will reduce the measurable
	 * voltage difference by the gain factor, with +-1000 mV/V being the maximum, with no gain.
	 * The possible values for gain are {@link #PHIDGET_BRIDGE_GAIN_1 PHIDGET_BRIDGE_GAIN_1},
	 * {@link #PHIDGET_BRIDGE_GAIN_8 PHIDGET_BRIDGE_GAIN_8}, {@link #PHIDGET_BRIDGE_GAIN_16 PHIDGET_BRIDGE_GAIN_16},
	 * {@link #PHIDGET_BRIDGE_GAIN_32 PHIDGET_BRIDGE_GAIN_32}, {@link #PHIDGET_BRIDGE_GAIN_64 PHIDGET_BRIDGE_GAIN_64},
	 * {@link #PHIDGET_BRIDGE_GAIN_128 PHIDGET_BRIDGE_GAIN_128}, {@link #PHIDGET_BRIDGE_GAIN_UNKNOWN PHIDGET_BRIDGE_GAIN_UNKNOWN}
	 * <p>
	 * @param index Index of the bridge
	 * @return gain
	 * @throws PhidgetException If this Phidget is not opened and attached, or if the index is invalid. 
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native int getGain (int index) throws PhidgetException;
	/**
	 * Sets the gain for the selected bridge.  Note that increasing the gains will reduce the measurable
	 * voltage difference by the gain factor, with +-1000 mV/V being the maximum, with no gain.
	 * <p>
	 * The possible values for gain are {@link #PHIDGET_BRIDGE_GAIN_1 PHIDGET_BRIDGE_GAIN_1},
	 * {@link #PHIDGET_BRIDGE_GAIN_8 PHIDGET_BRIDGE_GAIN_8}, {@link #PHIDGET_BRIDGE_GAIN_16 PHIDGET_BRIDGE_GAIN_16},
	 * {@link #PHIDGET_BRIDGE_GAIN_32 PHIDGET_BRIDGE_GAIN_32}, {@link #PHIDGET_BRIDGE_GAIN_64 PHIDGET_BRIDGE_GAIN_64},
	 * {@link #PHIDGET_BRIDGE_GAIN_128 PHIDGET_BRIDGE_GAIN_128}, {@link #PHIDGET_BRIDGE_GAIN_UNKNOWN PHIDGET_BRIDGE_GAIN_UNKNOWN}
	 * <p>
	 * @param index Index of the bridge
	 * @param gain new gain
	 * @throws PhidgetException If this Phidget is not opened and attached, or if the index is invalid. 
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native void setGain (int index, int gain) throws PhidgetException;
	/**
	 * Returns the data rate, in ms. Data rate applies to all 4 bridges simultaneously. Setting a slower data rate will reduce
	 * noise at the cost of sample time. Also note that each bridge is being sampled only 1/4 of the time - this is okay for very stable signals,
	 * but for changing signals, it is best to set a higher sampling rate and do averaging in the software. 
	 * <p>
	 * Data rate must be a multiple of 8ms. Trying to set something between multiplies of 8 will cause an EPHIDGET_INVALIDARG exception.
	 * <p>
	 * @return Data Rate
	 * @throws PhidgetException If this Phidget is not opened and attached, or if the index is invalid. 
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native int getDataRate () throws PhidgetException;
	/**
	 * Sets the data rate, in ms. Data rate applies to all 4 bridges simultaneously. Setting a slower data rate will reduce
	 * noise at the cost of sample time. Also note that each bridge is being sampled only 1/4 of the time - this is okay for very stable signals,
	 * but for changing signals, it is best to set a higher sampling rate and do averaging in the software.
	 * <p>
	 * Data rate must be a multiple of 8ms. Trying to set something between multiplies of 8 will cause an EPHIDGET_INVALIDARG exception.
	 * <p>
	 * @param rate new data rate
	 * @throws PhidgetException If this Phidget is not opened and attached, or if the data rate is out of range 
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native void setDataRate (int rate) throws PhidgetException;
	/**
	 * Gets the minimum supported data rate, in ms.
	 * @return minimum supported data rate
	 * @throws PhidgetException If this Phidget is not opened and attached.
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native int getDataRateMin () throws PhidgetException;
	/**
	 * Gets the maximum supported data rate, in ms.
	 * @return maximum supported data rate
	 * @throws PhidgetException If this Phidget is not opened and attached.
	 * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
	 */
	public native int getDataRateMax () throws PhidgetException;

	private final void enableDeviceSpecificEvents (boolean b)
	{
		enableBridgeDataEvents (b && bridgeDataListeners.size () > 0);
	}
	/**
	 * Adds a bridge data listener. The bridge data handler is a method that will be called at the specified data rate, for each enabled bridge. Value is the bridgeValue, in mV/V.
	 * <p>
	 * There is no limit on the number of bridge data handlers that can be registered for a particular Phidget.
	 * 
	 * @param l An implemetation of the {@link com.phidgets.event.BridgeDataListener BridgeDataListener} interface
	 */
	public final void addBridgeDataListener (BridgeDataListener l)
	{
		synchronized (bridgeDataListeners)
		{
			bridgeDataListeners.add (l);
			enableBridgeDataEvents (true);
	}} private LinkedList bridgeDataListeners = new LinkedList ();
	private long nativeBridgeDataHandler = 0;
	public final void removeBridgeDataListener (BridgeDataListener l)
	{
		synchronized (bridgeDataListeners)
		{
			bridgeDataListeners.remove (l);
			enableBridgeDataEvents (bridgeDataListeners.size () > 0);
	}} private void fireBridgeData (BridgeDataEvent e)
	{
		synchronized (bridgeDataListeners)
		{
			for (Iterator it = bridgeDataListeners.iterator (); it.hasNext ();)
				((BridgeDataListener) it.next ()).bridgeData (e);
		}
	}
	private native void enableBridgeDataEvents (boolean b);
}