aboutsummaryrefslogtreecommitdiffstats
path: root/Java/com/phidgets
diff options
context:
space:
mode:
Diffstat (limited to 'Java/com/phidgets')
-rw-r--r--Java/com/phidgets/AccelerometerPhidget.java116
-rw-r--r--Java/com/phidgets/AdvancedServoPhidget.java492
-rw-r--r--Java/com/phidgets/AnalogPhidget.java78
-rw-r--r--Java/com/phidgets/BridgePhidget.java202
-rw-r--r--Java/com/phidgets/Dictionary.java348
-rw-r--r--Java/com/phidgets/DictionaryKeyListener.java184
-rw-r--r--Java/com/phidgets/EncoderPhidget.java173
-rw-r--r--Java/com/phidgets/FrequencyCounterPhidget.java171
-rw-r--r--Java/com/phidgets/GPSPhidget.java151
-rw-r--r--Java/com/phidgets/IRCode.java93
-rw-r--r--Java/com/phidgets/IRCodeInfo.java360
-rw-r--r--Java/com/phidgets/IRLearnedCode.java51
-rw-r--r--Java/com/phidgets/IRPhidget.java239
-rw-r--r--Java/com/phidgets/InterfaceKitPhidget.java346
-rw-r--r--Java/com/phidgets/LEDPhidget.java141
-rw-r--r--Java/com/phidgets/Manager.java408
-rw-r--r--Java/com/phidgets/MotorControlPhidget.java497
-rw-r--r--Java/com/phidgets/PHSensorPhidget.java136
-rw-r--r--Java/com/phidgets/Phidget.java1000
-rw-r--r--Java/com/phidgets/PhidgetException.java337
-rw-r--r--Java/com/phidgets/RFIDPhidget.java197
-rw-r--r--Java/com/phidgets/ServoPhidget.java286
-rw-r--r--Java/com/phidgets/SpatialEventData.java101
-rw-r--r--Java/com/phidgets/SpatialPhidget.java205
-rw-r--r--Java/com/phidgets/StepperPhidget.java422
-rw-r--r--Java/com/phidgets/TemperatureSensorPhidget.java213
-rw-r--r--Java/com/phidgets/TextLCDPhidget.java278
-rw-r--r--Java/com/phidgets/TextLEDPhidget.java68
-rw-r--r--Java/com/phidgets/WeightSensorPhidget.java89
-rw-r--r--Java/com/phidgets/event/AccelerationChangeEvent.java69
-rw-r--r--Java/com/phidgets/event/AccelerationChangeListener.java20
-rw-r--r--Java/com/phidgets/event/AttachEvent.java46
-rw-r--r--Java/com/phidgets/event/AttachListener.java20
-rw-r--r--Java/com/phidgets/event/BackEMFUpdateEvent.java70
-rw-r--r--Java/com/phidgets/event/BackEMFUpdateListener.java21
-rw-r--r--Java/com/phidgets/event/BridgeDataEvent.java69
-rw-r--r--Java/com/phidgets/event/BridgeDataListener.java20
-rw-r--r--Java/com/phidgets/event/CodeEvent.java73
-rw-r--r--Java/com/phidgets/event/CodeListener.java21
-rw-r--r--Java/com/phidgets/event/CurrentChangeEvent.java69
-rw-r--r--Java/com/phidgets/event/CurrentChangeListener.java21
-rw-r--r--Java/com/phidgets/event/CurrentUpdateEvent.java70
-rw-r--r--Java/com/phidgets/event/CurrentUpdateListener.java20
-rw-r--r--Java/com/phidgets/event/DetachEvent.java46
-rw-r--r--Java/com/phidgets/event/DetachListener.java20
-rw-r--r--Java/com/phidgets/event/EncoderPositionChangeEvent.java84
-rw-r--r--Java/com/phidgets/event/EncoderPositionChangeListener.java20
-rw-r--r--Java/com/phidgets/event/EncoderPositionUpdateEvent.java73
-rw-r--r--Java/com/phidgets/event/EncoderPositionUpdateListener.java20
-rw-r--r--Java/com/phidgets/event/ErrorEvent.java59
-rw-r--r--Java/com/phidgets/event/ErrorListener.java21
-rw-r--r--Java/com/phidgets/event/FrequencyCounterCountEvent.java81
-rw-r--r--Java/com/phidgets/event/FrequencyCounterCountListener.java20
-rw-r--r--Java/com/phidgets/event/GPSPositionChangeEvent.java80
-rw-r--r--Java/com/phidgets/event/GPSPositionChangeListener.java20
-rw-r--r--Java/com/phidgets/event/GPSPositionFixStatusChangeEvent.java58
-rw-r--r--Java/com/phidgets/event/GPSPositionFixStatusChangeListener.java20
-rw-r--r--Java/com/phidgets/event/InputChangeEvent.java69
-rw-r--r--Java/com/phidgets/event/InputChangeListener.java21
-rw-r--r--Java/com/phidgets/event/KeyChangeEvent.java63
-rw-r--r--Java/com/phidgets/event/KeyChangeListener.java21
-rw-r--r--Java/com/phidgets/event/KeyRemovalEvent.java61
-rw-r--r--Java/com/phidgets/event/KeyRemovalListener.java21
-rw-r--r--Java/com/phidgets/event/LearnEvent.java60
-rw-r--r--Java/com/phidgets/event/LearnListener.java21
-rw-r--r--Java/com/phidgets/event/MotorVelocityChangeEvent.java69
-rw-r--r--Java/com/phidgets/event/MotorVelocityChangeListener.java20
-rw-r--r--Java/com/phidgets/event/OutputChangeEvent.java69
-rw-r--r--Java/com/phidgets/event/OutputChangeListener.java21
-rw-r--r--Java/com/phidgets/event/PHChangeEvent.java58
-rw-r--r--Java/com/phidgets/event/PHChangeListener.java20
-rw-r--r--Java/com/phidgets/event/RawDataEvent.java70
-rw-r--r--Java/com/phidgets/event/RawDataListener.java21
-rw-r--r--Java/com/phidgets/event/SensorChangeEvent.java69
-rw-r--r--Java/com/phidgets/event/SensorChangeListener.java19
-rw-r--r--Java/com/phidgets/event/SensorUpdateEvent.java70
-rw-r--r--Java/com/phidgets/event/SensorUpdateListener.java19
-rw-r--r--Java/com/phidgets/event/ServerConnectEvent.java48
-rw-r--r--Java/com/phidgets/event/ServerConnectListener.java20
-rw-r--r--Java/com/phidgets/event/ServerDisconnectEvent.java48
-rw-r--r--Java/com/phidgets/event/ServerDisconnectListener.java20
-rw-r--r--Java/com/phidgets/event/ServoPositionChangeEvent.java70
-rw-r--r--Java/com/phidgets/event/ServoPositionChangeListener.java21
-rw-r--r--Java/com/phidgets/event/ServoVelocityChangeEvent.java69
-rw-r--r--Java/com/phidgets/event/ServoVelocityChangeListener.java20
-rw-r--r--Java/com/phidgets/event/SpatialDataEvent.java60
-rw-r--r--Java/com/phidgets/event/SpatialDataListener.java21
-rw-r--r--Java/com/phidgets/event/StepperPositionChangeEvent.java70
-rw-r--r--Java/com/phidgets/event/StepperPositionChangeListener.java21
-rw-r--r--Java/com/phidgets/event/StepperVelocityChangeEvent.java69
-rw-r--r--Java/com/phidgets/event/StepperVelocityChangeListener.java20
-rw-r--r--Java/com/phidgets/event/TagGainEvent.java59
-rw-r--r--Java/com/phidgets/event/TagGainListener.java21
-rw-r--r--Java/com/phidgets/event/TagLossEvent.java59
-rw-r--r--Java/com/phidgets/event/TagLossListener.java21
-rw-r--r--Java/com/phidgets/event/TemperatureChangeEvent.java70
-rw-r--r--Java/com/phidgets/event/TemperatureChangeListener.java20
-rw-r--r--Java/com/phidgets/event/WeightChangeEvent.java58
-rw-r--r--Java/com/phidgets/event/WeightChangeListener.java20
-rw-r--r--Java/com/phidgets/macros/BridgePhidget.jm171
100 files changed, 10551 insertions, 0 deletions
diff --git a/Java/com/phidgets/AccelerometerPhidget.java b/Java/com/phidgets/AccelerometerPhidget.java
new file mode 100644
index 0000000..c0c82ae
--- /dev/null
+++ b/Java/com/phidgets/AccelerometerPhidget.java
@@ -0,0 +1,116 @@
+
+/*
+ * Copyright 2006 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 Accelerometer. All methods to read
+ * acceleration data from an Accelerometer are implemented in this class.
+ <p>
+ The Phidget Accelerometer provides 2 or 3 axes of acceleration data, at anywhere from 2g to 10g
+ sensitivity, depending on the specific revision. See your hardware documetation for more information.
+ They can measure both static (gravity) and dynamic acceleration.
+
+ * @author Phidgets Inc.
+ */
+public final class AccelerometerPhidget extends Phidget
+{
+ public AccelerometerPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+
+ /**
+ * Returns the number of accelerometer axes. Currently all accelerometers provide two or three axes of acceleration - x, y, (and z).
+ * @return number of axes of acceleration
+ */
+ public native int getAxisCount () throws PhidgetException;
+ /**
+ * Returns the acceleration of a particular axis. This value is returned in g's, where one g of acceleration is
+ * equal to gravity. This means that at a standstill each axis will measure between -1.0 and 1.0 g's depending on
+ * orientation.
+ * <P>
+ * This value will always be between {@link #getAccelerationMin getAccelerationMin} and {@link #getAccelerationMax getAccelerationMax}.
+ * <p>
+ * Index 0 is the x-axis, 1 is the y-axis, and 2 is the z-axis (where available).
+ *
+ * @param index index of the axis
+ * @return acceleration of the selected axis
+ * @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 getAcceleration (int index) throws PhidgetException;
+ /**
+ * Returns the maximum acceleration value that this axis will report. This will be set to just higher then the maximum
+ * acceleration that this axis can measure. If the acceleration is equal to this maximum, assume that that axis is saturated
+ * beyond what it can measure.
+ * @return maximum acceleration
+ */
+ public native double getAccelerationMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum acceleration value that this axis will report. This will be set to just lower then the minimum
+ * acceleration that this axis can measure. If the acceleration is equal to this minimum, assume that that axis is saturated
+ * beyond what it can measure.
+ * @return minimum acceleration
+ */
+ public native double getAccelerationMin (int index) throws PhidgetException;
+ /**
+ * Sets the change trigger for an Axis. This value is in g's and is by default set to 0.
+ * This is the difference in acceleration that must appear between succesive calls to the
+ * OnAccelerationChange event handler.
+ * @param index index of the axis
+ * @param newVal the new change trigger for this axis
+ * @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 void setAccelerationChangeTrigger (int index, double newVal) throws PhidgetException;
+ /**
+ * Returns the change trigger for an Axis. This value is in g's and is by default set to 0.
+ * @param index index of the axis
+ * @return change trigger of the selected axis
+ * @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 getAccelerationChangeTrigger (int index) throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableAccelerationChangeEvents (b && accelerationChangeListeners.size () > 0);
+ }
+ /**
+ * Adds an acceleration change listener. The acceleration change handler is a method that will be called when the acceleration
+ * of an axis has changed by at least the {@link #getAccelerationChangeTrigger(int) Trigger} that has been set for that axis.
+ * <p>
+ * There is no limit on the number of acceleration change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.AccelerationChangeListener AccelerationChangeListener} interface
+ */
+ public final void addAccelerationChangeListener (AccelerationChangeListener l)
+ {
+ synchronized (accelerationChangeListeners)
+ {
+ accelerationChangeListeners.add (l);
+ enableAccelerationChangeEvents (true);
+ }} private LinkedList accelerationChangeListeners = new LinkedList ();
+ private long nativeAccelerationChangeHandler = 0;
+ public final void removeAccelerationChangeListener (AccelerationChangeListener l)
+ {
+ synchronized (accelerationChangeListeners)
+ {
+ accelerationChangeListeners.remove (l);
+ enableAccelerationChangeEvents (accelerationChangeListeners.size () > 0);
+ }} private void fireAccelerationChange (AccelerationChangeEvent e)
+ {
+ synchronized (accelerationChangeListeners)
+ {
+ for (Iterator it = accelerationChangeListeners.iterator (); it.hasNext ();)
+ ((AccelerationChangeListener) it.next ()).accelerationChanged (e);
+ }
+ }
+ private native void enableAccelerationChangeEvents (boolean b);
+}
diff --git a/Java/com/phidgets/AdvancedServoPhidget.java b/Java/com/phidgets/AdvancedServoPhidget.java
new file mode 100644
index 0000000..1aa485a
--- /dev/null
+++ b/Java/com/phidgets/AdvancedServoPhidget.java
@@ -0,0 +1,492 @@
+
+/*
+ * Copyright 2006 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 Advanced Servo Controller. All methods
+ * to to control a motor controller and read back motor data are implemented in this class.
+ * <p>
+ * The Phidget Advanced Servo Controller is able to control 1 or more servo motors. Motos acceleration
+ * and Velocity are controllable. The number of servos that can be controlled depends on the
+ * version of the controller.
+ *
+ * @author Phidgets Inc.
+ */
+public final class AdvancedServoPhidget extends Phidget
+{
+ public AdvancedServoPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+
+ /**
+ * Default - This is what the servo API been historically used, originally based on the Futaba FP-S148. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_DEFAULT = 1;
+ /**
+ * Raw us mode - all position, velocity, acceleration functions are specified in microseconds rather then degrees. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_RAW_us_MODE = 2;
+ /**
+ * HiTec HS-322HD Standard Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS322HD = 3;
+ /**
+ * HiTec HS-5245MG Digital Mini Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS5245MG = 4;
+ /**
+ * HiTec HS-805BB Mega Quarter Scale Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_805BB = 5;
+ /**
+ * HiTec HS-422 Standard Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS422 = 6;
+ /**
+ * Tower Pro MG90 Micro Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_TOWERPRO_MG90 = 7;
+ /**
+ * HiTec HSR-1425CR Continuous Rotation Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HSR1425CR = 8;
+ /**
+ * HiTec HS-785HB Sail Winch Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS785HB = 9;
+ /**
+ * HiTec HS-485HB Deluxe Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS485HB = 10;
+ /**
+ * HiTec HS-645MG Ultra Torque Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS645MG = 11;
+ /**
+ * HiTec HS-815BB Mega Sail Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_815BB = 12;
+ /**
+ * Firgelli L12 Linear Actuator 30mm 50:1. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_FIRGELLI_L12_30_50_06_R = 13;
+ /**
+ * Firgelli L12 Linear Actuator 50mm 100:1. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_FIRGELLI_L12_50_100_06_R = 14;
+ /**
+ * Firgelli L12 Linear Actuator 50mm 210:1. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_FIRGELLI_L12_50_210_06_R = 15;
+ /**
+ * Firgelli L12 Linear Actuator 100mm 50:1. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_FIRGELLI_L12_100_50_06_R = 16;
+ /**
+ * Firgelli L12 Linear Actuator 100mm 100:1. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_FIRGELLI_L12_100_100_06_R = 17;
+ /**
+ * SpringRC SM-S2313M Micro Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S2313M = 18;
+ /**
+ * SpringRC SM-S3317M Small Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S3317M = 19;
+ /**
+ * SpringRC SM-S3317SR Small Continuous Rotation Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S3317SR = 20;
+ /**
+ * SpringRC SM-S4303R Standard Continuous Rotation Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S4303R = 21;
+ /**
+ * SpringRC SM-S4315M High Torque Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S4315M = 22;
+ /**
+ * SpringRC SM-S4315R High Torque Continuous Rotation Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S4315R = 23;
+ /**
+ * SpringRC SM-S4505B Standard Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S4505B = 24;
+ /**
+ * User Defined servo parameters. This is used with {@link #getServoType getServoType}
+ */
+ public static final int PHIDGET_SERVO_USER_DEFINED = 25;
+
+ /**
+ * Returns the number of servo motors supported by this Phidget. This does not neccesarily correspond
+ * to the number of motors actually attached to the board.
+ * @return number of supported motors
+ * @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 getMotorCount () throws PhidgetException;
+ /**
+ * Returns the maximum acceleration that a motor will accept, or return.
+ * <p>This value is in degrees per second squared.
+ * @param index Index of the motor
+ * @return Maximum acceleration
+ * @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 double getAccelerationMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum acceleration that a motor will accept, or return.
+ * <p>This value is in degrees per second squared.
+ * @param index Index of the motor
+ * @return Minimum acceleration
+ * @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 double getAccelerationMin (int index) throws PhidgetException;
+ /**
+ * Returns the maximum velocity that a servo motor will accept, or return.
+ * <p>This value is in degrees per second.
+ * @param index Index of the motor
+ * @return Maximum velocity
+ * @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 double getVelocityMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum velocity that a servo motor will accept, or return.
+ * <p>This value is in degrees per second.
+ * @param index Index of the motor
+ * @return Minimum velocity
+ * @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 double getVelocityMin (int index) throws PhidgetException;
+ /**
+ * Returns the maximum position that a servo motor will accept, or return.
+ * <p>This value is in degrees.
+ * @param index Index of the motor
+ * @return Maximum position
+ * @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 double getPositionMax (int index) throws PhidgetException;
+ /**
+ * Sets the maximum position that a servo motor will accept, or return. This is for limiting the range of motion of the servo
+ * controller. The Maximum cannot be extended beyond it's original value.
+ * <p>This value is in degrees.
+ * @param index Index of the motor
+ * @param position Maximum position
+ * @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 setPositionMax (int index, double position) throws PhidgetException;
+ /**
+ * Returns the minimum position that a servo motor will accept, or return.
+ * <p>This value uses the same units as
+ * <p>This value is in degrees.
+ * @param index Index of the motor
+ * @return Minimum position
+ * @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 double getPositionMin (int index) throws PhidgetException;
+ /**
+ * Sets the minimum position that a servo motor will accept, or return. This is for limiting the range of motion of the servo
+ * controller. The Minimum cannot be extended beyond it's original value.
+ * <p>This value is in degrees.
+ * @param index Index of the motor
+ * @param position Minimum position
+ * @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 setPositionMin (int index, double position) throws PhidgetException;
+ /**
+ * Returns a motor's acceleration. The valid range is between {@link #getAccelerationMin getAccelerationMin}
+ * and {@link #getAccelerationMax getAccelerationMax}, and refers to how fast the Servo Controller will change the speed of a motor.
+ * <p>This value is in degrees per second squared.
+ * @param index index of motor
+ * @return acceleration of motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if the acceleration is unknown.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getAcceleration (int index) throws PhidgetException;
+ /**
+ * Sets a motor's acceleration.
+ * The valid range is between {@link #getAccelerationMin getAccelerationMin} and {@link #getAccelerationMax getAccelerationMax}.
+ * This controls how fast the motor changes speed.
+ * <p>This value is in degrees per second squared.
+ * @param index index of the motor
+ * @param acceleration requested acceleration for that motor
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index or acceleration are invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setAcceleration (int index, double acceleration) throws PhidgetException;
+ /**
+ * Returns a motor's velocity limit. This is the maximum velocity that the motor will turn at.
+ * The valid range is between {@link #getVelocityMin getVelocityMin} and {@link #getVelocityMax getVelocityMax},
+ * with 0 being stopped.
+ * <p>This value is in degrees per second.
+ * @param index index of the motor
+ * @return current speed of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if the velocity in unknown.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getVelocityLimit (int index) throws PhidgetException;
+ /**
+ * Sets a motor's velocity limit. This is the maximum velocity that the motor will turn at.
+ * The valid range is between {@link #getVelocityMin getVelocityMin} and {@link #getVelocityMax getVelocityMax},
+ * with 0 being stopped.
+ * <p>This value is in degrees per second.
+ * @param index index of the motor
+ * @param velocity requested velocity for the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index or velocity are invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setVelocityLimit (int index, double velocity) throws PhidgetException;
+ /**
+ * Returns a motor's current velocity. The valid range is between {@link #getVelocityMin getVelocityMin} and {@link #getVelocityMax getVelocityMax},
+ * with 0 being stopped.
+ * <p>This value is in degrees per second.
+ * @param index index of the motor
+ * @return current speed of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if the velocity in unknown.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getVelocity (int index) throws PhidgetException;
+ /**
+ * Returns a motor's current position. This is the actual position that the motor is at right now.
+ * The valid range is between {@link #getPositionMin getPositionMin} and {@link #getPositionMax getPositionMax}.
+ * <p>This value is in degrees.
+ * @param index index of the motor
+ * @return current position of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if the position in unknown.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getPosition (int index) throws PhidgetException;
+ /**
+ * Sets a motor's target position. Use this is set the target position for the servo.
+ * If the servo is {@link #setEngaged engaged} it will start moving towards this target position.
+ * The valid range is between {@link #getPositionMin getPositionMin} and {@link #getPositionMax getPositionMax}.
+ * <p>This value is in degrees.
+ * @param index index of the motor
+ * @param position target position of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index or position are invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setPosition (int index, double position) throws PhidgetException;
+ /**
+ * Returns the engaged state of a motor.
+ *
+ * @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 boolean getEngaged (int index) throws PhidgetException;
+ /**
+ * Engage or disengage a motor.
+ * <p>
+ * This engages or disengages the servo motor. The motors are by default disengaged when the servo controller is plugged in.
+ * When the servo is disengaged, position, velocity, etc. can all be set, but the motor will not start moving until it is engaged.
+ * If position is read when a motor is disengaged, it will throw an exception.
+ * <p>
+ * This corresponds to a PCM of 0 being sent to the servo.
+ *
+ * @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 void setEngaged (int index, boolean state) throws PhidgetException;
+ /**
+ * Returns the speed ramping state of a motor.
+ *
+ * @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 boolean getSpeedRampingOn (int index) throws PhidgetException;
+ /**
+ * Sets the speed ramping state.
+ * <p>
+ * Disable speed ramping to disable velocity and acceleration control. With speed ramping disabled, the servo will be sent to
+ * the desired position immediately upon recieving the command. This is how the regular Phidget Servo Controller works.
+ * <p>
+ * This is turned on by default.
+ *
+ * @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 void setSpeedRampingOn (int index, boolean state) throws PhidgetException;
+ /**
+ * Returns a motor's current usage. The valid range depends on the servo controller.
+ * This value is in Amps.
+ * @param index index of the motor
+ * @return current usage of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if the value is unknown.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getCurrent (int index) throws PhidgetException;
+ /**
+ * Returns the stopped state of a motor. Use this to determine if the motor is moving and/or up to date with the latest commands you have sent.
+ * If this is true, the motor is guaranteed to be stopped and to have processed every command issued. Generally, this would
+ * be polled after a target position is set to wait until that position is reached.
+ *
+ * @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 boolean getStopped (int index) throws PhidgetException;
+ /**
+ * Returns the servo type for an index.
+ * The possible values for type are {@link #PHIDGET_SERVO_DEFAULT PHIDGET_SERVO_DEFAULT},
+ * {@link #PHIDGET_SERVO_RAW_us_MODE PHIDGET_SERVO_RAW_us_MODE}, {@link #PHIDGET_SERVO_HITEC_HS322HD PHIDGET_SERVO_HITEC_HS322HD},
+ * {@link #PHIDGET_SERVO_HITEC_HS5245MG PHIDGET_SERVO_HITEC_HS5245MG}, {@link #PHIDGET_SERVO_HITEC_805BB PHIDGET_SERVO_HITEC_805BB},
+ * {@link #PHIDGET_SERVO_HITEC_HS422 PHIDGET_SERVO_HITEC_HS422}, etc.
+ * @param index Input
+ * @return Servo Type
+ * @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 int getServoType (int index) throws PhidgetException;
+ /**
+ * Sets the servo type for an index.
+ * <p>
+ * This constrains the PCM to the valid range of the servo, and sets the degrees-to-PCM ratio to match the actual servo rotation.
+ * Velocity is also constrained to the maximum speed attainable by the servo.
+ * <p>
+ * The possible values for type are {@link #PHIDGET_SERVO_DEFAULT PHIDGET_SERVO_DEFAULT},
+ * {@link #PHIDGET_SERVO_RAW_us_MODE PHIDGET_SERVO_RAW_us_MODE}, {@link #PHIDGET_SERVO_HITEC_HS322HD PHIDGET_SERVO_HITEC_HS322HD},
+ * {@link #PHIDGET_SERVO_HITEC_HS5245MG PHIDGET_SERVO_HITEC_HS5245MG}, {@link #PHIDGET_SERVO_HITEC_805BB PHIDGET_SERVO_HITEC_805BB},
+ * {@link #PHIDGET_SERVO_HITEC_HS422 PHIDGET_SERVO_HITEC_HS422}, etc.
+ * <p>
+ * Support for other servo types can be achieved by using {@link #setServoParameters setServoParameters}.
+ * <p>
+ * The default setting is {@link #PHIDGET_SERVO_DEFAULT PHIDGET_SERVO_DEFAULT}, which is used for historical (backwards compatibility) reasons.
+ * @param index Input
+ * @param type Servo Type
+ * @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 void setServoType (int index, int type) throws PhidgetException;
+ /**
+ * Sets the servo parameters for a custom servo definition.
+ * <p>
+ * This constrains the PCM to the valid range of the servo, and sets the degrees-to-PCM ratio to match the actual servo rotation.
+ * Velocity is also constrained to the maximum speed attainable by the servo.
+ * <p>
+ * @param index Servo Index
+ * @param minUs Minimum PCM supported in microseconds
+ * @param maxUs Maximum PCM supported in microseconds
+ * @param degrees Degrees of rotation represented by the given PCM range
+ * @param velocityMax Maximum supported velocity of the servo in degrees/second
+ * @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 void setServoParameters (int index, double minUs, double maxUs, double degrees, double velocityMax) throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableServoPositionChangeEvents (b && servoPositionChangeListeners.size () > 0);
+ enableServoVelocityChangeEvents (b && servoVelocityChangeListeners.size () > 0);
+ enableCurrentChangeEvents (b && currentChangeListeners.size () > 0);
+ }
+ /**
+ * Adds a position change listener. The position change handler is a method that will be called when the servo
+ * position has changed.
+ * <p>
+ * There is no limit on the number of position change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.ServoPositionChangeListener ServoPositionChangeListener} interface
+ */
+ public final void addServoPositionChangeListener (ServoPositionChangeListener l)
+ {
+ synchronized (servoPositionChangeListeners)
+ {
+ servoPositionChangeListeners.add (l);
+ enableServoPositionChangeEvents (true);
+ }} private LinkedList servoPositionChangeListeners = new LinkedList ();
+ private long nativeServoPositionChangeHandler = 0;
+ public final void removeServoPositionChangeListener (ServoPositionChangeListener l)
+ {
+ synchronized (servoPositionChangeListeners)
+ {
+ servoPositionChangeListeners.remove (l);
+ enableServoPositionChangeEvents (servoPositionChangeListeners.size () > 0);
+ }} private void fireServoPositionChange (ServoPositionChangeEvent e)
+ {
+ synchronized (servoPositionChangeListeners)
+ {
+ for (Iterator it = servoPositionChangeListeners.iterator (); it.hasNext ();)
+ ((ServoPositionChangeListener) it.next ()).servoPositionChanged (e);
+ }
+ }
+ private native void enableServoPositionChangeEvents (boolean b);
+ /**
+ * Adds a velocity change listener. The velocity change handler is a method that will be called when the servo
+ * velocity has changed.
+ * <p>
+ * There is no limit on the number of velocity change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.ServoVelocityChangeListener ServoVelocityChangeListener} interface
+ */
+ public final void addServoVelocityChangeListener (ServoVelocityChangeListener l)
+ {
+ synchronized (servoVelocityChangeListeners)
+ {
+ servoVelocityChangeListeners.add (l);
+ enableServoVelocityChangeEvents (true);
+ }} private LinkedList servoVelocityChangeListeners = new LinkedList ();
+ private long nativeServoVelocityChangeHandler = 0;
+ public final void removeServoVelocityChangeListener (ServoVelocityChangeListener l)
+ {
+ synchronized (servoVelocityChangeListeners)
+ {
+ servoVelocityChangeListeners.remove (l);
+ enableServoVelocityChangeEvents (servoVelocityChangeListeners.size () > 0);
+ }} private void fireServoVelocityChange (ServoVelocityChangeEvent e)
+ {
+ synchronized (servoVelocityChangeListeners)
+ {
+ for (Iterator it = servoVelocityChangeListeners.iterator (); it.hasNext ();)
+ ((ServoVelocityChangeListener) it.next ()).servoVelocityChanged (e);
+ }
+ }
+ private native void enableServoVelocityChangeEvents (boolean b);
+ /**
+ * Adds a current change listener. The current change handler is a method that will be called when the servo
+ * current has changed.
+ * <p>
+ * There is no limit on the number of current change handlers that can be registered for a particular Phidget.
+ * <p>
+ * Note that not all stepper controllers support current sensing.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.CurrentChangeListener CurrentChangeListener} interface
+ */
+ public final void addCurrentChangeListener (CurrentChangeListener l)
+ {
+ synchronized (currentChangeListeners)
+ {
+ currentChangeListeners.add (l);
+ enableCurrentChangeEvents (true);
+ }} private LinkedList currentChangeListeners = new LinkedList ();
+ private long nativeCurrentChangeHandler = 0;
+ public final void removeCurrentChangeListener (CurrentChangeListener l)
+ {
+ synchronized (currentChangeListeners)
+ {
+ currentChangeListeners.remove (l);
+ enableCurrentChangeEvents (currentChangeListeners.size () > 0);
+ }} private void fireCurrentChange (CurrentChangeEvent e)
+ {
+ synchronized (currentChangeListeners)
+ {
+ for (Iterator it = currentChangeListeners.iterator (); it.hasNext ();)
+ ((CurrentChangeListener) it.next ()).currentChanged (e);
+ }
+ }
+ private native void enableCurrentChangeEvents (boolean b);
+}
diff --git a/Java/com/phidgets/AnalogPhidget.java b/Java/com/phidgets/AnalogPhidget.java
new file mode 100644
index 0000000..b8f4c0a
--- /dev/null
+++ b/Java/com/phidgets/AnalogPhidget.java
@@ -0,0 +1,78 @@
+
+/*
+ * Copyright 2011 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 Analog. All methods
+ * to manipulate the Phidget Analog are implemented in this class.
+ *
+ * @author Phidgets Inc.
+ */
+public final class AnalogPhidget extends Phidget
+{
+ public AnalogPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+
+ /**
+ * Returns the number of analog outputs.
+ * @return Number of analog outputs
+ */
+ public native int getOutputCount () throws PhidgetException;
+ /**
+ * Returns the current voltage output setting for an analog output, in Volts. The range is between {@link #getVoltageMin(int) getVoltageMin} and {@link #getVoltageMax(int) getVoltageMax}.
+ * @param index index of the analog output
+ * @return current voltage for an analog output, in Volts
+ * @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 getVoltage (int index) throws PhidgetException;
+ /**
+ * Sets the current voltage setting for an analog output, in Volts. The range is between {@link #getVoltageMin(int) getVoltageMin} and {@link #getVoltageMax(int) getVoltageMax}.
+ * @param index index of the analog output
+ * @param current new voltage for an analog output, in Volts
+ * @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 void setVoltage (int index, double current) throws PhidgetException;
+ /**
+ * Gets the minimum supported voltage for an output, in Volts.
+ * @param index index of the analog output
+ * @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 getVoltageMin (int index) throws PhidgetException;
+ /**
+ * Gets the maximum supported voltage for an output, in Volts.
+ * @param index index of the analog output
+ * @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 getVoltageMax (int index) throws PhidgetException;
+ /**
+ * Returns the enabled state for an analog output. When enabled, the output drives at the set Voltage, up to 20mA. When disabled, the output is tied to ground via a 4K pull-down.
+ * @param index index of the analog output
+ * @return enabled state for an output
+ * @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 for a an analog output. When enabled, the output drives at the set Voltage, up to 20mA. When disabled, the output is tied to ground via a 4K pull-down.
+ * @param index index of the analog output
+ * @param state new state of the analog output
+ * @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;
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ }
+}
diff --git a/Java/com/phidgets/BridgePhidget.java b/Java/com/phidgets/BridgePhidget.java
new file mode 100644
index 0000000..55f0b65
--- /dev/null
+++ b/Java/com/phidgets/BridgePhidget.java
@@ -0,0 +1,202 @@
+
+/*
+ * Copyright 2011 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.
+ * <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);
+}
diff --git a/Java/com/phidgets/Dictionary.java b/Java/com/phidgets/Dictionary.java
new file mode 100644
index 0000000..0afde5e
--- /dev/null
+++ b/Java/com/phidgets/Dictionary.java
@@ -0,0 +1,348 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets;
+
+import com.phidgets.event.*;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Vector;
+
+/**
+ * This class represents the Phidget Dictionary.
+ * <p>
+ * The Phidget Dictionary is a service provided by the Phidget Webservice.
+ * The Webservice maintains a centralized dictionary of key-value pairs that can be accessed and changed from any number of clients.
+ * <p>
+ * Note that the Webservice uses this dictionary to control access to Phidgets through the openRemote and openRemoteIP interfaces,
+ * and as such, you should never add or modify a key that starts with /PSK/ or /PCK/, unless you want to explicitly modify Phidget
+ * specific data -- and this is highly discouraged, as it's very easy to break things. Listening to these keys is fine if so desired.
+ * <p>
+ * The intended use for the dictionary is as a central repository for communication and persistent storage of data between several
+ * client applications. As an example - a higher level interface exposed by one application -- which controls the Phidgets, for
+ * others to access -- rather then every client talking directly to the Phidgets themselves.
+ * <p>
+ * The dictionary makes use of extended regular expressions for key matching.
+ *
+ * @author Phidgets Inc.
+ */
+public class Dictionary
+{
+ static
+ {
+ try
+ {
+ System.loadLibrary("phidget21");
+ }
+ catch(UnsatisfiedLinkError ex)
+ {
+ String os = System.getProperty("os.name");
+ if(os.startsWith("Linux"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library (libphidget21.so)."
+ +"\nMake sure it is installed, and add it's path to LD_LIBRARY_PATH.");
+ }
+ else if(os.startsWith("Windows"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library."
+ +"\nThe Windows Phidget21 MSI must be installed.");
+ }
+ else if(os.startsWith("Mac"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library."
+ +"\nThe Mac Phidget21 DMG must be installed.");
+ }
+ else
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library.");
+ }
+ }
+ }
+
+ public long handle = 0;
+ /**
+ * The default constructor. Creating a Phidget Dictionary object will initialize the
+ * dictionary handle internally, but {@link #open(String, int) open} still needs to be called
+ * to actually work with it.
+ */
+ public Dictionary() throws PhidgetException
+ {
+ handle = create();
+ }
+ private final native long create() throws PhidgetException;
+
+ private final native void nativeClose() throws PhidgetException;
+ private final native void nativeDelete() throws PhidgetException;
+ private final native void nativeOpenRemote(String serverID, String pass) throws PhidgetException;
+ private final native void nativeOpenRemoteIP(String ipAddress, int port, String pass) throws PhidgetException;
+ private final native void nativeAddKey(String key, String val, int persistent) throws PhidgetException;
+ private final native void nativeRemoveKey(String keyPattern) throws PhidgetException;
+ private final native String nativeGetKey(String key) throws PhidgetException;
+
+
+ /**
+ * Returns the Address of a Phidget Webservice when this Dictionary was opened as remote. This may be an IP Address or a hostname.
+ *
+ * @return Server Address
+ * @throws PhidgetException if this Dictionary was not opened.
+ */
+ public final native String getServerAddress() throws PhidgetException;
+ /**
+ * Returns the Server ID of a Phidget Webservice when this Dictionary was opened as remote. This is an arbitrary server identifier,
+ * independant of IP address and Port.
+ *
+ * @return Server ID
+ * @throws PhidgetException if this Dictionary was not opened.
+ */
+ public final native String getServerID() throws PhidgetException;
+ /**
+ * Returns the Port of a Phidget Webservice when this Dictionary was opened as remote.
+ *
+ * @return Server Port
+ * @throws PhidgetException if this Dictionary was not opened.
+ */
+ public final native int getServerPort() throws PhidgetException;
+ /**
+ * Returns the attached status of this Dictionary.
+ *
+ * @return Status
+ * @throws PhidgetException If this Dictionary is not opened.
+ */
+ public final native boolean isAttached() throws PhidgetException;
+
+ /**
+ * Returns the network attached status for remotely opened Phidgets. This method returns True or False, depending on whether a connection to the
+ * Phidget WebService is open - or not. If this is false for a remote Phidget then the connection is not active - either because a connection
+ * has not yet been established, or because the connection was terminated.
+ *
+ * @return Status
+ * @throws PhidgetException If this Phidget is not opened.
+ */
+ public final native boolean isAttachedToServer() throws PhidgetException;
+
+ /**
+ * Adds a new key to the Dictionary, or modifies the value of an existing key.
+ * <p>
+ * The key can only contain numbers, letters, "/", ".", "-", "_", and must begin with a letter, "_" or "/".
+ * <p>
+ * The value can contain any value.
+ * <p>
+ * The key will stay in the dictionary until explicitly removed.
+ *
+ *
+ */
+ public final void add(String key, String val) throws PhidgetException
+ {
+ nativeAddKey(key, val, 1);
+ }
+
+ /**
+ * Adds a new key to the Dictionary, or modifies the value of an existing key.
+ * <p>
+ * The key can only contain numbers, letters, "/", ".", "-", "_", and must begin with a letter, "_" or "/".
+ * <p>
+ * The value can contain any value.
+ * <p>
+ * The persistent value controls whether a key will stay in the dictionary after the client that created it disconnects.
+ * If persistent == 0, the key is removed when the connection closes. Otherwise the key remains in the dictionary until
+ * it is explicitly removed.
+ *
+ */
+ public final void add(String key, String val, boolean persistent) throws PhidgetException
+ {
+ if (persistent) nativeAddKey(key, val, 1);
+ else nativeAddKey(key, val, 0);
+ }
+ /**
+ * Removes a key, or set of keys, from the Dictionary.
+ * <p>
+ * The key name is a regular expressions pattern, and so care must be taken to only have it match the specific keys you want to remove.
+ */
+ public final void remove(String pattern) throws PhidgetException
+ {
+ nativeRemoveKey(pattern);
+ }
+
+ /**
+ * Gets the value for a key.
+ */
+ public final String get(String key) throws PhidgetException
+ {
+ return nativeGetKey(key);
+ }
+
+ /**
+ * Open this Dictionary remotely and securely, using an IP Address.
+ * <p>
+ * This method is the same as {@link #open(String, int) open(String ipAddress, int port)}, except that it specifies a password.
+ * This password can be set as a parameter when starting the Phidget Webservice.
+ */
+ public final void open(String ipAddress, int port, String password) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenRemoteIP(ipAddress, port, password);
+ }
+ /**
+ * Open this Dictionary remotely using an IP Address.
+ * <p>
+ * This version of open is network based, and relies on the Phidget Webservice running at the specified Address and Port
+ * before open is called.
+ * <p>
+ * @param ipAddress IP Address or hostname of the Phidget Webservice
+ * @param port Port of the Phidget Webservice
+ * @throws PhidgetException if the Phidget Webservice cannot be contacted
+ */
+ public final void open(String ipAddress, int port) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenRemoteIP(ipAddress, port, "");
+ }
+ /**
+ * Open this Dictionary remotely and securely, using a Server ID.
+ * <p>
+ * This method is the same as {@link #open(String) open(String serverID)}, except that it specifies a password.
+ * This password can be set as a parameter when starting the Phidget Webservice.
+ */
+ public final void open(String serverID, String password) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenRemote(serverID, password);
+ }
+ /**
+ * Open this Dictionary remotely using a Server ID.
+ * <p>
+ * This version of open is network based.
+ *
+ * @param serverID ServerID of the Phidget Webservice
+ */
+ public final void open(String serverID) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenRemote(serverID, "");
+ }
+ /**
+ * Closes this Dictionary.
+ * This will shut down all threads dealing with this Dictionary and you won't recieve any more events.
+ *
+ * @throws PhidgetException If this Dictionary is not opened.
+ */
+ public final void close() throws PhidgetException
+ {
+ enableEvents(false);
+ nativeClose();
+ }
+
+ private void enableEvents(boolean b)
+ {
+ enableServerConnectEvents(b && serverConnectListeners.size() > 0);
+ enableServerDisconnectEvents(b && serverDisconnectListeners.size() > 0);
+ }
+
+ private LinkedList serverConnectListeners = new LinkedList();
+ private long nativeServerConnectHandler = 0;
+
+ /**
+ * Adds an serverConnect listener. The serverConnect handler is a method that will be called when a connection to a server is made
+ * <p>
+ * There is no limit on the number of serverConnect handlers that can be registered for a particular Manager.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.ServerConnectListener ServerConnectListener} interface
+ */
+ public final void addServerConnectListener(ServerConnectListener l)
+ {
+ synchronized (serverConnectListeners)
+ {
+ serverConnectListeners.add(l);
+ enableServerConnectEvents(true);
+ }
+ }
+
+ /**
+ * Removes an serverConnect listener. This will remove a previously added serverConnect listener.
+ */
+ public final void removeServerConnectListener(ServerConnectListener l)
+ {
+ synchronized (serverConnectListeners)
+ {
+ serverConnectListeners.remove(l);
+ enableServerConnectEvents(serverConnectListeners.size() > 0);
+ }
+ }
+ private void fireServerConnect(ServerConnectEvent e)
+ {
+ synchronized (serverConnectListeners)
+ {
+ for (Iterator it = serverConnectListeners.iterator();
+ it.hasNext(); )
+ ((ServerConnectListener)it.next()).serverConnected(e);
+ }
+ }
+ private native void enableServerConnectEvents(boolean b);
+
+
+ private LinkedList serverDisconnectListeners = new LinkedList();
+ private long nativeServerDisconnectHandler = 0;
+
+ /**
+ * Adds an serverDisconnect listener. The serverDisconnect handler is a method that will be called when a connection to a server is terminated.
+ * <p>
+ * There is no limit on the number of serverDisconnect handlers that can be registered for a particular Manager.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.ServerDisconnectListener ServerDisconnectListener} interface
+ */
+ public final void addServerDisconnectListener(ServerDisconnectListener l)
+ {
+ synchronized (serverDisconnectListeners)
+ {
+ serverDisconnectListeners.add(l);
+ enableServerDisconnectEvents(true);
+ }
+ }
+
+ /**
+ * Removes an serverDisconnect listener. This will remove a previously added serverDisconnect listener.
+ */
+ public final void removeServerDisconnectListener(ServerDisconnectListener l)
+ {
+ synchronized (serverDisconnectListeners)
+ {
+ serverDisconnectListeners.remove(l);
+ enableServerDisconnectEvents(serverDisconnectListeners.size() > 0);
+ }
+ }
+ private void fireServerDisconnect(ServerDisconnectEvent e)
+ {
+ synchronized (serverDisconnectListeners)
+ {
+ for (Iterator it = serverDisconnectListeners.iterator();
+ it.hasNext(); )
+ ((ServerDisconnectListener)it.next()).serverDisconnected(e);
+ }
+ }
+ private native void enableServerDisconnectEvents(boolean b);
+
+ /**
+ * Return a Sring describing this dictionary.
+ */
+ public String toString()
+ {
+ return "PhidgetDictionary: ";
+ }
+
+ protected void finalize() {
+ try
+ {
+ close();
+ nativeDelete();
+ handle = 0;
+ } catch (Exception e) {
+ ;
+ }
+ }
+}
diff --git a/Java/com/phidgets/DictionaryKeyListener.java b/Java/com/phidgets/DictionaryKeyListener.java
new file mode 100644
index 0000000..db09a90
--- /dev/null
+++ b/Java/com/phidgets/DictionaryKeyListener.java
@@ -0,0 +1,184 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets;
+
+import com.phidgets.event.*;
+
+import com.phidgets.Dictionary;
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * This class represents a key listener.
+ * <p>
+ * This key listener is used, along with the Dictionary object, to set up listener for specific keys, or groups of keys.
+ * Events are available for key add or change, and for key removal.
+ */
+public class DictionaryKeyListener
+{
+ private String pattern;
+ Dictionary dict;
+
+ static
+ {
+ try
+ {
+ System.loadLibrary("phidget21");
+ }
+ catch(UnsatisfiedLinkError ex)
+ {
+ String os = System.getProperty("os.name");
+ if(os.startsWith("Linux"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library."
+ +"\nMake sure to compile with 'make jni' and install with 'make install'.");
+ }
+ else if(os.startsWith("Windows"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library."
+ +"\nThe Windows Phidget21 MSI must be installed.");
+ }
+ else if(os.startsWith("Mac"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library."
+ +"\nThe Mac Phidget21 DMG must be installed.");
+ }
+ else
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library.");
+ }
+ }
+ }
+
+ private long handle = 0;
+ private long nativeHandler = 0;
+ public long listenerhandle = 0;
+
+ /**
+ * Start this key listener. This method should not be called until the coresponding dictionary is connected.
+ */
+ public void start() throws PhidgetException
+ {
+ this.handle = dict.handle;
+ if (handle == 0)
+ throw (new PhidgetException(5, "Dictionary is not attached - call open first"));
+ listenerhandle = enableDictionaryKeyEvents((keyChangeListeners.size() > 0) || (keyRemovalListeners.size() > 0), pattern);
+ }
+
+ /**
+ * Stop this key listener.
+ */
+ public void stop()
+ {
+ listenerhandle = enableDictionaryKeyEvents(false, pattern);
+ }
+
+ /**
+ * Returns the Dictionary object that this listener is listening on.
+ */
+ public Dictionary getDictionary()
+ {
+ return dict;
+ }
+
+ /**
+ * Creates a new key listener, for a specific pattern, on a specific dictionary object.
+ * The pattern is a regular expression.
+ */
+ public DictionaryKeyListener(Dictionary dict, String pattern)
+ {
+ this.pattern = pattern;
+ this.dict = dict;
+ this.handle = dict.handle;
+ }
+
+ private LinkedList keyChangeListeners = new LinkedList();
+ private long nativeKeyChangeHandler = 0;
+
+ /**
+ * Add a new listener for key change events. This also applies for key add events..
+ */
+ public final void addKeyChangeListener(KeyChangeListener l)
+ {
+ synchronized (keyChangeListeners)
+ {
+ keyChangeListeners.add(l);
+ //enableDictionaryKeyEvents(true, pattern);
+ }
+ }
+ /**
+ * Removes a key change listener.
+ */
+ public final void removeKeyChangeListener(KeyChangeListener l)
+ {
+ synchronized (keyChangeListeners)
+ {
+ keyChangeListeners.remove(l);
+ //enableDictionaryKeyEvents(keyChangeListeners.size() > 0, pattern);
+ }
+ }
+ private void fireKeyChange(KeyChangeEvent e)
+ {
+ synchronized (keyChangeListeners)
+ {
+ for (Iterator it = keyChangeListeners.iterator();
+ it.hasNext(); )
+ ((KeyChangeListener)it.next()).keyChanged(e);
+ }
+ }
+ private native long enableDictionaryKeyEvents(boolean b, String pattern);
+
+ private LinkedList keyRemovalListeners = new LinkedList();
+ private long nativeKeyRemovalHandler = 0;
+
+ /**
+ * Add a new listener for key removal events.
+ */
+ public final void addKeyRemovalListener(KeyRemovalListener l)
+ {
+ synchronized (keyRemovalListeners)
+ {
+ keyRemovalListeners.add(l);
+ //enableDictionaryKeyEvents(true, pattern);
+ }
+ }
+ /**
+ * removes a key removal listener.
+ */
+ public final void removeKeyRemovalListener(KeyRemovalListener l)
+ {
+ synchronized (keyRemovalListeners)
+ {
+ keyRemovalListeners.remove(l);
+ //enableDictionaryKeyEvents(keyRemovalListeners.size() > 0, pattern);
+ }
+ }
+ private void fireKeyRemoval(KeyRemovalEvent e)
+ {
+ synchronized (keyRemovalListeners)
+ {
+ for (Iterator it = keyRemovalListeners.iterator();
+ it.hasNext(); )
+ ((KeyRemovalListener)it.next()).keyRemoved(e);
+ }
+ }
+
+ /**
+ * Return a Sring describing this dictionary key listener.
+ */
+ public String toString()
+ {
+ return dict.toString() + "Dictionary Key Listener ("+pattern+"): ";
+ }
+
+ protected void finalize()
+ {
+ listenerhandle = enableDictionaryKeyEvents(false, pattern);
+ }
+}
diff --git a/Java/com/phidgets/EncoderPhidget.java b/Java/com/phidgets/EncoderPhidget.java
new file mode 100644
index 0000000..1543bd3
--- /dev/null
+++ b/Java/com/phidgets/EncoderPhidget.java
@@ -0,0 +1,173 @@
+
+/*
+ * Copyright 2006 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 Encoder. All methods
+ * to read encoder data from an encoder are implemented in this class.
+ <p>
+ Phidget Encoder boards generally support 1 or more encoders with 0 or more digital inputs.
+ Both high speed optical and low speed mechanical encoders are supported with this API.
+ *
+ * @author Phidgets Inc.
+ */
+public final class EncoderPhidget extends Phidget
+{
+ public EncoderPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+ /**
+ * Returns number of encoders. All current encoder boards support one encoder.
+ * @return number of encoders
+ * @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 getEncoderCount () throws PhidgetException;
+ /**
+ * Returns number of digital inputs. On the mechanical encoder this refers to the pushbutton. The
+ high speed encoder does not have any digital inputs.
+ * @return number of inputs
+ * @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 getInputCount () throws PhidgetException;
+ /**
+ * Returns the position of an encoder. This is an absolute position as calcutated since the encoder was plugged in.
+ This value can be reset to anything using {@link #setEncoderPosition(int, int) setEncoderPosition}.
+ * @param index index of the encoder
+ * @return position of the encoder
+ * @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 int getPosition (int index) throws PhidgetException;
+ /**
+ * Returns the last index position of an encoder. This is the position of the last index pulse. Not all encoders support index.
+ * @param index index of the encoder
+ * @return last index position of the encoder
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is out of range, of if index is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native int getIndexPosition (int index) throws PhidgetException;
+ /**
+ * @deprecated Replaced by
+ * {@link #getPosition}
+ */
+ public native int getEncoderPosition (int index) throws PhidgetException;
+ /**
+ * Sets the position of a specific encoder. This resets the internal position count for an encoder. This call in no way actually
+ sends information to the device, as an absolute position is maintained only in the library. After this call, position changes
+ from the encoder will use the new value to calculate absolute position as reported by {@link #getEncoderPosition}.
+ * @param index index of the encoder
+ * @param position new position for this encoder.
+ * @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 void setPosition (int index, int position) throws PhidgetException;
+ /**
+ * @deprecated Replaced by
+ * {@link #setPosition}
+ */
+ public native void setEncoderPosition (int index, int position) throws PhidgetException;
+ /**
+ * Returns the state of a digital input. On the mechanical encoder this refers to the pushbutton. The
+ high speed encoder does not have any digital inputs. A value of true means that the input is active(the button is pushed).
+ * @param index index of the input
+ * @return state of the input
+ * @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 boolean getInputState (int index) throws PhidgetException;
+ /**
+ * Returns the enabled state of an encoder. True indicated activated, False deactivated, which is the default.
+ * @param index index of the encoder
+ * @return state of the encoder
+ * @throws PhidgetException If this Phidget is not opened and attached, the index is out of range, or enable is not supported.
+ * 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 an encoder. True indicated activated, False deactivated, which is the default.
+ * @param index index of the encoder
+ * @param state desired state
+ * @throws PhidgetException If this Phidget is not opened and attached, the index is out of range, or enable is not supported.
+ * 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;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableEncoderPositionChangeEvents (b && encoderPositionChangeListeners.size () > 0);
+ enableInputChangeEvents (b && inputChangeListeners.size () > 0);
+ }
+ /**
+ * Adds a position change listener. The position change handler is a method that will be called when the position of an
+ encoder changes. The position change event provides data about how many ticks have occured, and how much time has
+ passed since the last position change event, but does not contain an absolute position. This can be obtained from
+ {@link #getEncoderPosition}.
+ * <p>
+ * There is no limit on the number of position change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.EncoderPositionChangeListener EncoderPositionChangeListener} interface
+ */
+ public final void addEncoderPositionChangeListener (EncoderPositionChangeListener l)
+ {
+ synchronized (encoderPositionChangeListeners)
+ {
+ encoderPositionChangeListeners.add (l);
+ enableEncoderPositionChangeEvents (true);
+ }} private LinkedList encoderPositionChangeListeners = new LinkedList ();
+ private long nativeEncoderPositionChangeHandler = 0;
+ public final void removeEncoderPositionChangeListener (EncoderPositionChangeListener l)
+ {
+ synchronized (encoderPositionChangeListeners)
+ {
+ encoderPositionChangeListeners.remove (l);
+ enableEncoderPositionChangeEvents (encoderPositionChangeListeners.size () > 0);
+ }} private void fireEncoderPositionChange (EncoderPositionChangeEvent e)
+ {
+ synchronized (encoderPositionChangeListeners)
+ {
+ for (Iterator it = encoderPositionChangeListeners.iterator (); it.hasNext ();)
+ ((EncoderPositionChangeListener) it.next ()).encoderPositionChanged (e);
+ }
+ }
+ private native void enableEncoderPositionChangeEvents (boolean b);
+ /**
+ * Adds an input change listener. The input change handler is a method that will be called when an input on this
+ * Encoder board has changed.
+ * <p>
+ * There is no limit on the number of input change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.InputChangeListener InputChangeListener} interface
+ */
+ public final void addInputChangeListener (InputChangeListener l)
+ {
+ synchronized (inputChangeListeners)
+ {
+ inputChangeListeners.add (l);
+ enableInputChangeEvents (true);
+ }} private LinkedList inputChangeListeners = new LinkedList ();
+ private long nativeInputChangeHandler = 0;
+ public final void removeInputChangeListener (InputChangeListener l)
+ {
+ synchronized (inputChangeListeners)
+ {
+ inputChangeListeners.remove (l);
+ enableInputChangeEvents (inputChangeListeners.size () > 0);
+ }} private void fireInputChange (InputChangeEvent e)
+ {
+ synchronized (inputChangeListeners)
+ {
+ for (Iterator it = inputChangeListeners.iterator (); it.hasNext ();)
+ ((InputChangeListener) it.next ()).inputChanged (e);
+ }
+ }
+ private native void enableInputChangeEvents (boolean b);
+}
diff --git a/Java/com/phidgets/FrequencyCounterPhidget.java b/Java/com/phidgets/FrequencyCounterPhidget.java
new file mode 100644
index 0000000..b6b138e
--- /dev/null
+++ b/Java/com/phidgets/FrequencyCounterPhidget.java
@@ -0,0 +1,171 @@
+
+/*
+ * Copyright 2011 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 Frequency Counter. All methods
+ * to read manipulate the Phidget Frequency Counter are implemented in this class.
+ * <p>
+ *
+ * @author Phidgets Inc.
+ */
+public final class FrequencyCounterPhidget extends Phidget
+{
+ public FrequencyCounterPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+ /**
+ * Zero-Crossing Filter Type. This is used with {@link #getFilter(int) getFilter} and {@link #setFilter(int, int) setFilter}
+ */
+ public static final int PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_ZERO_CROSSING = 1;
+ /**
+ * Logic-Level Filter Type. This is used with {@link #getFilter(int) getFilter} and {@link #setFilter(int, int) setFilter}
+ */
+ public static final int PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_LOGIC_LEVEL = 2;
+ /**
+ * Unknown Filter Type. This is used with {@link #getFilter(int) getFilter} and {@link #setFilter(int, int) setFilter}
+ */
+ public static final int PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_UNKNOWN = 3;
+ /**
+ * Returns the number of channels.
+ * @return Number of inputs
+ */
+ public native int getFrequencyInputCount () throws PhidgetException;
+ /**
+ * Returns the last calcualted frequency on the specified channel, in Hz. This function will return 0 if the {@link #getTimeout(int) getTimeout} value elapses without detecting a signal.
+ * Frequency is recalculated up to 31.25 times a second, depending on the pulse rate.
+ * @param index Index of the channel
+ * @return frequency of the channel
+ * @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 getFrequency (int index) throws PhidgetException;
+ /**
+ * Returns the total number of pulses detected on the specified channel since the Phidget was opened, or since the last reset.
+ * @param index Index of the channel
+ * @return total number of pulses
+ * @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 long getTotalCount (int index) throws PhidgetException;
+ /**
+ * Returns the total elapsed tiem since Phidget was opened, or since the last reset, in microseconds. This time corresponds to the {@link #getTotalCount(int) getTotalCount} property.
+ * @param index Index of the channel
+ * @return total time, in microseconds
+ * @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 long getTotalTime (int index) throws PhidgetException;
+ /**
+ * Returns the timeout value, in microseconds. This value is used to set the time to wait without detecting a signal before reporting 0 Hz. The valid range is 0.1 - 100 seconds(100,000 - 100,000,000 microseconds).
+ * 0.1 timeout represents the lowest frequency that will be measurable.
+ * @param index Index of the channel
+ * @return timeout 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 int getTimeout (int index) throws PhidgetException;
+ /**
+ * Sets the timeout value, in microseconds. This value is used to set the time to wait without detecting a signal before reporting 0 Hz. The valid range is 0.1 - 100 seconds(100,000 - 100,000,000 microseconds).
+ * 0.1 timeout represents the lowest frequency that will be measurable.
+ * @param index Index of the channel
+ * @param timeout new timeout value
+ * @throws PhidgetException If this Phidget is not opened and attached, the index is out of range or the the timeout value is out of range.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setTimeout (int index, int timeout) throws PhidgetException;
+ /**
+ * Returns the enabled state on the specified channel. When the channel is disabled, it will no longer register counts. TotalTime and TotalCount properties will not be incremented until
+ * the channel is re-enabled.
+ * @param index Index of the channel
+ * @return state
+ * @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;
+ /**
+ * Gets the enabled state on the specified channel. When the channel is disabled, it will no longer register counts. TotalTime and TotalCount properties will not be incremented until
+ * the channel is re-enabled.
+ * @param index Index of the channel
+ * @param state new enabled state
+ * @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;
+ /**
+ * Gets the channel filter mode. This controls the type of signal that the Frequency Counter will respond to - either a zero-centered or a logic-level signal.
+ * <p>
+ * The possible values for type are {@link #PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_ZERO_CROSSING PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_ZERO_CROSSING},
+ * {@link #PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_LOGIC_LEVEL PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_LOGIC_LEVEL}, {@link #PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_UNKNOWN PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_UNKNOWN}
+ * <p>
+ * @param index Index of the channel
+ * @return filter type
+ * @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 getFilter (int index) throws PhidgetException;
+ /**
+ * Sets the channel filter mode. This controls the type of signal that the Frequency Counter will respond to - either a zero-centered or a logic-level signal.
+ * <p>
+ * The possible values for type are {@link #PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_ZERO_CROSSING PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_ZERO_CROSSING},
+ * {@link #PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_LOGIC_LEVEL PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_LOGIC_LEVEL}, {@link #PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_UNKNOWN PHIDGET_FREQUENCYCOUNTER_FILTERTYPE_UNKNOWN}
+ * <p>
+ * @param index Index of the channel
+ * @param type new filter type
+ * @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 setFilter (int index, int type) throws PhidgetException;
+ /**
+ * Resets the {@link #getTotalCount(int) getTotalCount} and {@link #getTotalTime(int) getTotalTime} counters to 0 for the specified channel. For best performance, this should be called when the channel is disabled.
+ * @param index Index of the channel
+ * @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 reset (int index) throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableFrequencyCounterCountEvents (b && frequencyCounterCountListeners.size () > 0);
+ }
+ /**
+ * Adds a count listener. The count handler is a method that will be called whenever some counts have been detected.
+ * This event will fire up to 31.25 times a second, depending on the pulse rate. The time is in microseconds and represents the amount
+ * of time in which the number of counts occured. This event can be used to calculate frequency independently of the phidget21 library frequency implementation.
+ * This event will fire with a count of 0 once, after the Timeout time has elapsed with no counts for a channel, to indicate 0 Hz.
+ * <p>
+ * There is no limit on the number of count handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.FrequencyCounterCountListener FrequencyCounterCountListener} interface
+ */
+ public final void addFrequencyCounterCountListener (FrequencyCounterCountListener l)
+ {
+ synchronized (frequencyCounterCountListeners)
+ {
+ frequencyCounterCountListeners.add (l);
+ enableFrequencyCounterCountEvents (true);
+ }} private LinkedList frequencyCounterCountListeners = new LinkedList ();
+ private long nativeFrequencyCounterCountHandler = 0;
+ public final void removeFrequencyCounterCountListener (FrequencyCounterCountListener l)
+ {
+ synchronized (frequencyCounterCountListeners)
+ {
+ frequencyCounterCountListeners.remove (l);
+ enableFrequencyCounterCountEvents (frequencyCounterCountListeners.size () > 0);
+ }} private void fireFrequencyCounterCount (FrequencyCounterCountEvent e)
+ {
+ synchronized (frequencyCounterCountListeners)
+ {
+ for (Iterator it = frequencyCounterCountListeners.iterator (); it.hasNext ();)
+ ((FrequencyCounterCountListener) it.next ()).frequencyCounterCounted (e);
+ }
+ }
+ private native void enableFrequencyCounterCountEvents (boolean b);
+}
diff --git a/Java/com/phidgets/GPSPhidget.java b/Java/com/phidgets/GPSPhidget.java
new file mode 100644
index 0000000..dde1400
--- /dev/null
+++ b/Java/com/phidgets/GPSPhidget.java
@@ -0,0 +1,151 @@
+
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets;
+import java.util.Iterator;
+import java.util.LinkedList;
+import com.phidgets.event.*;
+import java.util.Calendar;
+ /**
+ * This class represents a Phidget GPS. All methods
+ * to manipulate the Phidget GPS are implemented in this class.
+ * <p>
+ *
+ * @author Phidgets Inc.
+ */
+public final class GPSPhidget extends Phidget
+{
+ public GPSPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+
+ /**
+ * Returns the current latitude, in signed degrees format.
+ * @return Current latitude, in signed degrees format.
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the GPS is not plugged into the board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ * If the latitude is not available, an EPHIDGET_UNKNOWNVAL exception is thrown.
+ */
+ public native double getLatitude () throws PhidgetException;
+ /**
+ * Returns the current longitude, in signed degrees format.
+ * @return Current longitude, in signed degrees format.
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the GPS is not plugged into the board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ * If the longitude is not available, an EPHIDGET_UNKNOWNVAL exception is thrown.
+ */
+ public native double getLongitude () throws PhidgetException;
+ /**
+ * Returns the current altitude, in meters.
+ * @return Current altitude, in meters.
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the GPS is not plugged into the board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ * If the altitude is not available, an EPHIDGET_UNKNOWNVAL exception is thrown.
+ */
+ public native double getAltitude () throws PhidgetException;
+ /**
+ * Returns the current heading, in degrees - compass bearing format. Heading is only accurate if the GPS is moving, and it represents
+ * a heading over time, and not the actual direction the PhidgetGPS is pointing.
+ * exception is thrown.
+ * @return Heading in degrees(compass bearing format).
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the GPS is not plugged into the board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ * If the heading is not available, an EPHIDGET_UNKNOWNVAL.
+ */
+ public native double getHeading () throws PhidgetException;
+ /**
+ * Returns the current velocity, in km/h. Velocity is only accurate if the PhidgetGPS is moving.
+ * @return Velocity in km/h.
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the GPS is not plugged into the board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ * If the velocity is not available, an EPHIDGET_UNKNOWNVAL exception is thrown.
+ */
+ public native double getVelocity () throws PhidgetException;
+ /**
+ * Returns the current GPS date and time, in UTC. The time is updated 10 times a second and is accurate to within at least 500ms when {@link #getPositionFixStatus getPositionFixStatus} is true.
+ * @return Current GPS date and time.
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the GPS is not plugged into the board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ * If the date or time are not available, an EPHIDGET_UNKNOWNVAL exception is thrown.
+ */
+ public native Calendar getDateAndTime () throws PhidgetException;
+ /**
+ * Returns the current position fix status. If true, all of the above properties will be available. Time and date may or may not be available, but they can only be trusted
+ * as accurate when the PositionFixStatus is true.
+ * @return Current position fix status.
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the GPS is not plugged into the board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ * If false, the {@link #getHeading getHeading} / {@link #getVelocity getVelocity} will throw an EPHIDGET_UNKNOWN exception.
+ */
+ public native boolean getPositionFixStatus () throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableGPSPositionFixStatusChangeEvents (b && gpsPositionFixStatusChangeListeners.size () > 0);
+ enableGPSPositionChangeEvents (b && gpsPositionChangeListeners.size () > 0);
+ }
+ /**
+ * Adds a position fix status change listener. The position fix status change handler is a method that will be called when the position fix status changes.
+ * <p>
+ * There is no limit on the number of position fix status change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.GPSPositionFixStatusChangeListener GPSPositionFixStatusChangeListener} interface
+ */
+ public final void addGPSPositionFixStatusChangeListener (GPSPositionFixStatusChangeListener l)
+ {
+ synchronized (gpsPositionFixStatusChangeListeners)
+ {
+ gpsPositionFixStatusChangeListeners.add (l);
+ enableGPSPositionFixStatusChangeEvents (true);
+ }} private LinkedList gpsPositionFixStatusChangeListeners = new LinkedList ();
+ private long nativeGPSPositionFixStatusChangeHandler = 0;
+ public final void removeGPSPositionFixStatusChangeListener (GPSPositionFixStatusChangeListener l)
+ {
+ synchronized (gpsPositionFixStatusChangeListeners)
+ {
+ gpsPositionFixStatusChangeListeners.remove (l);
+ enableGPSPositionFixStatusChangeEvents (gpsPositionFixStatusChangeListeners.size () > 0);
+ }} private void fireGPSPositionFixStatusChange (GPSPositionFixStatusChangeEvent e)
+ {
+ synchronized (gpsPositionFixStatusChangeListeners)
+ {
+ for (Iterator it = gpsPositionFixStatusChangeListeners.iterator (); it.hasNext ();)
+ ((GPSPositionFixStatusChangeListener) it.next ()).gpsPositionFixStatusChanged (e);
+ }
+ }
+ private native void enableGPSPositionFixStatusChangeEvents (boolean b);
+ /**
+ * Adds a position change listener. The position change handler is a method that will be called when the position changes.
+ * <p>
+ * There is no limit on the number of position change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.GPSPositionChangeListener GPSPositionChangeListener} interface
+ */
+ public final void addGPSPositionChangeListener (GPSPositionChangeListener l)
+ {
+ synchronized (gpsPositionChangeListeners)
+ {
+ gpsPositionChangeListeners.add (l);
+ enableGPSPositionChangeEvents (true);
+ }} private LinkedList gpsPositionChangeListeners = new LinkedList ();
+ private long nativeGPSPositionChangeHandler = 0;
+ public final void removeGPSPositionChangeListener (GPSPositionChangeListener l)
+ {
+ synchronized (gpsPositionChangeListeners)
+ {
+ gpsPositionChangeListeners.remove (l);
+ enableGPSPositionChangeEvents (gpsPositionChangeListeners.size () > 0);
+ }} private void fireGPSPositionChange (GPSPositionChangeEvent e)
+ {
+ synchronized (gpsPositionChangeListeners)
+ {
+ for (Iterator it = gpsPositionChangeListeners.iterator (); it.hasNext ();)
+ ((GPSPositionChangeListener) it.next ()).gpsPositionChanged (e);
+ }
+ }
+ private native void enableGPSPositionChangeEvents (boolean b);
+}
diff --git a/Java/com/phidgets/IRCode.java b/Java/com/phidgets/IRCode.java
new file mode 100644
index 0000000..51b014c
--- /dev/null
+++ b/Java/com/phidgets/IRCode.java
@@ -0,0 +1,93 @@
+
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets;
+/**
+ * This class represents an IR Code.
+ *
+ * @author Phidget Inc.
+ */
+public final class IRCode
+{
+ private short[] data;
+ /**
+ * IR code data. This is MSB first, right justified. This is really an (unsigned) Byte array,
+ * so values range from 0-255. We have to use shorts because Java doesn't support unsigned types.
+ */
+ public short[] getData()
+ {
+ return data;
+ }
+ private int bitCount;
+ /**
+ * Data bits. This is important because many codes use a number of bits that doesn't line up with byte (8-bit) borders.
+ */
+ public int getBitCount()
+ {
+ return bitCount;
+ }
+
+ /**
+ * Creates a new IR Code from a string.
+ * @param code the IR code
+ * @param bitCount the code length in bits.
+ */
+ public IRCode(String code, int bitCount)
+ {
+ this.data = HexToData(code);
+ this.bitCount = bitCount;
+ }
+
+ /**
+ * Creates a new IR Code from a data array.
+ * @param data the IR code data
+ * @param bitCount the code length in bits.
+ */
+ public IRCode(short[] data, int bitCount)
+ {
+ int length = (bitCount / 8) + ((bitCount % 8 > 0) ? 1 : 0);
+
+ this.data = new short[length];
+ for (int i = 0; i < length; i++)
+ this.data[i] = data[i];
+
+ this.bitCount = bitCount;
+ }
+
+ private short[] HexToData(String hexString)
+ {
+ if (hexString == null)
+ return null;
+
+ if (hexString.startsWith("0x")){
+ hexString = hexString.substring(2);
+ }
+
+ if (hexString.length() % 2 == 1)
+ hexString = '0' + hexString; // Up to you whether to pad the first or last byte
+
+ short[] data = new short[hexString.length() / 2];
+
+ for (int i = 0; i < data.length; i++){
+ data[i] = (short) Integer.parseInt(hexString.substring(i * 2, (i * 2) + 2), 16);
+ }
+
+ return data;
+ }
+ private char[] hexlookup = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
+ /**
+ * String representation of the IR code.
+ */
+ public String toString()
+ {
+ String out = "";
+ for(int i=0;i<data.length;i++)
+ {
+ out = out + (hexlookup[data[i] / 16]);
+ out = out + (hexlookup[data[i] % 16]);
+ }
+ return out;
+ }
+}
diff --git a/Java/com/phidgets/IRCodeInfo.java b/Java/com/phidgets/IRCodeInfo.java
new file mode 100644
index 0000000..8c67b10
--- /dev/null
+++ b/Java/com/phidgets/IRCodeInfo.java
@@ -0,0 +1,360 @@
+
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets;
+/**
+ * This class represents IR Code Properties needed for transmit.
+ *
+ * @author Phidget Inc.
+ */
+public final class IRCodeInfo
+{
+ /**
+ * Unknown encoding. This is used with {@link #getEncoding getEncoding}
+ */
+ public static final int ENCODING_UNKNOWN = 1;
+ /**
+ * Space encoding. This is used with {@link #getEncoding getEncoding}
+ */
+ public static final int ENCODING_SPACE = 2;
+ /**
+ * Pulse encoding. This is used with {@link #getEncoding getEncoding}
+ */
+ public static final int ENCODING_PULSE = 3;
+ /**
+ * BiPhase encoding. This is used with {@link #getEncoding getEncoding}
+ */
+ public static final int ENCODING_BIPHASE = 4;
+ /**
+ * RC5 encoding. This is used with {@link #getEncoding getEncoding}
+ */
+ public static final int ENCODING_RC5 = 5;
+ /**
+ * RC6 encoding. This is used with {@link #getEncoding getEncoding}
+ */
+ public static final int ENCODING_RC6 = 6;
+
+ /**
+ * Unknown length. This is used with {@link #getLength getLength}
+ */
+ public static final int LENGTH_UNKNOWN = 1;
+ /**
+ * Constant length. This is used with {@link #getLength getLength}
+ */
+ public static final int LENGTH_CONSTANT = 2;
+ /**
+ * Variable length. This is used with {@link #getLength getLength}
+ */
+ public static final int LENGTH_VARIABLE = 3;
+
+ private int encoding=ENCODING_UNKNOWN, length=LENGTH_UNKNOWN, bitCount=0, gap=0, trail=0, minRepeat=1, carrierFrequency=38000, dutyCycle=33;
+ private int[] header=null, one=new int[] {0,0}, zero=new int[] {0,0}, repeat=null;
+ private IRCode toggleMask=null;
+
+ /**
+ * Creates a new IR Code Info object.
+ * @param bitCount the bit count
+ */
+ public IRCodeInfo(int bitCount) throws PhidgetException
+ {
+ this.bitCount = bitCount;
+ }
+
+ /**
+ * Creates a new IR Code Info object.
+ * @param encoding the encoding - one of {@link #ENCODING_SPACE ENCODING_SPACE},
+ * {@link #ENCODING_PULSE ENCODING_PULSE}, {@link #ENCODING_BIPHASE ENCODING_BIPHASE},
+ * {@link #ENCODING_RC5 ENCODING_RC5} or {@link #ENCODING_RC6 ENCODING_RC6}
+ * @param bitCount the bit count
+ */
+ public IRCodeInfo(int encoding, int bitCount) throws PhidgetException
+ {
+ this.encoding = encoding;
+ this.bitCount = bitCount;
+ }
+
+ /**
+ * Creates a new IR Code Info object.
+ * @param encoding the encoding - one of {@link #ENCODING_SPACE ENCODING_SPACE},
+ * {@link #ENCODING_PULSE ENCODING_PULSE}, {@link #ENCODING_BIPHASE ENCODING_BIPHASE},
+ * {@link #ENCODING_RC5 ENCODING_RC5} or {@link #ENCODING_RC6 ENCODING_RC6}
+ * @param bitCount the bit count
+ * @param header the header (pulse,space)
+ * @param zero the zero (pulse, space)
+ * @param one the one (pulse, space)
+ * @param trail the trailing pulse
+ * @param gap the trailing gap
+ */
+ public IRCodeInfo(int encoding, int bitCount, int[] header, int[] zero, int[] one, int trail, int gap) throws PhidgetException
+ {
+ this.encoding = encoding;
+ this.bitCount = bitCount;
+
+ if(header != null)
+ {
+ if(header.length != 2)
+ throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "header must have 2 elements");
+ this.header = new int[] { header[0], header[1] };
+ }
+
+ if(zero==null || zero.length != 2)
+ throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "zero must have 2 elements");
+ this.zero = new int[] { zero[0], zero[1] };
+
+ if(one==null || one.length != 2)
+ throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "one must have 2 elements");
+ this.one = new int[] { one[0], one[1] };
+
+ this.trail = trail;
+ this.gap = gap;
+ }
+
+ /**
+ * Creates a new IR Code Info object.
+ * @param encoding the encoding - one of {@link #ENCODING_SPACE ENCODING_SPACE},
+ * {@link #ENCODING_PULSE ENCODING_PULSE}, {@link #ENCODING_BIPHASE ENCODING_BIPHASE},
+ * {@link #ENCODING_RC5 ENCODING_RC5} or {@link #ENCODING_RC6 ENCODING_RC6}
+ * @param bitCount the bit count
+ * @param header the header (pulse,space)
+ * @param zero the zero (pulse, space)
+ * @param one the one (pulse, space)
+ * @param trail the trailing pulse
+ * @param gap the trailing gap
+ * @param repeat the special repeat code
+ */
+ public IRCodeInfo(int encoding, int bitCount, int[] header, int[] zero, int[] one, int trail, int gap, int[] repeat) throws PhidgetException
+ {
+ this.encoding = encoding;
+ this.bitCount = bitCount;
+
+ if(header != null)
+ {
+ if(header.length != 2)
+ throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "header must have 2 elements");
+ this.header = new int[] { header[0], header[1] };
+ }
+
+ if(zero==null || zero.length != 2)
+ throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "zero must have 2 elements");
+ this.zero = new int[] { zero[0], zero[1] };
+
+ if(one==null || one.length != 2)
+ throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "one must have 2 elements");
+ this.one = new int[] { one[0], one[1] };
+
+ this.trail = trail;
+ this.gap = gap;
+
+ if(repeat != null)
+ {
+ this.repeat = new int[repeat.length];
+ for(int i=0; i<repeat.length; i++)
+ this.repeat[i] = repeat[i];
+ }
+ }
+
+ /**
+ * Creates a new IR Code Info object.
+ * @param encoding the encoding - one of {@link #ENCODING_SPACE ENCODING_SPACE},
+ * {@link #ENCODING_PULSE ENCODING_PULSE}, {@link #ENCODING_BIPHASE ENCODING_BIPHASE},
+ * {@link #ENCODING_RC5 ENCODING_RC5} or {@link #ENCODING_RC6 ENCODING_RC6}
+ * @param bitCount the bit count
+ * @param header the header (pulse,space)
+ * @param zero the zero (pulse, space)
+ * @param one the one (pulse, space)
+ * @param trail the trailing pulse
+ * @param gap the trailing gap
+ * @param repeat the special repeat code
+ * @param minRepeat the minimum number of times to repeat the code
+ * @param toggleMask the bits to toggle when minRepeat is > 1
+ * @param length the length style - one of {@link #LENGTH_CONSTANT LENGTH_CONSTANT} or {@link #LENGTH_VARIABLE LENGTH_VARIABLE}
+ * @param carrierFrequency the carrier frequency in kHz
+ * @param dutyCycle the duty cycle in percent
+ */
+ public IRCodeInfo(
+ int encoding,
+ int bitCount,
+ int[] header,
+ int[] zero,
+ int[] one,
+ int trail,
+ int gap,
+ int[] repeat,
+ int minRepeat,
+ IRCode toggleMask,
+ int length,
+ int carrierFrequency,
+ int dutyCycle) throws PhidgetException
+ {
+ this.encoding = encoding;
+ this.bitCount = bitCount;
+
+ if(header != null)
+ {
+ if(header.length != 2)
+ throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "header must have 2 elements");
+ this.header = new int[] { header[0], header[1] };
+ }
+
+ if(zero==null || zero.length != 2)
+ throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "zero must have 2 elements");
+ this.zero = new int[] { zero[0], zero[1] };
+
+ if(one==null || one.length != 2)
+ throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "one must have 2 elements");
+ this.one = new int[] { one[0], one[1] };
+
+ this.trail = trail;
+ this.gap = gap;
+
+ if(repeat != null)
+ {
+ this.repeat = new int[repeat.length];
+ for(int i=0; i<repeat.length; i++)
+ this.repeat[i] = repeat[i];
+ }
+
+ this.minRepeat = minRepeat;
+
+ if(toggleMask != null)
+ toggleMask = new IRCode(toggleMask.getData(), toggleMask.getBitCount());
+
+ this.length = length;
+ this.carrierFrequency = carrierFrequency;
+ this.dutyCycle = dutyCycle;
+ }
+
+ /**
+ * Returns the encoding.
+ * @return encoding
+ */
+ public int getEncoding()
+ {
+ return encoding;
+ }
+ /**
+ * Returns the length style.
+ * @return length style
+ */
+ public int getLength()
+ {
+ return length;
+ }
+ /**
+ * Returns the bit count.
+ * @return bit count
+ */
+ public int getBitCount()
+ {
+ return bitCount;
+ }
+ /**
+ * Returns the gap.
+ * @return gap
+ */
+ public int getGap()
+ {
+ return gap;
+ }
+ /**
+ * Returns the trail.
+ * @return trail
+ */
+ public int getTrail()
+ {
+ return trail;
+ }
+ /**
+ * Returns the min repeat.
+ * @return min repeat
+ */
+ public int getMinRepeat()
+ {
+ return minRepeat;
+ }
+ /**
+ * Returns the carrier frequency.
+ * @return carrier frequency
+ */
+ public int getCarrierFrequency()
+ {
+ return carrierFrequency;
+ }
+ /**
+ * Returns the duty cycle.
+ * @return duty cycle
+ */
+ public int getDutyCycle()
+ {
+ return dutyCycle;
+ }
+ /**
+ * Returns the header.
+ * @return header
+ */
+ public int[] getHeader()
+ {
+ return header;
+ }
+ /**
+ * Returns the zero.
+ * @return zero
+ */
+ public int[] getZero()
+ {
+ return zero;
+ }
+ /**
+ * Returns the one.
+ * @return one
+ */
+ public int[] getOne()
+ {
+ return one;
+ }
+ /**
+ * Returns the repeat code.
+ * @return repeat code
+ */
+ public int[] getRepeat()
+ {
+ return repeat;
+ }
+ /**
+ * Returns the toggle mask.
+ * @return toggle mask
+ */
+ public IRCode getToggleMask()
+ {
+ return toggleMask;
+ }
+
+
+ public String toString()
+ {
+ String out = "";
+ out = out + " Encoding: " + encoding + "\n";
+ out = out + " Zero: " + zero[0] + ", " + zero[1] + "\n";
+ out = out + " One: " + one[0] + ", " + one[1] + "\n";
+ if (header != null)
+ {
+ if (header[0] != 0)
+ out = out + " Header: " + header[0] + ", " + header[1] + "\n";
+ }
+
+ if (trail != 0)
+ out = out + " Trail: " + trail + "\n";
+ if (gap != 0)
+ out = out + " Gap: " + gap + "\n";
+ if (repeat != null)
+ {
+ out = out + " Repeat: ";
+ for(int i=0;i<repeat.length;i++)
+ out = out + repeat[i] + ", ";
+ out = out + "\n";
+ }
+ return out;
+ }
+}
diff --git a/Java/com/phidgets/IRLearnedCode.java b/Java/com/phidgets/IRLearnedCode.java
new file mode 100644
index 0000000..4949d07
--- /dev/null
+++ b/Java/com/phidgets/IRLearnedCode.java
@@ -0,0 +1,51 @@
+
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets;
+/**
+ * This class represents an IR Learned Code. This is used in the Learn event.
+ *
+ * @author Phidget Inc.
+ */
+public final class IRLearnedCode
+{
+ private IRCode code;
+ private IRCodeInfo codeInfo;
+
+ /**
+ * Creates a new IR Learned Code. This is used in the Learn event.
+ * @param code the IR code
+ * @param codeInfo the code parameters
+ */
+ public IRLearnedCode(IRCode code, IRCodeInfo codeInfo)
+ {
+ this.code=code;
+ this.codeInfo=codeInfo;
+ }
+
+ /**
+ * Returns the code.
+ * @return code
+ */
+ public IRCode getCode()
+ {
+ return code;
+ }
+
+ /**
+ * Returns the code parameters.
+ * @return code parameters
+ */
+ public IRCodeInfo getCodeInfo()
+ {
+ return codeInfo;
+ }
+
+ public String toString()
+ {
+ return code.toString() + " (" + code.getBitCount() + "-bit)\n" + codeInfo.toString();
+ }
+}
+
diff --git a/Java/com/phidgets/IRPhidget.java b/Java/com/phidgets/IRPhidget.java
new file mode 100644
index 0000000..8418d74
--- /dev/null
+++ b/Java/com/phidgets/IRPhidget.java
@@ -0,0 +1,239 @@
+
+/*
+ * Copyright 2010 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 IR. All methods
+ * to send and receive IR data are implemented in this class.
+ * <p>
+ * The Phidget IR Receiver-Transmitter can send and receive Consumer-IR signals. Ability to learn and re-transmit codes,
+ * as well as low-level access to raw data, is provided.
+ *
+ * @author Phidgets Inc.
+ */
+public final class IRPhidget extends Phidget
+{
+ public IRPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+
+ /**
+ * Represents a long space (greater then 327,670 microseconds) in raw data.
+ * This can be considered a period of no IR activity. This is used with {@link #readRaw readRaw}
+ */
+ public static final int RAWDATA_LONGSPACE = 0x7fffffff;
+
+ /**
+ * Transmits a code.
+ * @param code the code to transmit
+ * @param codeInfo the code specification
+ * @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 void transmit (IRCode code, IRCodeInfo codeInfo) throws PhidgetException;
+ /**
+ * Transmits a repeat. This needs to be called within the gap time of a transmit to be meaningful.
+ * @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 void transmitRepeat () throws PhidgetException;
+ /**
+ * Transmits raw data.
+ * @param data data in microseconds, must start and end with a pulse
+ * @param offset offset in the data array to start transmitting
+ * @param count number of elements of data to transmit
+ * @param gap gap size in microseconds
+ * @param carrierFrequency carrier frequency in kHz
+ * @param dutyCycle duty cycle in percent
+ * @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 void transmitRaw (int[]data, int offset, int count, int gap, int carrierFrequency, int dutyCycle) throws PhidgetException;
+ /**
+ * Transmits raw data.
+ * @param data data in microseconds, must start and end with a pulse
+ * @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 final void transmitRaw (int[]data) throws PhidgetException
+ {
+ transmitRaw (data, 0, data.length, 0, 0, 0);
+ }
+ /**
+ * Transmits raw data.
+ * @param data data in microseconds, must start and end with a pulse
+ * @param gap gap size in microseconds
+ * @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 final void transmitRaw (int[]data, int gap) throws PhidgetException
+ {
+ transmitRaw (data, 0, data.length, gap, 0, 0);
+ }
+ /**
+ * Transmits raw data.
+ * @param data data in microseconds, must start and end with a pulse
+ * @param offset offset in the data array to start transmitting
+ * @param count number of elements of data to transmit
+ * @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 final void transmitRaw (int[]data, int offset, int count) throws PhidgetException
+ {
+ transmitRaw (data, offset, count, 0, 0, 0);
+ }
+ /**
+ * Transmits raw data.
+ * @param data data in microseconds, must start and end with a pulse
+ * @param offset offset in the data array to start transmitting
+ * @param count number of elements of data to transmit
+ * @param gap gap size in microseconds
+ * @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 final void transmitRaw (int[]data, int offset, int count, int gap) throws PhidgetException
+ {
+ transmitRaw (data, offset, count, gap, 0, 0);
+ }
+ /**
+ * Reads raw data. Use {@link #RAWDATA_LONGSPACE RAWDATA_LONGSPACE} to detect gaps in IR data.
+ * @param buffer array into which data will be read.
+ * @param offset offset in data to start writing
+ * @param count maximum ammount of data to read
+ * @return ammount of data read
+ * @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 readRaw (int[]buffer, int offset, int count) throws PhidgetException;
+ /**
+ * Reads raw data. Use {@link #RAWDATA_LONGSPACE RAWDATA_LONGSPACE} to detect gaps in IR data.
+ * @param buffer array into which data will be read.
+ * @return ammount of data read
+ * @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 final int readRaw (int[]buffer) throws PhidgetException
+ {
+ return readRaw (buffer, 0, buffer.length);
+ }
+ /**
+ * Returns the last recieved code. This is updated right after the code event returns.
+ * @return last code
+ * @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 IRCode getLastCode () throws PhidgetException;
+ /**
+ * Returns the last learned code. This is updated right after the learn event returns.
+ * @return last learned code
+ * @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 IRLearnedCode getLastLearnedCode () throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableCodeEvents (b && codeListeners.size () > 0);
+ enableLearnEvents (b && learnListeners.size () > 0);
+ enableRawDataEvents (b && rawDataListeners.size () > 0);
+ }
+ /**
+ * Adds a code listener. The code handler is a method that will be called when a new code is
+ seen by the reader. The event is fired on each code, including repetitions.
+ * <p>
+ * There is no limit on the number of code handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.CodeListener CodeListener} interface
+ */
+ public final void addCodeListener (CodeListener l)
+ {
+ synchronized (codeListeners)
+ {
+ codeListeners.add (l);
+ enableCodeEvents (true);
+ }} private LinkedList codeListeners = new LinkedList ();
+ private long nativeCodeHandler = 0;
+ public final void removeCodeListener (CodeListener l)
+ {
+ synchronized (codeListeners)
+ {
+ codeListeners.remove (l);
+ enableCodeEvents (codeListeners.size () > 0);
+ }} private void fireCode (CodeEvent e)
+ {
+ synchronized (codeListeners)
+ {
+ for (Iterator it = codeListeners.iterator (); it.hasNext ();)
+ ((CodeListener) it.next ()).code (e);
+ }
+ }
+ private native void enableCodeEvents (boolean b);
+ /**
+ * Adds a code learn listener. The learn handler is a method that will be called when a new code is
+ learned by the reader. This requires that the code be repeated several times.
+ * <p>
+ * There is no limit on the number of learn handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.LearnListener LearnListener} interface
+ */
+ public final void addLearnListener (LearnListener l)
+ {
+ synchronized (learnListeners)
+ {
+ learnListeners.add (l);
+ enableLearnEvents (true);
+ }} private LinkedList learnListeners = new LinkedList ();
+ private long nativeLearnHandler = 0;
+ public final void removeLearnListener (LearnListener l)
+ {
+ synchronized (learnListeners)
+ {
+ learnListeners.remove (l);
+ enableLearnEvents (learnListeners.size () > 0);
+ }} private void fireLearn (LearnEvent e)
+ {
+ synchronized (learnListeners)
+ {
+ for (Iterator it = learnListeners.iterator (); it.hasNext ();)
+ ((LearnListener) it.next ()).learn (e);
+ }
+ }
+ private native void enableLearnEvents (boolean b);
+ /**
+ * Adds a rawData listener. The rawData handler is a method that will be called when a raw IR data is recieved.
+ * <p>
+ * There is no limit on the number of rawData handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.RawDataListener RawDataListener} interface
+ */
+ public final void addRawDataListener (RawDataListener l)
+ {
+ synchronized (rawDataListeners)
+ {
+ rawDataListeners.add (l);
+ enableRawDataEvents (true);
+ }} private LinkedList rawDataListeners = new LinkedList ();
+ private long nativeRawDataHandler = 0;
+ public final void removeRawDataListener (RawDataListener l)
+ {
+ synchronized (rawDataListeners)
+ {
+ rawDataListeners.remove (l);
+ enableRawDataEvents (rawDataListeners.size () > 0);
+ }} private void fireRawData (RawDataEvent e)
+ {
+ synchronized (rawDataListeners)
+ {
+ for (Iterator it = rawDataListeners.iterator (); it.hasNext ();)
+ ((RawDataListener) it.next ()).rawData (e);
+ }
+ }
+ private native void enableRawDataEvents (boolean b);
+}
diff --git a/Java/com/phidgets/InterfaceKitPhidget.java b/Java/com/phidgets/InterfaceKitPhidget.java
new file mode 100644
index 0000000..d7aed29
--- /dev/null
+++ b/Java/com/phidgets/InterfaceKitPhidget.java
@@ -0,0 +1,346 @@
+/*
+ * Copyright 2006 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 Interface Kit. All methods
+ * to read and write data to and from an Interface Kit are implemented in this class.
+ * <p>
+ * There are many types of Interface Kits, but each is simply a collection of 0 or more
+ * digital inputs, digital outpus and analog sensors. Inputs can be read and outputs can be set,
+ * and event handlers can be set for each of these.
+ * <p>
+ * See your hardware documentation for more information on the I/O specific to your Phidget.
+ *
+ * @author Phidgets Inc.
+ */
+public final class InterfaceKitPhidget extends Phidget
+{
+ /**
+ * Class Constructor. Calling this opens a connection to the phidget21 C library creates
+ * an internal handle for this Phidget, ready to call open on.
+ *
+ * @throws PhidgetException If there was a problem connecting to phidget21 or creating
+ * the internal handle.
+ */
+ public InterfaceKitPhidget() throws PhidgetException {
+ super(create());
+ }
+
+ private static native long create() throws PhidgetException;
+
+ /**
+ * Returns the number of digital outputs on this Interface Kit. Not all interface kits
+ * have the same number of digital outputs, and some don't have any digital outputs at all.
+ *
+ * @return Number of digital outputs
+ * @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 getOutputCount() throws PhidgetException;
+
+ /**
+ * Returns the number of ditigal inputs on this Interface Kit. Not all interface kits
+ * have the same number of digital inputs, and some don't have any digital inputs at all.
+ *
+ * @return Number of digital inputs
+ * @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 getInputCount() throws PhidgetException;
+
+ /**
+ * Returns the number of analog inputs on the Interface Kit. Not all interface kits
+ * have the same number of analog inputs, and some don't have any analog inputs at all.
+ *
+ * @return Number of analog inputs
+ * @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 getSensorCount() throws PhidgetException;
+
+ /**
+ * Returns the minimum data rate for a sensor, in milliseconds.
+ *
+ * @param index Index of the input
+ * @return minimum data rate
+ * @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 int getDataRateMin(int index) throws PhidgetException;
+
+ /**
+ * Returns the maximum data rate for a sensor, in milliseconds.
+ *
+ * @param index Index of the input
+ * @return maximum data rate
+ * @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 int getDataRateMax(int index) throws PhidgetException;
+
+ /**
+ * Returns the state of a digital input. Digital inputs read True where they are activated and false
+ * when they are in their default state.
+ * <p>
+ * Be sure to check {@link #getInputCount() getInputCount} first if you are unsure as to the number of inputs, so as not to
+ * set an Index that is out of range.
+ *
+ * @param index Index of the input
+ * @return State of the input
+ * @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 boolean getInputState(int index) throws PhidgetException;
+
+ /**
+ * Returns the state of a digital output. Depending on the Phidget, this value may be either the value that you last
+ * wrote out to the Phidget, or the value that the Phidget last returned. This is because some Phidgets return their output state
+ * and others do not. This means that with some devices, reading the output
+ * state of a pin directly after setting it, may not return the value that you just set.
+ * <p>
+ * Be sure to check {@link #getOutputCount() getOutputCount} first if you are unsure as to the number of outputs, so as not to
+ * attempt to get an Index that is out of range.
+ *
+ * @param index Index of the output
+ * @return State of the output
+ * @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 boolean getOutputState(int index) throws PhidgetException;
+
+ /**
+ * Returns the value of a analog input.
+ * The analog inputs are where analog sensors are attached on the InterfaceKit 8/8/8.
+ * On the Linear and Circular touch sensor Phidgets, analog input 0 represents position
+ * on the slider.
+ * <p>
+ * The valid range is 0-1000. In the case of a sensor, this value can be converted to an actual
+ * sensor value using the formulas provided here: http://www.phidgets.com/documentation/Sensors.pdf
+ *
+ * @param index Index of the sensor
+ * @return Sensor 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 int getSensorValue(int index) throws PhidgetException;
+
+ /**
+ * Returns the raw value of a analog input. This is a more accurate version of {@link #getSensorValue(int) getSensorValue}.
+ * The valid range is 0-4095. Note however that the analog outputs on the Interface Kit 8/8/8 are only 10-bit values
+ * and this value represents an oversampling to 12-bit.
+ *
+ * @param index Index of the sensor
+ * @return Sensor 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 int getSensorRawValue(int index) throws PhidgetException;
+
+ /**
+ * Returns the change trigger for an analog input. This is the ammount that an inputs must change
+ * between successive SensorChangeEvents. This is based on the 0-1000 range provided by getSensorValue.
+ * This value is by default set to 10 for most Interface Kits with analog inputs.
+ *
+ * @param index Index of the sensor
+ * @return Trigger 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 int getSensorChangeTrigger(int index)
+ throws PhidgetException;
+
+ /**
+ * Returns the data rate for a sensor, in milliseconds.
+ *
+ * @param index Index of the sensor
+ * @return data rate
+ * @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 int getDataRate(int index)
+ throws PhidgetException;
+
+ /**
+ * Gets the ratiometric state for the analog sensors
+ *
+ * @return state State
+ * @throws PhidgetException If this Phidget is not opened and attached, or if this phidget does not support ratiometric.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native boolean getRatiometric()
+ throws PhidgetException;
+
+ /**
+ * Sets the state of a digital output. Setting this to true will activate the output, False is the default state.
+ *
+ * @param index Index of the output
+ * @param newVal State to set the output to
+ * @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 void setOutputState(int index, boolean newVal)
+ throws PhidgetException;
+
+ /**
+ * Sets the change trigger for an analog input. This is the ammount that an inputs must change
+ * between successive SensorChangeEvents. This is based on the 0-1000 range provided by getSensorValue.
+ * This value is by default set to 10 for most Interface Kits with analog inputs.
+ *
+ * @param index Input
+ * @param newVal 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 void setSensorChangeTrigger(int index, int newVal)
+ throws PhidgetException;
+
+ /**
+ * Sets the data rate of a sensor, in milliseconds.
+ *
+ * @param index Input
+ * @param newVal data rate
+ * @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 void setDataRate(int index, int newVal)
+ throws PhidgetException;
+
+ /**
+ * Sets the ratiometric state for the analog inputs. The default is for ratiometric to be set on and this
+ * is appropriate for most sensors.
+ *
+ * @param state State
+ * @throws PhidgetException If this Phidget is not opened and attached, or if this Phidget does not support ratiometric
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setRatiometric(boolean state)
+ throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents(boolean b) {
+ enableInputChangeEvents(b && inputChangeListeners.size() > 0);
+ enableOutputChangeEvents(b && outputChangeListeners.size() > 0);
+ enableSensorChangeEvents(b && sensorChangeListeners.size() > 0);
+ }
+
+ private LinkedList inputChangeListeners = new LinkedList();
+ private long nativeInputChangeHandler = 0;
+
+ /**
+ * Adds an input change listener. The input change handler is a method that will be called when an input on this
+ * Interface Kit has changed.
+ * <p>
+ * There is no limit on the number of input change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.InputChangeListener InputChangeListener} interface
+ */
+ public final void addInputChangeListener(InputChangeListener l) {
+ synchronized (inputChangeListeners) {
+ inputChangeListeners.add(l);
+ enableInputChangeEvents(true);
+ }
+ }
+
+ /**
+ * Removes an input change listener. This will remove a previously added input change listener.
+ */
+ public final void removeInputChangeListener(InputChangeListener l) {
+ synchronized (inputChangeListeners) {
+ inputChangeListeners.remove(l);
+ enableInputChangeEvents(inputChangeListeners.size() >
+ 0);
+ }
+ }
+ private void fireInputChange(InputChangeEvent e) {
+ synchronized (inputChangeListeners) {
+ for (Iterator it = inputChangeListeners.iterator();
+ it.hasNext(); )
+ ((InputChangeListener)it.next()).inputChanged(
+ e);
+ }
+ }
+ private native void enableInputChangeEvents(boolean b);
+
+ private LinkedList outputChangeListeners = new LinkedList();
+ private long nativeOutputChangeHandler = 0;
+
+ /**
+ * Adds an output change listener. The output change handler is a method that will be called when an output on this
+ * Interface Kit has changed.
+ * <p>
+ * There is no limit on the number of output change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.OutputChangeListener OutputChangeListener} interface
+ */
+ public final void addOutputChangeListener(OutputChangeListener l) {
+ synchronized (outputChangeListeners) {
+ outputChangeListeners.add(l);
+ enableOutputChangeEvents(true);
+ }
+ }
+
+ /**
+ * Removes an output change listener. This will remove a previously added output change listener.
+ */
+ public final void removeOutputChangeListener(OutputChangeListener l) {
+ synchronized (outputChangeListeners) {
+ outputChangeListeners.remove(l);
+ enableOutputChangeEvents(outputChangeListeners.size()
+ > 0);
+ }
+ }
+ private void fireOutputChange(OutputChangeEvent e) {
+ synchronized (outputChangeListeners) {
+ for (Iterator it = outputChangeListeners.iterator();
+ it.hasNext(); )
+ ((OutputChangeListener)it.next())
+ .outputChanged(e);
+ }
+ }
+ private native void enableOutputChangeEvents(boolean b);
+
+ private LinkedList sensorChangeListeners = new LinkedList();
+ private long nativeSensorChangeHandler = 0;
+
+ /**
+ * Adds a sensor change listener. The sensor change handler is a method that will be called when a sensor on this
+ * Interface Kit has changed by at least the {@link #getSensorChangeTrigger(int) Trigger} that has been set for this sensor.
+ * <p>
+ * There is no limit on the number of sensor change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.SensorChangeListener SensorChangeListener} interface
+ */
+ public final void addSensorChangeListener(SensorChangeListener l) {
+ synchronized (sensorChangeListeners) {
+ sensorChangeListeners.add(l);
+ enableSensorChangeEvents(true);
+ }
+ }
+
+ /**
+ * Removes a sensor change listener. This will remove a previously added sensor change listener.
+ */
+ public final void removeSensorChangeListener(SensorChangeListener l) {
+ synchronized (sensorChangeListeners) {
+ sensorChangeListeners.remove(l);
+ enableSensorChangeEvents(sensorChangeListeners.size()
+ > 0);
+ }
+ }
+ private void fireSensorChange(SensorChangeEvent e) {
+ synchronized (sensorChangeListeners) {
+ for (Iterator it = sensorChangeListeners.iterator();
+ it.hasNext(); )
+ ((SensorChangeListener)it.next())
+ .sensorChanged(e);
+ }
+ }
+ private native void enableSensorChangeEvents(boolean b);
+}
diff --git a/Java/com/phidgets/LEDPhidget.java b/Java/com/phidgets/LEDPhidget.java
new file mode 100644
index 0000000..77a37e2
--- /dev/null
+++ b/Java/com/phidgets/LEDPhidget.java
@@ -0,0 +1,141 @@
+
+/*
+ * Copyright 2006 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 LED. All methods
+ * to control a Phidget LED are implemented in this class.
+ <p>
+ The Phidget LED is a board that is meant for driving LEDs. Currently, the
+ only available version drives 64 LEDs, but other versions may become available
+ so this number is not absolute.
+ <p>
+ LEDs can be controlled individually, at brightness levels from 0-100.
+ *
+ * @author Phidgets Inc.
+ */
+public final class LEDPhidget extends Phidget
+{
+ public LEDPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+
+ /**
+ * 20mA current limit. This is used with {@link #getCurrentLimit getCurrentLimit} and {@link #setCurrentLimit setCurrentLimit}
+ */
+ public static final int PHIDGET_LED_CURRENT_LIMIT_20mA = 1;
+ /**
+ * 40mA current limit. This is used with {@link #getCurrentLimit getCurrentLimit} and {@link #setCurrentLimit setCurrentLimit}
+ */
+ public static final int PHIDGET_LED_CURRENT_LIMIT_40mA = 2;
+ /**
+ * 60mA current limit. This is used with {@link #getCurrentLimit getCurrentLimit} and {@link #setCurrentLimit setCurrentLimit}
+ */
+ public static final int PHIDGET_LED_CURRENT_LIMIT_60mA = 3;
+ /**
+ * 80mA current limit. This is used with {@link #getCurrentLimit getCurrentLimit} and {@link #setCurrentLimit setCurrentLimit}
+ */
+ public static final int PHIDGET_LED_CURRENT_LIMIT_80mA = 4;
+
+ /**
+ * 1.7V Voltage output. This is used with {@link #getVoltage getVoltage} and {@link #setVoltage setVoltage}
+ */
+ public static final int PHIDGET_LED_VOLTAGE_1_7V = 1;
+ /**
+ * 2.75V Voltage output. This is used with {@link #getVoltage getVoltage} and {@link #setVoltage setVoltage}
+ */
+ public static final int PHIDGET_LED_VOLTAGE_2_75V = 2;
+ /**
+ * 3.9V Voltage output. This is used with {@link #getVoltage getVoltage} and {@link #setVoltage setVoltage}
+ */
+ public static final int PHIDGET_LED_VOLTAGE_3_9V = 3;
+ /**
+ * 5.0V Voltage output. This is used with {@link #getVoltage getVoltage} and {@link #setVoltage setVoltage}
+ */
+ public static final int PHIDGET_LED_VOLTAGE_5_0V = 4;
+
+ /**
+ * Returns the current limit for the all outputs. This is only supported by some PhidgetLEDs - see the product manual.
+ * The possible values for type are {@link #PHIDGET_LED_CURRENT_LIMIT_20mA PHIDGET_LED_CURRENT_LIMIT_20mA},
+ * {@link #PHIDGET_LED_CURRENT_LIMIT_40mA PHIDGET_LED_CURRENT_LIMIT_40mA}, {@link #PHIDGET_LED_CURRENT_LIMIT_60mA PHIDGET_LED_CURRENT_LIMIT_60mA} and
+ * {@link #PHIDGET_LED_CURRENT_LIMIT_80mA PHIDGET_LED_CURRENT_LIMIT_80mA}
+ * @return Current Limit
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is out of range, or if unsupported by this board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native int getCurrentLimit () throws PhidgetException;
+ /**
+ * Sets the current limit for all outputs. This is only supported by some PhidgetLEDs - see the product manual.
+ * <p>
+ * The possible values for type are {@link #PHIDGET_LED_CURRENT_LIMIT_20mA PHIDGET_LED_CURRENT_LIMIT_20mA},
+ * {@link #PHIDGET_LED_CURRENT_LIMIT_40mA PHIDGET_LED_CURRENT_LIMIT_40mA}, {@link #PHIDGET_LED_CURRENT_LIMIT_60mA PHIDGET_LED_CURRENT_LIMIT_60mA} and
+ * {@link #PHIDGET_LED_CURRENT_LIMIT_80mA PHIDGET_LED_CURRENT_LIMIT_80mA}
+ * <p>
+ * By default, currentLimit is set to {@link #PHIDGET_LED_CURRENT_LIMIT_20mA PHIDGET_LED_CURRENT_LIMIT_20mA}.
+ * @param currentLimit Current Limit
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is out of range, or if unsupported by this board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setCurrentLimit (int currentLimit) throws PhidgetException;
+
+ /**
+ * Returns the voltage output for the all outputs. This is only supported by some PhidgetLEDs - see the product manual.
+ * The possible values for type are {@link #PHIDGET_LED_VOLTAGE_1_7V PHIDGET_LED_VOLTAGE_1_7V},
+ * {@link #PHIDGET_LED_VOLTAGE_2_75V PHIDGET_LED_VOLTAGE_2_75V}, {@link #PHIDGET_LED_VOLTAGE_3_9V PHIDGET_LED_VOLTAGE_3_9V} and
+ * {@link #PHIDGET_LED_VOLTAGE_5_0V PHIDGET_LED_VOLTAGE_5_0V}
+ * @return Voltage
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is out of range, or if unsupported by this board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native int getVoltage () throws PhidgetException;
+ /**
+ * Sets the voltage output for all outputs. This is only supported by some PhidgetLEDs - see the product manual.
+ * <p>
+ * The possible values for type are {@link #PHIDGET_LED_VOLTAGE_1_7V PHIDGET_LED_VOLTAGE_1_7V},
+ * {@link #PHIDGET_LED_VOLTAGE_2_75V PHIDGET_LED_VOLTAGE_2_75V}, {@link #PHIDGET_LED_VOLTAGE_3_9V PHIDGET_LED_VOLTAGE_3_9V} and
+ * {@link #PHIDGET_LED_VOLTAGE_5_0V PHIDGET_LED_VOLTAGE_5_0V}
+ * <p>
+ * By default, voltage is set to {@link #PHIDGET_LED_VOLTAGE_2_75V PHIDGET_LED_VOLTAGE_2_75V}.
+ * @param voltage Voltage
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is out of range, or if unsupported by this board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setVoltage (int voltage) throws PhidgetException;
+
+ /**
+ * Returns the number of LEDs that this board can drive. This may not correspond to the actual number
+ of LEDs attached.
+ * @return number of LEDs
+ * @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 getLEDCount () throws PhidgetException;
+ /**
+ * Returns the brightness value of an LED. This value ranges from 0-100.
+ * @param index LED
+ * @return brightness
+ * @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 int getDiscreteLED (int index) throws PhidgetException;
+ /**
+ * Sets the brightness of an LED.
+ * Valid values are 0-100, with 0 being off and 100 being the brightest. This 0-100 value is converted internally to a
+ 6-bit value (0-63) so only 64 levels of brightness are actually possible.
+ * @param index index of the LED
+ * @param brightness desired brightness of this LED
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index of brightness value are out of range.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setDiscreteLED (int index, int brightness) throws PhidgetException;
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ }
+}
diff --git a/Java/com/phidgets/Manager.java b/Java/com/phidgets/Manager.java
new file mode 100644
index 0000000..7e7cafb
--- /dev/null
+++ b/Java/com/phidgets/Manager.java
@@ -0,0 +1,408 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets;
+
+import com.phidgets.event.*;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.Vector;
+
+/**
+ * <p>
+ * This class represents a Phidget Manager.
+ * The Phidget manager is a way to keep track of attached phidgets, it will send
+ * Attach and Detach events as Phidgets are added and removed fromt the system.
+ * <p>
+ * The Phidget manager deals in base Phidget objects. These objects are not actually connected to
+ * opened Phidgets but can be used to get serial number, name, version, etc.
+ *
+ * @author Phidgets Inc.
+ */
+public class Manager
+{
+ private Vector phidgets;
+
+ static
+ {
+ try
+ {
+ System.loadLibrary("phidget21");
+ }
+ catch(UnsatisfiedLinkError ex)
+ {
+ String os = System.getProperty("os.name");
+ if(os.startsWith("Linux"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library (libphidget21.so)."
+ +"\nMake sure it is installed, and add it's path to LD_LIBRARY_PATH.");
+ }
+ else if(os.startsWith("Windows"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library."
+ +"\nThe Windows Phidget21 MSI must be installed.");
+ }
+ else if(os.startsWith("Mac"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library."
+ +"\nThe Mac Phidget21 DMG must be installed.");
+ }
+ else
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library.");
+ }
+ }
+ }
+
+ private long handle = 0;
+ /**
+ * The default constructor. Creating a Phidget Manager object will initialize the
+ * attach and detach handlers internally, but {@link #open() open} still needs to be called
+ * to actually recieve event notifications.
+ */
+ public Manager() throws PhidgetException
+ {
+ handle = create();
+ phidgets = new Vector();
+ addAttachListener(new AttachListener()
+ {
+ public void attached(AttachEvent ae)
+ {
+ phidgets.add(ae.getSource());
+ }
+ });
+ addDetachListener(new DetachListener()
+ {
+ public void detached(DetachEvent ae)
+ {
+ phidgets.remove(ae.getSource());
+ }
+ });
+ }
+ private final native long create() throws PhidgetException;
+
+ /**
+ * Returns the Address of a Phidget Webservice when this Manager was opened as remote. This may be an IP Address or a hostname.
+ *
+ * @return Server Address
+ * @throws PhidgetException if this Manager was not opened.
+ */
+ public final native String getServerAddress() throws PhidgetException;
+ /**
+ * Returns the Server ID of a Phidget Webservice when this Manager was opened as remote. This is an arbitrary server identifier,
+ * independant of IP address and Port.
+ *
+ * @return Server ID
+ * @throws PhidgetException if this Manager was not opened.
+ */
+ public final native String getServerID() throws PhidgetException;
+ /**
+ * Returns the Port of a Phidget Webservice when this Manager was opened as remote.
+ *
+ * @return Server Port
+ * @throws PhidgetException if this Manager was not opened.
+ */
+ public final native int getServerPort() throws PhidgetException;
+ /**
+ * Returns the attached status of this Manager.
+ *
+ * @return Status
+ * @throws PhidgetException If this Manager is not opened.
+ */
+ public final native boolean isAttached() throws PhidgetException;
+
+ /**
+ * Returns the network attached status for remotely opened Phidgets. This method returns True or False, depending on whether a connection to the
+ * Phidget WebService is open - or not. If this is false for a remote Phidget then the connection is not active - either because a connection
+ * has not yet been established, or because the connection was terminated.
+ *
+ * @return Status
+ * @throws PhidgetException If this Phidget is not opened.
+ */
+ public final native boolean isAttachedToServer() throws PhidgetException;
+
+ private final native void nativeClose() throws PhidgetException;
+ private final native void nativeDelete() throws PhidgetException;
+ private final native void nativeOpen() throws PhidgetException;
+ private final native void nativeOpenRemote(String serverID, String pass) throws PhidgetException;
+ private final native void nativeOpenRemoteIP(String ipAddress, int port, String pass) throws PhidgetException;
+
+ /**
+ * Starts the PhidgetManager. This method starts the phidget manager running in the base Phidget21 C library.
+ * If attach and detach listeners are to be used, they should be registered before start is called so
+ * that no events are missed. Once start is called, the Phidget Manager will be active until {@link #close() close} is called.
+ */
+ public final void open() throws PhidgetException {
+ enableEvents(true);
+ nativeOpen();
+ }
+ /**
+ * Open this Manager remotely and securely, using an IP Address.
+ * <p>
+ * This method is the same as {@link #open(String, int) open(String ipAddress, int port)}, except that it specifies a password.
+ * This password can be set as a parameter when starting the Phidget Webservice.
+ */
+ public final void open(String ipAddress, int port, String password) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenRemoteIP(ipAddress, port, password);
+ }
+ /**
+ * Open this Manager remotely using an IP Address.
+ * <p>
+ * This version of open is network based.
+ * <p>
+ * @param ipAddress IP Address or hostname of the Phidget Webservice
+ * @param port Port of the Phidget Webservice
+ * @throws PhidgetException if the Phidget Webservice cannot be contacted
+ */
+ public final void open(String ipAddress, int port) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenRemoteIP(ipAddress, port, "");
+ }
+ /**
+ * Open this Manager remotely and securely, using a Server ID.
+ * <p>
+ * This method is the same as {@link #open(String) open(String serverID)}, except that it specifies a password.
+ * This password can be set as a parameter when starting the Phidget Webservice.
+ */
+ public final void open(String serverID, String password) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenRemote(serverID, password);
+ }
+ /**
+ * Open this Manager remotely using a Server ID.
+ * <p>
+ * This version of open is network based.
+ * <p>
+ * ServerID can be NULL to get a listing of all Phidgets on all Servers
+ *
+ * @param serverID ServerID of the Phidget Webservice
+ */
+ public final void open(String serverID) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenRemote(serverID, "");
+ }
+
+ /**
+ * Shuts down the Phidget Manager. This method should be called to close down the Phidget Manager.
+ * Events will no longer be recieved. This method gets calledd automatically when the class is
+ * destroyed so calling it is not required.
+ */
+ public final void close() throws PhidgetException {
+ enableEvents(false);
+ nativeClose();
+ }
+
+ private void enableEvents(boolean b)
+ {
+ enableManagerAttachEvents(b && attachListeners.size() > 0);
+ enableManagerDetachEvents(b && detachListeners.size() > 0);
+ enableServerConnectEvents(b && serverConnectListeners.size() > 0);
+ enableServerDisconnectEvents(b && serverDisconnectListeners.size() > 0);
+ }
+
+ private LinkedList attachListeners = new LinkedList();
+ private long nativeAttachHandler = 0;
+
+ /**
+ * Adds an attach listener. The attach handler is a method that will be called when a Phidget is phisically attached
+ * to the system, and has gone through its initalization, and so is ready to be used.
+ * <p>
+ * There is no limit on the number of attach handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.AttachListener AttachListener} interface
+ */
+ public final void addAttachListener(AttachListener l) {
+ synchronized (attachListeners) {
+ attachListeners.add(l);
+ enableManagerAttachEvents(true);
+ }
+ }
+
+ /**
+ * Removes an attach listener. This will remove a previously added attach listener.
+ */
+ public final void removeAttachListener(AttachListener l) {
+ synchronized (attachListeners) {
+ attachListeners.remove(l);
+ enableManagerAttachEvents(attachListeners.size() > 0);
+ }
+ }
+ private void fireAttach(AttachEvent e) {
+ synchronized (attachListeners) {
+ for (Iterator it = attachListeners.iterator();
+ it.hasNext(); )
+ ((AttachListener)it.next()).attached(e);
+ }
+ }
+ private native void enableManagerAttachEvents(boolean b);
+
+ private LinkedList detachListeners = new LinkedList();
+ private long nativeDetachHandler = 0;
+
+ /**
+ * Adds a detach listener. The detach handler is a method that will be called when a Phidget is phisically detached
+ * from the system, and is no longer available.
+ * <p>
+ * There is no limit on the number of detach handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.DetachListener DetachListener} interface
+ */
+ public final void addDetachListener(DetachListener l) {
+ synchronized (detachListeners) {
+ detachListeners.add(l);
+ enableManagerDetachEvents(true);
+ }
+ }
+
+ /**
+ * Removes a detach listener. This will remove a previously added detach listener.
+ */
+ public final void removeDetachListener(DetachListener l) {
+ synchronized (detachListeners) {
+ detachListeners.remove(l);
+ enableManagerDetachEvents(detachListeners.size() > 0);
+ }
+ }
+ private void fireDetach(DetachEvent e) {
+ synchronized (detachListeners) {
+ for (Iterator it = detachListeners.iterator();
+ it.hasNext(); )
+ ((DetachListener)it.next()).detached(e);
+ }
+ }
+ private native void enableManagerDetachEvents(boolean b);
+
+ private LinkedList serverConnectListeners = new LinkedList();
+ private long nativeServerConnectHandler = 0;
+
+ /**
+ * Adds an serverConnect listener. The serverConnect handler is a method that will be called when a connection to a server is made
+ * <p>
+ * There is no limit on the number of serverConnect handlers that can be registered for a particular Manager.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.ServerConnectListener ServerConnectListener} interface
+ */
+ public final void addServerConnectListener(ServerConnectListener l)
+ {
+ synchronized (serverConnectListeners)
+ {
+ serverConnectListeners.add(l);
+ enableServerConnectEvents(true);
+ }
+ }
+
+ /**
+ * Removes an serverConnect listener. This will remove a previously added serverConnect listener.
+ */
+ public final void removeServerConnectListener(ServerConnectListener l)
+ {
+ synchronized (serverConnectListeners)
+ {
+ serverConnectListeners.remove(l);
+ enableServerConnectEvents(serverConnectListeners.size() > 0);
+ }
+ }
+ private void fireServerConnect(ServerConnectEvent e)
+ {
+ synchronized (serverConnectListeners)
+ {
+ for (Iterator it = serverConnectListeners.iterator();
+ it.hasNext(); )
+ ((ServerConnectListener)it.next()).serverConnected(e);
+ }
+ }
+ private native void enableServerConnectEvents(boolean b);
+
+
+ private LinkedList serverDisconnectListeners = new LinkedList();
+ private long nativeServerDisconnectHandler = 0;
+
+ /**
+ * Adds an serverDisconnect listener. The serverDisconnect handler is a method that will be called when a connection to a server is terminated.
+ * <p>
+ * There is no limit on the number of serverDisconnect handlers that can be registered for a particular Manager.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.ServerDisconnectListener ServerDisconnectListener} interface
+ */
+ public final void addServerDisconnectListener(ServerDisconnectListener l)
+ {
+ synchronized (serverDisconnectListeners)
+ {
+ serverDisconnectListeners.add(l);
+ enableServerDisconnectEvents(true);
+ }
+ }
+
+ /**
+ * Removes an serverDisconnect listener. This will remove a previously added serverDisconnect listener.
+ */
+ public final void removeServerDisconnectListener(ServerDisconnectListener l)
+ {
+ synchronized (serverDisconnectListeners)
+ {
+ serverDisconnectListeners.remove(l);
+ enableServerDisconnectEvents(serverDisconnectListeners.size() > 0);
+ }
+ }
+ private void fireServerDisconnect(ServerDisconnectEvent e)
+ {
+ synchronized (serverDisconnectListeners)
+ {
+ for (Iterator it = serverDisconnectListeners.iterator();
+ it.hasNext(); )
+ ((ServerDisconnectListener)it.next()).serverDisconnected(e);
+ }
+ }
+ private native void enableServerDisconnectEvents(boolean b);
+
+ protected void finalize() throws Throwable
+ {
+ try
+ {
+ close();
+ } catch (Exception e) {
+ ;
+ }
+ try
+ {
+ nativeDelete();
+ }
+ catch (Exception e)
+ {
+ ;
+ }
+ finally{
+ handle = 0;
+ super.finalize();
+ }
+ }
+
+ /**
+ * Return a Sring describing this manager.
+ */
+ public String toString()
+ {
+ return "PhidgetManager: ";
+ }
+
+ /**
+ * Returns a list of Phidgets attached to the host computer. This list is updated right before the attach and detach
+ * events, and so will be up to date within these events.
+ * @return list of attached Phidgets
+ */
+ public Vector getPhidgets()
+ {
+ return phidgets;
+ }
+}
diff --git a/Java/com/phidgets/MotorControlPhidget.java b/Java/com/phidgets/MotorControlPhidget.java
new file mode 100644
index 0000000..8539b98
--- /dev/null
+++ b/Java/com/phidgets/MotorControlPhidget.java
@@ -0,0 +1,497 @@
+
+/*
+ * Copyright 2011 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 Motor Controller. All Methods
+ * to to control a motor controller and read back motor data are implemented in this class.
+ <p>
+ The Motor Control Phidget is able to control 1 or more DC motors.
+ Both speed and acceleration are controllable. Speed is controlled via PWM. The size of the motors
+ that can be driven depends on the motor controller. See your hardware documentation for more information.
+ <p>
+ The motor Controller boards also has 0 or more digital inputs.
+ *
+ * @author Phidgets Inc.
+ */
+public final class MotorControlPhidget extends Phidget
+{
+ public MotorControlPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+
+ /**
+ * Returns the number of motors supported by this Phidget. This does not neccesarily correspond
+ to the number of motors actually attached to the board.
+ * @return number of supported motors
+ * @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 getMotorCount () throws PhidgetException;
+ /**
+ * Returns the number of digital inputs. Not all Motor Controllers have digital inputs.
+ * @return number of digital inputs
+ * @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 getInputCount () throws PhidgetException;
+ /**
+ * Returns the number of encoders. Not all Motor Controllers have encoders.
+ * @return number of encoders
+ * @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 getEncoderCount () throws PhidgetException;
+ /**
+ * Returns the number of analog inputs. Not all Motor Controllers have analog inputs.
+ * @return number of analog inputs
+ * @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 getSensorCount () throws PhidgetException;
+ /**
+ * Returns the state of a digital input. True means that the input is activated, and False indicates the default state.
+ * @param index index of the input
+ * @return state of the input
+ * @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 getInputState (int index) throws PhidgetException;
+ /**
+ * Returns the position of an encoder. This is an absolute position as calcutated since the encoder was plugged in.
+ This value can be reset to anything using {@link #setEncoderPosition(int, int) setEncoderPosition}. Not all Motor Controllers have encoders.
+
+ * @param index index of the encoder
+ * @return position of the encoder
+ * @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 int getEncoderPosition (int index) throws PhidgetException;
+ /**
+ * Sets the position of a specific encoder. This resets the internal position count for an encoder. This call in no way actually
+ sends information to the device, as an absolute position is maintained only in the library. After this call, position changes
+ from the encoder will use the new value to calculate absolute position as reported by {@link #getEncoderPosition}. Not all Motor Controllers have encoders.
+ * @param index index of the encoder
+ * @param position new position for a encoder.
+ * @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 void setEncoderPosition (int index, int position) throws PhidgetException;
+ /**
+ * Returns the value of a sensor. Not all Motor Controllers have analog sensors.
+ * @param index index of the sensor
+ * @return sensor value of the sensor. Range is 0-1000.
+ * @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 int getSensorValue (int index) throws PhidgetException;
+ /**
+ * Returns the raw value of a sensor(12-bit). Not all Motor Controllers have analog sensors.
+ * @param index index of the sensor
+ * @return sensor raw value of the sensor. Range is 0-4096.
+ * @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 int getSensorRawValue (int index) throws PhidgetException;
+ /**
+ * Returns the ratiometric state of a sensor. Not all Motor Controllers have analog sensors.
+ * @return ratiometric state of sensors
+ * @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 boolean getRatiometric () throws PhidgetException;
+ /**
+ * Sets the ratiometric state. This controls the voltage reference used for sampling the analog sensors.
+ * @param ratiometric new ratiometric state of the sensors
+ * @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 void setRatiometric (boolean ratiometric) throws PhidgetException;
+ /**
+ * Returns a motor's acceleration. The valid range is between {@link #getAccelerationMin getAccelerationMin} and {@link #getAccelerationMax getAccelerationMax}, and refers to how fast the Motor Controller
+ will change the speed of a motor.
+ * @param index Index of motor
+ * @return acceleration of motor
+ * @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 double getAcceleration (int index) throws PhidgetException;
+ /**
+ * Sets a motor's acceleration.
+ * The valid range is between {@link #getAccelerationMin getAccelerationMin} and {@link #getAccelerationMax getAccelerationMax}. This controls how fast the motor changes speed.
+ * @param index index of the motor
+ * @param acceleration requested acceleration for that motor
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index or acceleration value are invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setAcceleration (int index, double acceleration) throws PhidgetException;
+ /**
+ * Returns the maximum acceleration that a motor will accept, or return.
+ * @param index Index of the motor
+ * @return Maximum acceleration
+ * @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 double getAccelerationMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum acceleration that a motor will accept, or return.
+ * @param index Index of the motor
+ * @return Minimum acceleration
+ * @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 double getAccelerationMin (int index) throws PhidgetException;
+ /**
+ * Returns a motor's velocity. The valid range is -100 - 100, with 0 being stopped.
+ * @param index index of the motor
+ * @return current velocity of the motor
+ * @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 double getVelocity (int index) throws PhidgetException;
+ /**
+ * @deprecated Replaced by
+ * {@link #getVelocity}
+ */
+ public native double getSpeed (int index) throws PhidgetException;
+ /**
+ * Sets a motor's velocity.
+ * The valid range is from -100 to 100, with 0 being stopped. -100 and 100 both correspond to full voltage,
+ with the value in between corresponding to different widths of PWM.
+ * @param index index of the motor
+ * @param velocity requested velocity for the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index or speed value are invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setVelocity (int index, double velocity) throws PhidgetException;
+ /**
+ * @deprecated Replaced by
+ * {@link #setVelocity}
+ */
+ public native void setSpeed (int index, double speed) throws PhidgetException;
+ /**
+ * Returns a motor's current usage. The valid range is 0 - 255. Note that this is not supported on all motor controllers.
+ * @param index index of the motor
+ * @return current usage of the motor
+ * @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 double getCurrent (int index) throws PhidgetException;
+ /**
+ * Returns the Back EMF sensing state for a specific motor. Note that this is not supported on all motor controllers.
+ * @param index Index of the motor
+ * @return Back EMF Sensing state for the motor
+ * @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 getBackEMFSensingState (int index) throws PhidgetException;
+ /**
+ * Sets the Back EMF sensing state for a specific motor. Note that this is not supported on all motor controllers.
+ * @param index Index of the motor
+ * @param bEMFState new Back EMF Sensing State
+ * @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 setBackEMFSensingState (int index, boolean bEMFState) throws PhidgetException;
+ /**
+ * Sets the Back EMF voltage for a specific motor. Note that this is not supported on all motor controllers.
+ * @param index Index of the motor
+ * @return Back EMF voltage of the motor
+ * @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 double getBackEMF (int index) throws PhidgetException;
+ /**
+ * Sets the supply voltage for the motors. This could be higher than the actual voltage. Note that this is not supported on all motor controllers.
+ * @return Supply voltage of the motor, in volts
+ * @throws PhidgetException If this Phidget is not opened and attached, the index is invalid, or if {@link #setBackEMFSensingState setBackEMFSensingState} is not set.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getSupplyVoltage () throws PhidgetException;
+ /**
+ * Returns the braking value for a specific motor. Note that this is not supported on all motor controllers.
+ * @param index index of the motor
+ * @return Braking value for the motor
+ * @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 double getBraking (int index) throws PhidgetException;
+ /**
+ * Sets the braking value for a specific motor. This is applied when velocity is 0. Default is 0%. Note that this is not supported on all motor controllers. Range is 0-100.
+ * @param index index of the motor
+ * @param braking new braking value for a specific motor
+ * @throws PhidgetException If this Phidget is not opened and attached, the index is invalid, or the brake value is invalid
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setBraking (int index, double braking) throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableMotorVelocityChangeEvents (b && motorVelocityChangeListeners.size () > 0);
+ enableCurrentChangeEvents (b && currentChangeListeners.size () > 0);
+ enableCurrentUpdateEvents (b && currentUpdateListeners.size () > 0);
+ enableInputChangeEvents (b && inputChangeListeners.size () > 0);
+ enableEncoderPositionChangeEvents (b && encoderPositionChangeListeners.size () > 0);
+ enableEncoderPositionUpdateEvents (b && encoderPositionUpdateListeners.size () > 0);
+ enableBackEMFUpdateEvents (b && backEMFUpdateListeners.size () > 0);
+ enableSensorUpdateEvents (b && sensorUpdateListeners.size () > 0);
+ }
+ /**
+ * Adds a velocity change listener. The velocity change handler is a method that will be called when the velocity
+ of a motor changes. These velocity changes are reported back from the Motor Controller and so correspond to actual motor speeds
+ over time.
+ * <p>
+ * There is no limit on the number of velocity change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.MotorVelocityChangeListener MotorVelocityChangeListener} interface
+ */
+ public final void addMotorVelocityChangeListener (MotorVelocityChangeListener l)
+ {
+ synchronized (motorVelocityChangeListeners)
+ {
+ motorVelocityChangeListeners.add (l);
+ enableMotorVelocityChangeEvents (true);
+ }} private LinkedList motorVelocityChangeListeners = new LinkedList ();
+ private long nativeMotorVelocityChangeHandler = 0;
+ public final void removeMotorVelocityChangeListener (MotorVelocityChangeListener l)
+ {
+ synchronized (motorVelocityChangeListeners)
+ {
+ motorVelocityChangeListeners.remove (l);
+ enableMotorVelocityChangeEvents (motorVelocityChangeListeners.size () > 0);
+ }} private void fireMotorVelocityChange (MotorVelocityChangeEvent e)
+ {
+ synchronized (motorVelocityChangeListeners)
+ {
+ for (Iterator it = motorVelocityChangeListeners.iterator (); it.hasNext ();)
+ ((MotorVelocityChangeListener) it.next ()).motorVelocityChanged (e);
+ }
+ }
+ private native void enableMotorVelocityChangeEvents (boolean b);
+ /**
+ * Adds a current change listener. The current change handler is a method that will be called when the current
+ consumed by a motor changes. Note that this event is not supported with the current motor controller, but
+ will be supported in the future
+ * <p>
+ * There is no limit on the number of current change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.CurrentChangeListener CurrentChangeListener} interface
+ */
+ public final void addCurrentChangeListener (CurrentChangeListener l)
+ {
+ synchronized (currentChangeListeners)
+ {
+ currentChangeListeners.add (l);
+ enableCurrentChangeEvents (true);
+ }} private LinkedList currentChangeListeners = new LinkedList ();
+ private long nativeCurrentChangeHandler = 0;
+ public final void removeCurrentChangeListener (CurrentChangeListener l)
+ {
+ synchronized (currentChangeListeners)
+ {
+ currentChangeListeners.remove (l);
+ enableCurrentChangeEvents (currentChangeListeners.size () > 0);
+ }} private void fireCurrentChange (CurrentChangeEvent e)
+ {
+ synchronized (currentChangeListeners)
+ {
+ for (Iterator it = currentChangeListeners.iterator (); it.hasNext ();)
+ ((CurrentChangeListener) it.next ()).currentChanged (e);
+ }
+ }
+ private native void enableCurrentChangeEvents (boolean b);
+ /**
+ * Adds a current update listener. The current change handler is a method that will be called every 8ms, regardless whether the current
+ consumed by a motor changes. Note that this event is not supported with all motor controllers
+ * <p>
+ * There is no limit on the number of current update handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.CurrentUpdateListener CurrentUpdateListener} interface
+ */
+ public final void addCurrentUpdateListener (CurrentUpdateListener l)
+ {
+ synchronized (currentUpdateListeners)
+ {
+ currentUpdateListeners.add (l);
+ enableCurrentUpdateEvents (true);
+ }} private LinkedList currentUpdateListeners = new LinkedList ();
+ private long nativeCurrentUpdateHandler = 0;
+ public final void removeCurrentUpdateListener (CurrentUpdateListener l)
+ {
+ synchronized (currentUpdateListeners)
+ {
+ currentUpdateListeners.remove (l);
+ enableCurrentUpdateEvents (currentUpdateListeners.size () > 0);
+ }} private void fireCurrentUpdate (CurrentUpdateEvent e)
+ {
+ synchronized (currentUpdateListeners)
+ {
+ for (Iterator it = currentUpdateListeners.iterator (); it.hasNext ();)
+ ((CurrentUpdateListener) it.next ()).currentUpdated (e);
+ }
+ }
+ private native void enableCurrentUpdateEvents (boolean b);
+ /**
+ * Adds an input change listener. The input change handler is a method that will be called when an input on this
+ * Motor Controller board has changed.
+ * <p>
+ * There is no limit on the number of input change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.InputChangeListener InputChangeListener} interface
+ */
+ public final void addInputChangeListener (InputChangeListener l)
+ {
+ synchronized (inputChangeListeners)
+ {
+ inputChangeListeners.add (l);
+ enableInputChangeEvents (true);
+ }} private LinkedList inputChangeListeners = new LinkedList ();
+ private long nativeInputChangeHandler = 0;
+ public final void removeInputChangeListener (InputChangeListener l)
+ {
+ synchronized (inputChangeListeners)
+ {
+ inputChangeListeners.remove (l);
+ enableInputChangeEvents (inputChangeListeners.size () > 0);
+ }} private void fireInputChange (InputChangeEvent e)
+ {
+ synchronized (inputChangeListeners)
+ {
+ for (Iterator it = inputChangeListeners.iterator (); it.hasNext ();)
+ ((InputChangeListener) it.next ()).inputChanged (e);
+ }
+ }
+ private native void enableInputChangeEvents (boolean b);
+ /**
+ * Adds a position change listener. The position change handler is a method that will be called when the position of an
+ encoder changes. The position change event provides data about how many ticks have occured, and how much time has
+ passed since the last position change event, but does not contain an absolute position. This can be obtained from
+ {@link #getEncoderPosition}.
+ * <p>
+ * There is no limit on the number of encoder position change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.EncoderPositionChangeListener EncoderPositionChangeListener} interface
+ */
+ public final void addEncoderPositionChangeListener (EncoderPositionChangeListener l)
+ {
+ synchronized (encoderPositionChangeListeners)
+ {
+ encoderPositionChangeListeners.add (l);
+ enableEncoderPositionChangeEvents (true);
+ }} private LinkedList encoderPositionChangeListeners = new LinkedList ();
+ private long nativeEncoderPositionChangeHandler = 0;
+ public final void removeEncoderPositionChangeListener (EncoderPositionChangeListener l)
+ {
+ synchronized (encoderPositionChangeListeners)
+ {
+ encoderPositionChangeListeners.remove (l);
+ enableEncoderPositionChangeEvents (encoderPositionChangeListeners.size () > 0);
+ }} private void fireEncoderPositionChange (EncoderPositionChangeEvent e)
+ {
+ synchronized (encoderPositionChangeListeners)
+ {
+ for (Iterator it = encoderPositionChangeListeners.iterator (); it.hasNext ();)
+ ((EncoderPositionChangeListener) it.next ()).encoderPositionChanged (e);
+ }
+ }
+ private native void enableEncoderPositionChangeEvents (boolean b);
+ /**
+ * Adds a position update listener. The position update handler is a method that will be called at a constant rate; every 8ms, whether the encoder position has changed or not.
+ * The position update event provides data about how many ticks have occured since the last position update event, but does not contain an absolute position. This can be obtained from
+ *{@link #getEncoderPosition}.
+ * <p>
+ * There is no limit on the number of encoder position update handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.EncoderPositionUpdateListener EncoderPositionUpdateListener} interface
+ */
+ public final void addEncoderPositionUpdateListener (EncoderPositionUpdateListener l)
+ {
+ synchronized (encoderPositionUpdateListeners)
+ {
+ encoderPositionUpdateListeners.add (l);
+ enableEncoderPositionUpdateEvents (true);
+ }} private LinkedList encoderPositionUpdateListeners = new LinkedList ();
+ private long nativeEncoderPositionUpdateHandler = 0;
+ public final void removeEncoderPositionUpdateListener (EncoderPositionUpdateListener l)
+ {
+ synchronized (encoderPositionUpdateListeners)
+ {
+ encoderPositionUpdateListeners.remove (l);
+ enableEncoderPositionUpdateEvents (encoderPositionUpdateListeners.size () > 0);
+ }} private void fireEncoderPositionUpdate (EncoderPositionUpdateEvent e)
+ {
+ synchronized (encoderPositionUpdateListeners)
+ {
+ for (Iterator it = encoderPositionUpdateListeners.iterator (); it.hasNext ();)
+ ((EncoderPositionUpdateListener) it.next ()).encoderPositionUpdated (e);
+ }
+ }
+ private native void enableEncoderPositionUpdateEvents (boolean b);
+ /**
+ * Adds a Back EMF update listener. The Back EMF update handler is a method that will be called at a constant rate; every 8ms, whether the Back EMF value has changed or not.
+ * <p>
+ * There is no limit on the number of Back EMF update handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.BackEMFUpdateListener BackEMFUpdateListener} interface
+ */
+ public final void addBackEMFUpdateListener (BackEMFUpdateListener l)
+ {
+ synchronized (backEMFUpdateListeners)
+ {
+ backEMFUpdateListeners.add (l);
+ enableBackEMFUpdateEvents (true);
+ }} private LinkedList backEMFUpdateListeners = new LinkedList ();
+ private long nativeBackEMFUpdateHandler = 0;
+ public final void removeBackEMFUpdateListener (BackEMFUpdateListener l)
+ {
+ synchronized (backEMFUpdateListeners)
+ {
+ backEMFUpdateListeners.remove (l);
+ enableBackEMFUpdateEvents (backEMFUpdateListeners.size () > 0);
+ }} private void fireBackEMFUpdate (BackEMFUpdateEvent e)
+ {
+ synchronized (backEMFUpdateListeners)
+ {
+ for (Iterator it = backEMFUpdateListeners.iterator (); it.hasNext ();)
+ ((BackEMFUpdateListener) it.next ()).backEMFUpdated (e);
+ }
+ }
+ private native void enableBackEMFUpdateEvents (boolean b);
+ /**
+ * Adds a sensor update listener. The sensor update handler is a method that will be called at a constant rate; every 8ms, whether the sensor value has changed or not.
+ * <p>
+ * There is no limit on the number of sensor update handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.SensorUpdateListener SensorUpdateListener} interface
+ */
+ public final void addSensorUpdateListener (SensorUpdateListener l)
+ {
+ synchronized (sensorUpdateListeners)
+ {
+ sensorUpdateListeners.add (l);
+ enableSensorUpdateEvents (true);
+ }} private LinkedList sensorUpdateListeners = new LinkedList ();
+ private long nativeSensorUpdateHandler = 0;
+ public final void removeSensorUpdateListener (SensorUpdateListener l)
+ {
+ synchronized (sensorUpdateListeners)
+ {
+ sensorUpdateListeners.remove (l);
+ enableSensorUpdateEvents (sensorUpdateListeners.size () > 0);
+ }} private void fireSensorUpdate (SensorUpdateEvent e)
+ {
+ synchronized (sensorUpdateListeners)
+ {
+ for (Iterator it = sensorUpdateListeners.iterator (); it.hasNext ();)
+ ((SensorUpdateListener) it.next ()).sensorUpdated (e);
+ }
+ }
+ private native void enableSensorUpdateEvents (boolean b);
+}
diff --git a/Java/com/phidgets/PHSensorPhidget.java b/Java/com/phidgets/PHSensorPhidget.java
new file mode 100644
index 0000000..dc9ecf6
--- /dev/null
+++ b/Java/com/phidgets/PHSensorPhidget.java
@@ -0,0 +1,136 @@
+
+/*
+ * Copyright 2006 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 PH Sensor. All methods
+ * to read pH data from the PH Sensor are implemented in this class.
+ * <p>
+ * The Phidget PH Sensor provides one standard pH sensor input.
+ *
+ * @author Phidgets Inc.
+ */
+public final class PHSensorPhidget extends Phidget
+{
+ public PHSensorPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+ /**
+ * Returns the measured pH. This value can range from between {@link #getPHMin getPHMin} and {@link #getPHMax getPHMax}, but
+ * some of this range is likely outside of the valid range of most pH sensors. For example, when there is no pH sensor
+ * attached, the board will often report an (invalid) pH of 15, which while technically within a valid pH range, is unlikely to be seen.
+ * @return the current pH
+ * @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 double getPH () throws PhidgetException;
+ /**
+ * Returns the maximum pH that will be returned by the pH sensor input.
+ * @return Maximum pH
+ * @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 double getPHMax () throws PhidgetException;
+ /**
+ * Returns the minimum pH that will be returned by the pH sensor input.
+ * @return Minimum pH
+ * @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 double getPHMin () throws PhidgetException;
+ /**
+ * Returns the Potential, in millivolts. This returns the actual voltage potential measured by the A/D.
+ * This value will always be between {@link #getPotentialMin getPotentialMin} and {@link #getPotentialMax getPotentialMax}.
+ * This is the value that is internally used to calculate pH in the library.
+ * @return the current potential
+ * @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 double getPotential () throws PhidgetException;
+ /**
+ * Returns the maximum potential that will be returned by the pH sensor input.
+ * @return Maximum potential in millivolts
+ * @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 double getPotentialMax () throws PhidgetException;
+ /**
+ * Returns the minimum potential that will be returned by the pH sensor input.
+ * @return Minimum potential in millivolts
+ * @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 double getPotentialMin () throws PhidgetException;
+ /**
+ * Sets the probe temperature in degrees celcius.
+ * This value is used while calculating the pH. The default value in the libary is 20 degrees celcius. If the temperature
+ * of the liquid being measured is not 20 degrees, then it should be measued and set for maximum accuracy.
+ * <p>
+ * Note: All that this does is set a value in the library that is used for calculating ph. This does not set anything
+ * in the hardware itself.
+ *
+ * @param newVal temperature
+ * @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 void setTemperature (double newVal) throws PhidgetException;
+ /**
+ * Sets the change trigger.
+ * This is how much the pH much change between successive PHChangeEvents. By default this value is set to 0.05
+ * @param newVal Trigger
+ * @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 void setPHChangeTrigger (double newVal) throws PhidgetException;
+ /**
+ * Returns the change trigger.
+ * This is how much the pH much change between successive PHChangeEvents. By default this value is set to 0.05
+ * @return Trigger
+ * @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 double getPHChangeTrigger () throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enablePHChangeEvents (b && phChangeListeners.size () > 0);
+ }
+ /**
+ * Adds a pH change listener. The pH change handler is a method that will be called when the pH
+ * has changed by at least the {@link #getPHChangeTrigger() Trigger} that has been set.
+ * <p>
+ * There is no limit on the number of pH change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.PHChangeListener PHChangeListener} interface
+ */
+ public final void addPHChangeListener (PHChangeListener l)
+ {
+ synchronized (phChangeListeners)
+ {
+ phChangeListeners.add (l);
+ enablePHChangeEvents (true);
+ }} private LinkedList phChangeListeners = new LinkedList ();
+ private long nativePHChangeHandler = 0;
+ public final void removePHChangeListener (PHChangeListener l)
+ {
+ synchronized (phChangeListeners)
+ {
+ phChangeListeners.remove (l);
+ enablePHChangeEvents (phChangeListeners.size () > 0);
+ }} private void firePHChange (PHChangeEvent e)
+ {
+ synchronized (phChangeListeners)
+ {
+ for (Iterator it = phChangeListeners.iterator (); it.hasNext ();)
+ ((PHChangeListener) it.next ()).phChanged (e);
+ }
+ }
+ private native void enablePHChangeEvents (boolean b);
+}
diff --git a/Java/com/phidgets/Phidget.java b/Java/com/phidgets/Phidget.java
new file mode 100644
index 0000000..e2d611c
--- /dev/null
+++ b/Java/com/phidgets/Phidget.java
@@ -0,0 +1,1000 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+package com.phidgets;
+
+import com.phidgets.event.*;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+/**
+ * This is the base class from which all Phidget device classes derive.
+ * Don't create phidget devices directly using this class. Use the specific class for the
+ * device that you wish to access.
+ *
+ * @author Phidgets Inc.
+ * @version 2.1.7
+ */
+public class Phidget
+{
+ static
+ {
+ try
+ {
+
+ System.loadLibrary("phidget21");
+
+ }
+ catch(UnsatisfiedLinkError ex)
+ {
+ String os = System.getProperty("os.name");
+ if(os.startsWith("Linux"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library (libphidget21.so)."
+ +"\nMake sure it is installed, and add it's path to LD_LIBRARY_PATH.");
+ }
+ else if(os.startsWith("Windows"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library."
+ +"\nThe Windows Phidget21 MSI must be installed.");
+ }
+ else if(os.startsWith("Mac"))
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library."
+ +"\nThe Mac Phidget21 DMG must be installed.");
+ }
+ else
+ {
+ throw new ExceptionInInitializerError(ex.getMessage()
+ +"\nCould not locate the Phidget C library.");
+ }
+ }
+
+
+
+ }
+
+ private long handle = 0;
+ boolean managerPhidget = false;
+
+ /**
+ * Class constructor specifying a handle. This constructor is to be used only by subclasses, as the Phidget calss should never need to
+ * be instatiated directly by the user.
+ *
+ * @param handle A native Handle points to the underlying phidget structure in the base phidget21 C library.
+ */
+ public Phidget(long handle) {
+ this.handle = handle;
+ }
+
+ private final long getHandle() {
+ return handle;
+ }
+
+ /**
+ * Returns the library version. This is the library version of the underlying phidget21 C library and not the version of the
+ * JNI wrapper implementation.
+ * <p>
+ * The version is retured at a string which contains the version number and build date.
+ *
+ * @return Library Version
+ */
+ public final static native String getLibraryVersion();
+
+ /**
+ * Critial error messages. This is used with {@link #enableLogging enableLogging} and {@link #log log}
+ * <p>
+ * This is the lowest logging level. Errors at this level are generally non-recoverable and indicate either hardware problems,
+ * library bugs, or other serious issues.
+ * <P>
+ * If logging is enabled at this level, only {@link #PHIDGET_LOG_CRITICAL PHIDGET_LOG_CRITICAL} messages are logged.
+ */
+ public static final int PHIDGET_LOG_CRITICAL = 1;
+ /**
+ * Non-critical error messages. This is used with {@link #enableLogging enableLogging} and {@link #log log}
+ * <P>
+ * Errors at this level are generally automatically recoverable, but may help to track down issues.
+ * <p>
+ * If logging is enabled at this level, {@link #PHIDGET_LOG_ERROR PHIDGET_LOG_ERROR} as well as
+ * {@link #PHIDGET_LOG_CRITICAL PHIDGET_LOG_CRITICAL} messages are logged.
+ */
+ public static final int PHIDGET_LOG_ERROR = 2;
+ /**
+ * Warning messages. This is used with {@link #enableLogging enableLogging} and {@link #log log}
+ * <P>
+ * Warnings are used to log behaviour that is not neccessarily in error, but is nevertheless odd or unexpected.
+ * <p>
+ * If logging is enabled at this level, {@link #PHIDGET_LOG_WARNING PHIDGET_LOG_WARNING} as well as
+ * {@link #PHIDGET_LOG_ERROR PHIDGET_LOG_ERROR} and {@link #PHIDGET_LOG_CRITICAL PHIDGET_LOG_CRITICAL} messages are logged.
+ */
+ public static final int PHIDGET_LOG_WARNING = 3;
+ /**
+ * Debug messages. This is used with {@link #enableLogging enableLogging} and {@link #log log}
+ * <P>
+ * Debug messages are generally used for debugging at Phdigets Inc.
+ * <p>
+ * Note: {@link #PHIDGET_LOG_DEBUG PHIDGET_LOG_DEBUG} messages are only logged in the debug version of the library, regardless of logging level.
+ * Thus, these logs should never be seen outside of Phidgets Inc.
+ * <p>
+ * If logging is enabled at this level, {@link #PHIDGET_LOG_DEBUG PHIDGET_LOG_DEBUG} as well as
+ * {@link #PHIDGET_LOG_WARNING PHIDGET_LOG_WARNING}, {@link #PHIDGET_LOG_ERROR PHIDGET_LOG_ERROR}
+ * and {@link #PHIDGET_LOG_CRITICAL PHIDGET_LOG_CRITICAL} messages are logged.
+ */
+ public static final int PHIDGET_LOG_DEBUG = 4;
+ /**
+ * Informational messages. This is used with {@link #enableLogging enableLogging} and {@link #log log}
+ * <P>
+ * Informational messages track key happenings within phidget21 - mostly to do with threads starting and shutting down, and the
+ * internals of the USB code.
+ * <p>
+ * If logging is enabled at this level, {@link #PHIDGET_LOG_INFO PHIDGET_LOG_INFO} as well as
+ * {@link #PHIDGET_LOG_DEBUG PHIDGET_LOG_DEBUG}, {@link #PHIDGET_LOG_WARNING PHIDGET_LOG_WARNING}, {@link #PHIDGET_LOG_ERROR PHIDGET_LOG_ERROR}
+ * and {@link #PHIDGET_LOG_CRITICAL PHIDGET_LOG_CRITICAL} messages are logged.
+ */
+ public static final int PHIDGET_LOG_INFO = 5;
+ /**
+ * Verbose messages. This is used with {@link #enableLogging enableLogging} and {@link #log log}
+ * <P>
+ * This is the highest logging level. Verbose messages are informational messages that are expected to happen so
+ * frequently that they tend to drown out other log messages.
+ * <p>
+ * If logging is enabled at this level, {@link #PHIDGET_LOG_VERBOSE PHIDGET_LOG_VERBOSE} as well as
+ * {@link #PHIDGET_LOG_INFO PHIDGET_LOG_INFO}, {@link #PHIDGET_LOG_DEBUG PHIDGET_LOG_DEBUG},
+ * {@link #PHIDGET_LOG_WARNING PHIDGET_LOG_WARNING}, {@link #PHIDGET_LOG_ERROR PHIDGET_LOG_ERROR}
+ * and {@link #PHIDGET_LOG_CRITICAL PHIDGET_LOG_CRITICAL} messages are logged.
+ */
+ public static final int PHIDGET_LOG_VERBOSE = 6;
+
+ private final static native void nativeEnableLogging(int level, String file);
+
+ /**
+ * Turns on logging in the native C Library. This is mostly usefull for debugging purposes - when an issue needs to be resolved by
+ * Phidgets Inc. The output is mostly low-level library information, that won't be usefull for most users.
+ * <p>
+ * Logging may be usefull for users trying to debug their own problems, as logs can be inserted by the user using {@link #log log}.
+ * <p>
+ * The level can be one of: {@link #PHIDGET_LOG_VERBOSE PHIDGET_LOG_VERBOSE},
+ * {@link #PHIDGET_LOG_INFO PHIDGET_LOG_INFO}, {@link #PHIDGET_LOG_DEBUG PHIDGET_LOG_DEBUG},
+ * {@link #PHIDGET_LOG_WARNING PHIDGET_LOG_WARNING}, {@link #PHIDGET_LOG_ERROR PHIDGET_LOG_ERROR}
+ * or {@link #PHIDGET_LOG_CRITICAL PHIDGET_LOG_CRITICAL}
+ *
+ * @param level highest level of logging that will be output
+ * @param file file to output log to. specify 'null' to output to the console
+ */
+ public final static void enableLogging(int level, String file)
+ {
+ nativeEnableLogging(level, file);
+ }
+
+ /**
+ * Turns off logging in the native C Library. This only needs to be called if enableLogging was called to turn logging on.
+ * This will turn logging back off.
+ */
+ public final static native void disableLogging();
+
+ private final static native void nativeLog(int level, String id, String log);
+
+ /**
+ * Adds a log entry into the phidget log. This log is enabled by calling {@link #enableLogging(int level, String file) enableLogging}
+ * and this allows the entry of user logs in amongst the phidget library logs.
+ * <p>
+ * The level can be one of: {@link #PHIDGET_LOG_VERBOSE PHIDGET_LOG_VERBOSE},
+ * {@link #PHIDGET_LOG_INFO PHIDGET_LOG_INFO}, {@link #PHIDGET_LOG_DEBUG PHIDGET_LOG_DEBUG},
+ * {@link #PHIDGET_LOG_WARNING PHIDGET_LOG_WARNING}, {@link #PHIDGET_LOG_ERROR PHIDGET_LOG_ERROR}
+ * or {@link #PHIDGET_LOG_CRITICAL PHIDGET_LOG_CRITICAL}
+ * <p>
+ * Note: {@link #PHIDGET_LOG_DEBUG PHIDGET_LOG_DEBUG} should not be used, as these logs are only printed when using the debug library,
+ * which is not generally available.
+ *
+ * @param level level to enter the log at
+ * @param id an arbitrary identifier for this log. This can be NULL. The C library uses this field for source filename and line number
+ * @param log the message to log
+ */
+ public final static void log(int level, String id, String log)
+ {
+ nativeLog(level, id, log);
+ }
+
+ public static final int PHIDID_NOTHING = 1;
+
+ /* These are all current devices */
+ public static final int PHIDID_ACCELEROMETER_3AXIS = 0x07E;
+ public static final int PHIDID_ADVANCEDSERVO_1MOTOR = 0x082;
+ public static final int PHIDID_ANALOG_4OUTPUT = 0x037;
+ public static final int PHIDID_ADVANCEDSERVO_8MOTOR = 0x03A;
+ public static final int PHIDID_BIPOLAR_STEPPER_1MOTOR = 0x07B;
+ public static final int PHIDID_BRIDGE_4INPUT = 0x03B;
+ public static final int PHIDID_ENCODER_1ENCODER_1INPUT = 0x04B;
+ public static final int PHIDID_ENCODER_HS_1ENCODER = 0x080;
+ public static final int PHIDID_ENCODER_HS_4ENCODER_4INPUT = 0x04F;
+ public static final int PHIDID_FREQUENCYCOUNTER_2INPUT = 0x035;
+ public static final int PHIDID_GPS = 0x079;
+ public static final int PHIDID_INTERFACEKIT_0_0_4 = 0x040;
+ public static final int PHIDID_INTERFACEKIT_0_0_8 = 0x081;
+ public static final int PHIDID_INTERFACEKIT_0_16_16 = 0x044;
+ public static final int PHIDID_INTERFACEKIT_8_8_8 = 0x045;
+ public static final int PHIDID_INTERFACEKIT_8_8_8_w_LCD = 0x07D;
+ public static final int PHIDID_IR = 0x04D;
+ public static final int PHIDID_LED_64 = 0x04A;
+ public static final int PHIDID_LED_64_ADV = 0x04C;
+ public static final int PHIDID_LINEAR_TOUCH = 0x076;
+ public static final int PHIDID_MOTORCONTROL_HC_2MOTOR = 0x059;
+ public static final int PHIDID_MOTORCONTROL_LV_2MOTOR_4INPUT = 0x058;
+ public static final int PHIDID_MOTORCONTROL_1MOTOR = 0x03E;
+ public static final int PHIDID_PHSENSOR = 0x074;
+ public static final int PHIDID_RFID_2OUTPUT = 0x031;
+ public static final int PHIDID_ROTARY_TOUCH = 0x077;
+ public static final int PHIDID_SERVO_1MOTOR = 0x039;
+ public static final int PHIDID_SPATIAL_ACCEL_3AXIS = 0x07F;
+ public static final int PHIDID_SPATIAL_ACCEL_GYRO_COMPASS = 0x033;
+ public static final int PHIDID_TEMPERATURESENSOR = 0x070;
+ public static final int PHIDID_TEMPERATURESENSOR_4 = 0x032;
+ public static final int PHIDID_TEXTLCD_2x20_w_8_8_8 = 0x17D;
+ public static final int PHIDID_TEXTLCD_ADAPTER = 0x03D;
+ public static final int PHIDID_UNIPOLAR_STEPPER_4MOTOR = 0x07A;
+
+ /* These are all past devices (no longer sold) */
+ public static final int PHIDID_ACCELEROMETER_2AXIS = 0x071;
+ public static final int PHIDID_INTERFACEKIT_0_8_8_w_LCD = 0x053;
+ public static final int PHIDID_INTERFACEKIT_4_8_8 = 4;
+ public static final int PHIDID_RFID = 0x030;
+ public static final int PHIDID_SERVO_1MOTOR_OLD = 2;
+ public static final int PHIDID_SERVO_4MOTOR = 0x038;
+ public static final int PHIDID_SERVO_4MOTOR_OLD = 3;
+ public static final int PHIDID_TEXTLCD_2x20 = 0x052;
+ public static final int PHIDID_TEXTLCD_2x20_w_0_8_8 = 0x153;
+ public static final int PHIDID_TEXTLED_1x8 = 0x049;
+ public static final int PHIDID_TEXTLED_4x8 = 0x048;
+ public static final int PHIDID_WEIGHTSENSOR = 0x072;
+
+
+ /**
+ * Returns the Device ID of this Phidget. This is one of the PHIDID_(...) constants defined above. This uniquely identifies a specific type of Phidget.
+ *
+ * @return Device ID
+ * @throws PhidgetException If this Phidget is not opened and attached. See {@link #open(int) open} for information on determining if a device is attached.
+ */
+ public final native int getDeviceID() throws PhidgetException;
+
+ public static final int PHIDCLASS_NOTHING = 1;
+ public static final int PHIDCLASS_ACCELEROMETER = 2;
+ public static final int PHIDCLASS_ADVANCEDSERVO = 3;
+ public static final int PHIDCLASS_ANALOG = 22;
+ public static final int PHIDCLASS_BRIDGE = 23;
+ public static final int PHIDCLASS_ENCODER = 4;
+ public static final int PHIDCLASS_FREQUENCYCOUNTER = 21;
+ public static final int PHIDCLASS_GPS = 5;
+ public static final int PHIDCLASS_INTERFACEKIT = 7;
+ public static final int PHIDCLASS_LED = 8;
+ public static final int PHIDCLASS_MOTORCONTROL = 9;
+ public static final int PHIDCLASS_PHSENSOR = 10;
+ public static final int PHIDCLASS_RFID = 11;
+ public static final int PHIDCLASS_SERVO = 12;
+ public static final int PHIDCLASS_STEPPER = 13;
+ public static final int PHIDCLASS_TEMPERATURESENSOR = 14;
+ public static final int PHIDCLASS_TEXTLCD = 15;
+ public static final int PHIDCLASS_TEXTLED = 16;
+ public static final int PHIDCLASS_WEIGHTSENSOR = 17;
+
+ /**
+ * Returns the Device Class of this Phidget. This is one of the PHIDCLASS_(...) constants defined above. This represents a class of Phidgets - ie Interface Kit.
+ *
+ * @return Device ID
+ * @throws PhidgetException If this Phidget is not opened and attached. See {@link #open(int) open} for information on determining if a device is attached.
+ */
+ public final native int getDeviceClass() throws PhidgetException;
+
+ /**
+ * Returns the unique serial number of this Phidget. This number is set during manufacturing, and is unique across all Phidgets.
+ * This number can be used in calls to {@link #open(int) open} to specify this specific Phidget to be opened.
+ *
+ * @return Serial Number
+ * @throws PhidgetException If this Phidget is not opened and attached. See {@link #open(int) open} for information on determining if a device is attached.
+ */
+ public final native int getSerialNumber() throws PhidgetException;
+
+ /**
+ * Returns the device version of this Phidget. This number is simply a way of distinguishing between different revisions
+ * of a specific type of Phidget, and is only really of use if you need to troubleshoot device problems with Phidgets Inc.
+ *
+ * @return Version
+ * @throws PhidgetException If this Phidget is not opened and attached. See {@link #open(int) open} for information on determining if a device is attached.
+ */
+ public final native int getDeviceVersion() throws PhidgetException;
+
+ /**
+ * Return the device type of this Phidget. This is a string that describes the device as a class of devices. For example,
+ * all PhidgetInterfaceKit Phidgets will returns the String "PhidgetInterfaceKit".
+ * <p>
+ * This function is mostly usefull if you are using the {@link com.phidgets.Manager Phidget Manager} because it's attach and detach handlers
+ * return {link com.phidgets.phidget phidget} objects, and you can use this method to determine their proper type.
+ *
+ * @return Device Type
+ * @throws PhidgetException If this Phidget is not opened and attached. See {@link #open(int) open} for information on determining if a device is attached.
+ */
+ public final native String getDeviceType() throws PhidgetException;
+
+ /**
+ * Return the name of this Phidget. This is a string that describes the device. For example, a PhidgetInterfaceKit could be described
+ * as "Phidget InterfaceKit 8/8/8", or "Phidget InterfaceKit 0/0/4", among others, depending on the specific device.
+ * <p>
+ * This lets you determine the specific type of a Phidget, within the broader classes of Phidgets, such as PhidgetInterfaceKit, or PhidgetServo
+ *
+ * @return Name
+ * @throws PhidgetException If this Phidget is not opened and attached. See {@link #open(int) open} for information on determining if a device is attached.
+ */
+ public final native String getDeviceName() throws PhidgetException;
+
+ /**
+ * Returns the attached status of this Phidget. This method returns True or False, depending on whether the Phidget is phisically plugged
+ * into the computer, initialized, and ready to use - or not. If a Phidget is not attached, many functions calls will fail with a PhidgetException,
+ * so either checking this function, or using the Attach and Detach events, is recommended, if a device is likely to be attached or
+ * detached during use.
+ *
+ * @return Status
+ * @throws PhidgetException If this Phidget is not opened.
+ */
+ public final native boolean isAttached() throws PhidgetException;
+
+ /**
+ * Returns the network attached status for remotely opened Phidgets. This method returns True or False, depending on whether a connection to the
+ * Phidget WebService is open - or not. If this is false for a remote Phidget then the connection is not active - either because a connection
+ * has not yet been established, or because the connection was terminated.
+ *
+ * @return Status
+ * @throws PhidgetException If this Phidget is not opened.
+ */
+ public final native boolean isAttachedToServer() throws PhidgetException;
+
+ /**
+ * Returns the label associated with this Phidget. This label is a String - up to ten digits - that is stored in the Flash memory
+ * of newer Phidgets. This label can be set programatically (see {@link #setDeviceLabel(String) setDeviceLabel}), and is non-volatile - so it is remembered
+ * even if the Phidget is unplugged.
+ *
+ * @return Label
+ * @throws PhidgetException If this Phidget is not opened and attached, or if this Phidget does not support labels.
+ * See {@link #open(int) open} for determining if a device is attached.
+ */
+ public final native String getDeviceLabel() throws PhidgetException;
+
+ /**
+ * Sets the Label associated with this Phidget. Labels are user defined Strings that persist in a Phidget's Flash.
+ * They are only supported in the newer Phidgets. The maximum length is 10 characters.
+ * <p>
+ * Labels can not currently be set from Windows because of driver incompatibility. Labels can be set from MacOS, Linux and Windows CE.
+ *
+ * @param label Label
+ * @throws PhidgetException If this Phidget is not opened and attached, or if this Phidget does not support labels, or if this is
+ * called from Windows. See {@link #open(int) open} for determining if a device is attached.
+ */
+ public final native void setDeviceLabel(String label) throws PhidgetException;
+
+ /**
+ * Returns the Address of a Phidget Webservice when this Phidget was opened as remote. This may be an IP Address or a hostname.
+ *
+ * @return Server Address
+ * @throws PhidgetException if this Phidget was open opened as a remote Phidget.
+ */
+ public final native String getServerAddress() throws PhidgetException;
+ /**
+ * Returns the Server ID of a Phidget Webservice when this Phidget was opened as remote. This is an arbitrary server identifier,
+ * independant of IP address and Port.
+ *
+ * @return Server ID
+ * @throws PhidgetException if this Phidget was open opened as a remote Phidget.
+ */
+ public final native String getServerID() throws PhidgetException;
+ /**
+ * Returns the Port of a Phidget Webservice when this Phidget was opened as remote.
+ *
+ * @return Server Port
+ * @throws PhidgetException if this Phidget was open opened as a remote Phidget.
+ */
+ public final native int getServerPort() throws PhidgetException;
+
+ private final native void nativeClose() throws PhidgetException;
+ private final native void nativeDelete() throws PhidgetException;
+ private final native void nativeOpen(int serial) throws PhidgetException;
+ private final native void nativeOpenRemote(int serial, String serverID, String pass) throws PhidgetException;
+ private final native void nativeOpenRemoteIP(int serial, String ipAddress, int port, String pass) throws PhidgetException;
+ private final native void nativeOpenLabel(String label) throws PhidgetException;
+ private final native void nativeOpenLabelRemote(String label, String serverID, String pass) throws PhidgetException;
+ private final native void nativeOpenLabelRemoteIP(String label, String ipAddress, int port, String pass) throws PhidgetException;
+
+ /**
+ * Open this Phidget with a specific serial number.
+ * <p>
+ * Open is pervasive. What this means is that you can call open on a device before it is plugged in,
+ * and keep the device opened across device dis- and re-connections.
+ * <p>
+ * Open is Asynchronous. What this means is that open will return immediately --
+ * before the device being opened is actually available, so you need to use either the {@link #addAttachListener(AttachListener l) attach event}
+ * or the {@link #waitForAttachment() waitForAttachment} method to determine if a device
+ * is available before using it.
+ * <p>
+ * This version of open specifies a serial number - The serial number is a unique number assigned to each Phidget
+ * during production and can be used to uniquely identify specific phidgets.
+ * use {@link #openAny() openAny} to open a device without specifying the serial number.
+ *
+ * @param serial Serial Number
+ */
+ public final void open(int serial) throws PhidgetException {
+ enableEvents(true);
+ nativeOpen(serial);
+ }
+
+ /**
+ * Open this Phidget remotely using an IP Address, and a specific serial number.
+ * <p>
+ * This version of open is network based.
+ * <p>
+ * Open is pervasive. What this means is that you can call open on a device before it is plugged in,
+ * and on a server before it is running, and keep the device opened across device, and server dis- and re-connections.
+ * <p>
+ * Open is Asynchronous. What this means is that open will return immediately --
+ * before the device being opened is actually available, so you need to use either the {@link #addAttachListener(AttachListener l) attach event}
+ * or the {@link #waitForAttachment() waitForAttachment} method to determine if a device
+ * is available before using it.
+ * <p>
+ * This version of open specifies a serial number - The serial number is a unique number assigned to each Phidget
+ * during production and can be used to uniquely identify specific phidgets.
+ * use {@link #openAny(String ipAddress, int port) openAny(String ipAddress, int port)} to open a device without specifying the serial number.
+ *
+ * @param serial Serial Number
+ * @param ipAddress IP Address or hostname of the Phidget Webservice
+ * @param port Port of the Phidget Webservice
+ * @throws PhidgetException if the Phidget Webservice cannot be contacted
+ */
+ public final void open(int serial, String ipAddress, int port) throws PhidgetException
+ {
+ open(serial, ipAddress, port, "");
+ }
+ /**
+ * Open this Phidget remotely and securely, using an IP Address, and a specific serial number.
+ * <p>
+ * This method is the same as {@link #open(int, String, int) open(int serial, String ipAddress, int port)}, except that it specifies a password.
+ * This password can be set as a parameter when starting the Phidget Webservice.
+ */
+ public final void open(int serial, String ipAddress, int port, String password) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenRemoteIP(serial, ipAddress, port, password);
+ }
+
+ /**
+ * Open this Phidget remotely using a Server ID, and a specific serial number.
+ * <p>
+ * This version of open is network based.
+ * <p>
+ * Open is pervasive. What this means is that you can call open on a device before it is plugged in,
+ * and on a server before it is running, and keep the device opened across device, and server dis- and re-connections.
+ * <p>
+ * Open is Asynchronous. What this means is that open will return immediately --
+ * before the device being opened is actually available, so you need to use either the {@link #addAttachListener(AttachListener l) attach event}
+ * or the {@link #waitForAttachment() waitForAttachment} method to determine if a device
+ * is available before using it.
+ * <p>
+ * This version of open specifies a serial number - The serial number is a unique number assigned to each Phidget
+ * during production and can be used to uniquely identify specific phidgets.
+ * use {@link #openAny(String) openAny(String serverID)} to open a device without specifying the serial number.
+ * <p>
+ * ServerID can be set to null, if the ServerID does not matter. In this case, the specified Phidget (by serial number) will be opened
+ * whenever it is seen on the network, regardless of which server it appears on. This also applies when not specifying a serial number.
+ * <p>
+ * Note: All open methods that specify a ServerID rather then an IP Addresss and Port require that both the client and host sides of the
+ * connection be running an implementation of zeroconf:
+ * <ul><li>On Windows, this means installing Apple's Bonjour - available <a href="http://www.apple.com/support/downloads/bonjourforwindows.html">here</a>.</li>
+ * <li>On Linux, this means Avahi, which is usually either installed by default or available as a package install.</li>
+ * <li>On MacOSX, Bonjour is already integrated into the operationg system.</li></ul>
+ *
+ * @param serial Serial Number
+ * @param serverID ServerID of the Phidget Webservice
+ */
+ public final void open(int serial, String serverID) throws PhidgetException
+ {
+ open(serial, serverID, "");
+ }
+
+ /**
+ * Open this Phidget remotely and securely, using a Server ID, and a specific serial number.
+ * <p>
+ * This method is the same as {@link #open(int, String) open(int serial, String serverID)}, except that it specifies a password.
+ * This password can be set as a parameter when starting the Phidget Webservice.
+ */
+ public final void open(int serial, String serverID, String password) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenRemote(serial, serverID, password);
+ }
+
+ /**
+ * Open a this Phidget without a serial number. This method is the same as {@link #open(int) open}, except that it specifies no serial number. Therefore, the first available
+ * Phidget will be opened. If there are two Phidgets of the same type attached to the system, you should specify a serial number, as
+ * there is no guarantee which Phidget will be selected by the call to openAny().
+ */
+ public final void openAny() throws PhidgetException {
+ open(-1);
+ }
+
+ /**
+ * Open this Phidget remotely using an IP Address, without a serial number.
+ * This method is the same as {@link #open(int, String, int) open(int serial, String ipAddress, int port)},
+ * except that it specifies no serial number. Therefore, the first available
+ * Phidget will be opened. If there are two Phidgets of the same type attached to the system, you should specify a serial number, as
+ * there is no guarantee which Phidget will be selected by the call to openAny().
+ */
+ public final void openAny(String ipAddress, int port) throws PhidgetException
+ {
+ open(-1, ipAddress, port, "");
+ }
+
+
+ /**
+ * Open this Phidget remotely and securely, using an IP Address, without a serial number.
+ * This method is the same as {@link #open(int, String, int, String) open(int serial, String ipAddress, int port, String password)},
+ * except that it specifies no serial number. Therefore, the first available
+ * Phidget will be opened. If there are two Phidgets of the same type attached to the system, you should specify a serial number, as
+ * there is no guarantee which Phidget will be selected by the call to openAny().
+ */
+ public final void openAny(String ipAddress, int port, String password) throws PhidgetException
+ {
+ open(-1, ipAddress, port, password);
+ }
+
+
+ /**
+ * Open this Phidget remotely using a Server ID, without a serial number.
+ * This method is the same as {@link #open(int, String) open(int serial, String serverID)},
+ * except that it specifies no serial number. Therefore, the first available
+ * Phidget will be opened. If there are two Phidgets of the same type attached to the system, you should specify a serial number, as
+ * there is no guarantee which Phidget will be selected by the call to openAny().
+ */
+ public final void openAny(String serverID) throws PhidgetException
+ {
+ open(-1, serverID, "");
+ }
+
+ /**
+ * Open this Phidget remotely and securely, using a Server ID, without a serial number.
+ * This method is the same as {@link #open(int, String, String) open(int serial, String serverID, String password)},
+ * except that it specifies no serial number. Therefore, the first available
+ * Phidget will be opened. If there are two Phidgets of the same type attached to the system, you should specify a serial number, as
+ * there is no guarantee which Phidget will be selected by the call to openAny().
+ */
+ public final void openAny(String serverID, String password) throws PhidgetException
+ {
+ open(-1, serverID, password);
+ }
+
+ /**
+ * Open this Phidget with a specific label.
+ * <p>
+ * Open is pervasive. What this means is that you can call open on a device before it is plugged in,
+ * and keep the device opened across device dis- and re-connections.
+ * <p>
+ * Open is Asynchronous. What this means is that open will return immediately --
+ * before the device being opened is actually available, so you need to use either the {@link #addAttachListener(AttachListener l) attach event}
+ * or the {@link #waitForAttachment() waitForAttachment} method to determine if a device
+ * is available before using it.
+ * <p>
+ * This version of open specifies a label - The label can be set and changed by using the setLabel method (setLabel is unsupported on Windows).
+ * use {@link #openAny() openAny} to open a device without specifying the label.
+ *
+ * @param label The Label
+ */
+ public final void openLabel(String label) throws PhidgetException {
+ enableEvents(true);
+ nativeOpenLabel(label);
+ }
+
+ /**
+ * Open this Phidget remotely using an IP Address, and a specific label.
+ * <p>
+ * This version of open is network based.
+ * <p>
+ * Open is pervasive. What this means is that you can call open on a device before it is plugged in,
+ * and on a server before it is running, and keep the device opened across device, and server dis- and re-connections.
+ * <p>
+ * Open is Asynchronous. What this means is that open will return immediately --
+ * before the device being opened is actually available, so you need to use either the {@link #addAttachListener(AttachListener l) attach event}
+ * or the {@link #waitForAttachment() waitForAttachment} method to determine if a device
+ * is available before using it.
+ * <p>
+ * This version of open specifies a label - The label can be set and changed by using the setLabel method (setLabel is unsupported on Windows).
+ * use {@link #openAny(String ipAddress, int port) openAny(String ipAddress, int port)} to open a device without specifying the label.
+ *
+ * @param label The Label
+ * @param ipAddress IP Address or hostname of the Phidget Webservice
+ * @param port Port of the Phidget Webservice
+ * @throws PhidgetException if the Phidget Webservice cannot be contacted
+ */
+ public final void openLabel(String label, String ipAddress, int port) throws PhidgetException
+ {
+ openLabel(label, ipAddress, port, "");
+ }
+ /**
+ * Open this Phidget remotely and securely, using an IP Address, and a specific label.
+ * <p>
+ * This method is the same as {@link #openLabel(String, String, int) openLabel(String label, String ipAddress, int port)}, except that it specifies a password.
+ * This password can be set as a parameter when starting the Phidget Webservice.
+ */
+ public final void openLabel(String label, String ipAddress, int port, String password) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenLabelRemoteIP(label, ipAddress, port, password);
+ }
+
+ /**
+ * Open this Phidget remotely using a Server ID, and a specific label.
+ * <p>
+ * This version of open is network based.
+ * <p>
+ * Open is pervasive. What this means is that you can call open on a device before it is plugged in,
+ * and on a server before it is running, and keep the device opened across device, and server dis- and re-connections.
+ * <p>
+ * Open is Asynchronous. What this means is that open will return immediately --
+ * before the device being opened is actually available, so you need to use either the {@link #addAttachListener(AttachListener l) attach event}
+ * or the {@link #waitForAttachment() waitForAttachment} method to determine if a device
+ * is available before using it.
+ * <p>
+ * This version of open specifies a label - The label can be set and changed by using the setLabel method (setLabel is unsupported on Windows).
+ * use {@link #openAny(String) openAny(String serverID)} to open a device without specifying the label.
+ * <p>
+ * ServerID can be set to null, if the ServerID does not matter. In this case, the specified Phidget (by label) will be opened
+ * whenever it is seen on the network, regardless of which server it appears on. This also applies when not specifying a label.
+ * <p>
+ * Note: All open methods that specify a ServerID rather then an IP Addresss and Port require that both the client and host sides of the
+ * connection be running an implementation of zeroconf:
+ * <ul><li>On Windows, this means installing Apple's Bonjour - available <a href="http://www.apple.com/support/downloads/bonjourforwindows.html">here</a>.</li>
+ * <li>On Linux, this means Avahi, which is usually either installed by default or available as a package install.</li>
+ * <li>On MacOSX, Bonjour is already integrated into the operationg system.</li></ul>
+ *
+ * @param label The Label
+ * @param serverID ServerID of the Phidget Webservice
+ */
+ public final void openLabel(String label, String serverID) throws PhidgetException
+ {
+ openLabel(label, serverID, "");
+ }
+
+ /**
+ * Open this Phidget remotely and securely, using a Server ID, and a specific label.
+ * <p>
+ * This method is the same as {@link #openLabel(String, String) openLabel(String label, String serverID)}, except that it specifies a password.
+ * This password can be set as a parameter when starting the Phidget Webservice.
+ */
+ public final void openLabel(String label, String serverID, String password) throws PhidgetException
+ {
+ enableEvents(true);
+ nativeOpenLabelRemote(label, serverID, password);
+ }
+
+ /**
+ * Closes this Phidget.
+ * This will shut down all threads dealing with this Phidget and you won't recieve any more events.
+ *
+ * @throws PhidgetException If this Phidget is not opened.
+ */
+ public final void close() throws PhidgetException {
+ if(!managerPhidget)
+ {
+ enableEvents(false);
+ nativeClose();
+ }
+ }
+
+ private void enableEvents(boolean b) {
+ enableAttachEvents(b && attachListeners.size() > 0);
+ enableDetachEvents(b && detachListeners.size() > 0);
+ enableErrorEvents(b && errorListeners.size() > 0);
+ enableServerConnectEvents(b && serverConnectListeners.size() > 0);
+ enableServerDisconnectEvents(b && serverDisconnectListeners.size() > 0);
+ enableDeviceSpecificEvents(b);
+ }
+
+ /**
+ * Waits for this Phidget to become available. This method can be called after open has been called
+ * to wait for thid Phidget to become available. This is usefull because open is asynchronous (and thus returns immediately),
+ * and most methods will throw a PhidgetException is they are called before a device is actually ready. This method is
+ * synonymous with polling the isAttached method until it returns True, or using the Attach event.
+ * <p>
+ * This method blocks for up to the timeout, at which point it will throw a PhidgetException. Otherwise, it returns when
+ * the phidget is attached and initialized.
+ * <p>
+ * A timeout of 0 is infinite.
+ *
+ * @param timeout Timeout in milliseconds
+ * @throws PhidgetException If this Phidget is not opened.
+ */
+ public final native void waitForAttachment(int timeout) throws PhidgetException;
+ /**
+ * Waits for this Phidget to become available. This method can be called after open has been called
+ * to wait for thid Phidget to become available. This is usefull because open is asynchronous (and thus returns immediately),
+ * and most methods will throw a PhidgetException is they are called before a device is actually ready. This method is
+ * synonymous with polling the isAttached method until it returns True, or using the Attach event.
+ * <p>
+ * This method blocks indefinitely until the Phidget becomes available. This can be quite some time
+ * (forever), if the Phidget is never plugged in.
+ *
+ * @throws PhidgetException If this Phidget is not opened.
+ */
+ public final void waitForAttachment() throws PhidgetException
+ {
+ waitForAttachment(0);
+ }
+
+ private void enableDeviceSpecificEvents(boolean b) { }
+
+ private LinkedList attachListeners = new LinkedList();
+ private long nativeAttachHandler = 0;
+
+ /**
+ * Adds an attach listener. The attach handler is a method that will be called when this Phidget is phisically attached
+ * to the system, and has gone through its initalization, and so is ready to be used.
+ * <p>
+ * There is no limit on the number of attach handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.AttachListener AttachListener} interface
+ */
+ public final void addAttachListener(AttachListener l) {
+ synchronized (attachListeners) {
+ attachListeners.add(l);
+ enableAttachEvents(true);
+ }
+ }
+
+ /**
+ * Removes an attach listener. This will remove a previously added attach listener.
+ */
+ public final void removeAttachListener(AttachListener l) {
+ synchronized (attachListeners) {
+ attachListeners.remove(l);
+ enableAttachEvents(attachListeners.size() > 0);
+ }
+ }
+ private void fireAttach(AttachEvent e) {
+ synchronized (attachListeners) {
+ for (Iterator it = attachListeners.iterator();
+ it.hasNext(); )
+ ((AttachListener)it.next()).attached(e);
+ }
+ }
+ private native void enableAttachEvents(boolean b);
+
+ private LinkedList errorListeners = new LinkedList();
+ private long nativeErrorHandler = 0;
+
+ /**
+ * Adds an error listener. The error handler is a method that will be called when an asynchronous error occurs.
+ * Error events are not currently used, but will be in the future to report any problems that happen out of context from
+ * a direct function call.
+ * <p>
+ * There is no limit on the number of error handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.ErrorListener ErrorListener} interface
+ */
+ public final void addErrorListener(ErrorListener l) {
+ synchronized (errorListeners) {
+ errorListeners.add(l);
+ enableErrorEvents(true);
+ }
+ }
+
+ /**
+ * Removes an error listener. This will remove a previously added error listener.
+ */
+ public final void removeErrorListener(ErrorListener l) {
+ synchronized (errorListeners) {
+ errorListeners.remove(l);
+ enableErrorEvents(errorListeners.size() > 0);
+ }
+ }
+ private void fireError(ErrorEvent e) {
+ synchronized (errorListeners) {
+ for (Iterator it = errorListeners.iterator();
+ it.hasNext(); )
+ ((ErrorListener)it.next()).error(e);
+ }
+ }
+ private native void enableErrorEvents(boolean b);
+
+ private LinkedList detachListeners = new LinkedList();
+ private long nativeDetachHandler = 0;
+
+ /**
+ * Adds a detach listener. The detach handler is a method that will be called when this Phidget is phisically detached
+ * from the system, and is no longer available. This is particularly usefull for applications when a phisical detach would be expected.
+ * <p>
+ * Remember that many of the methods, if called on an unattached device, will throw a PhidgetException. This Exception can be checked to see if it
+ * was caused by a device being unattached, but a better method would be to regiter the detach handler, which could notify the main program logic that
+ * the device is no longer available, disable GUI controls, etc.
+ * <p>
+ * There is no limit on the number of detach handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.DetachListener DetachListener} interface
+ */
+ public final void addDetachListener(DetachListener l) {
+ synchronized (detachListeners) {
+ detachListeners.add(l);
+ enableDetachEvents(true);
+ }
+ }
+ /**
+ * Removes a detach listener. This will remove a previously added detach listener.
+ */
+ public final void removeDetachListener(DetachListener l) {
+ synchronized (detachListeners) {
+ detachListeners.remove(l);
+ enableDetachEvents(detachListeners.size() > 0);
+ }
+ }
+ private void fireDetach(DetachEvent e) {
+ synchronized (detachListeners) {
+ for (Iterator it = detachListeners.iterator();
+ it.hasNext(); )
+ ((DetachListener)it.next()).detached(e);
+ }
+ }
+ private native void enableDetachEvents(boolean b);
+
+
+ private LinkedList serverConnectListeners = new LinkedList();
+ private long nativeServerConnectHandler = 0;
+
+ /**
+ * Adds an serverConnect listener. The serverConnect handler is a method that will be called when a connection to a server is made.
+ * This is only usefull for Phidgets opened remotely.
+ * <p>
+ * There is no limit on the number of serverConnect handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.ServerConnectListener ServerConnectListener} interface
+ */
+ public final void addServerConnectListener(ServerConnectListener l)
+ {
+ synchronized (serverConnectListeners)
+ {
+ serverConnectListeners.add(l);
+ enableServerConnectEvents(true);
+ }
+ }
+
+ /**
+ * Removes an serverConnect listener. This will remove a previously added serverConnect listener.
+ */
+ public final void removeServerConnectListener(ServerConnectListener l)
+ {
+ synchronized (serverConnectListeners)
+ {
+ serverConnectListeners.remove(l);
+ enableServerConnectEvents(serverConnectListeners.size() > 0);
+ }
+ }
+ private void fireServerConnect(ServerConnectEvent e)
+ {
+ synchronized (serverConnectListeners)
+ {
+ for (Iterator it = serverConnectListeners.iterator();
+ it.hasNext(); )
+ ((ServerConnectListener)it.next()).serverConnected(e);
+ }
+ }
+ private native void enableServerConnectEvents(boolean b);
+
+
+ private LinkedList serverDisconnectListeners = new LinkedList();
+ private long nativeServerDisconnectHandler = 0;
+
+ /**
+ * Adds an serverDisconnect listener. The serverDisconnect handler is a method that will be called when a connection to a server is terminated.
+ * This is only usefull for Phidgets opened remotely.
+ * <p>
+ * There is no limit on the number of serverDisconnect handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.ServerDisconnectListener ServerDisconnectListener} interface
+ */
+ public final void addServerDisconnectListener(ServerDisconnectListener l)
+ {
+ synchronized (serverDisconnectListeners)
+ {
+ serverDisconnectListeners.add(l);
+ enableServerDisconnectEvents(true);
+ }
+ }
+
+ /**
+ * Removes an serverDisconnect listener. This will remove a previously added serverDisconnect listener.
+ */
+ public final void removeServerDisconnectListener(ServerDisconnectListener l)
+ {
+ synchronized (serverDisconnectListeners)
+ {
+ serverDisconnectListeners.remove(l);
+ enableServerDisconnectEvents(serverDisconnectListeners.size() > 0);
+ }
+ }
+ private void fireServerDisconnect(ServerDisconnectEvent e)
+ {
+ synchronized (serverDisconnectListeners)
+ {
+ for (Iterator it = serverDisconnectListeners.iterator();
+ it.hasNext(); )
+ ((ServerDisconnectListener)it.next()).serverDisconnected(e);
+ }
+ }
+ private native void enableServerDisconnectEvents(boolean b);
+
+ /**
+ * Return a Sring describing this Phidget.
+ */
+ public String toString() {
+ int dv = -1;
+ int sn = -1;
+ String dt = null;
+ String at = "";
+
+ try {
+ dv = getDeviceVersion();
+ sn = getSerialNumber();
+ dt = getDeviceType();
+ at = isAttached() ? " (attached)" : " (unattached)";
+ } catch (PhidgetException e) {
+ ;
+ } finally {
+ if (dt == null)
+ dt = getClass().getName().replaceFirst(
+ ".*\\.", "");
+ }
+ return dt + " v" + dv + " #" + sn + at;
+ }
+
+ protected void finalize() throws Throwable
+ {
+ try
+ {
+ if(!managerPhidget)
+ {
+ try
+ {
+ close();
+ }
+ catch (Exception e)
+ {
+ ;
+ }
+ try
+ {
+ nativeDelete();
+ }
+ catch (Exception e)
+ {
+ ;
+ }
+ }
+ }
+ finally
+ {
+ handle = 0;
+ super.finalize();
+ }
+ }
+
+ /**
+ * Compares two Phidgets. This method compares two Phidgets using serial number, device type and version.
+ */
+ public boolean equals(Object comp)
+ {
+ Phidget temp = (Phidget)comp;
+ try
+ {
+ if (temp.getSerialNumber() == getSerialNumber() && temp.getDeviceType().equals(getDeviceType()) &&
+ temp.getDeviceVersion() == getDeviceVersion())
+ return true;
+ }
+ catch (Exception e) { }
+ return false;
+ }
+}
diff --git a/Java/com/phidgets/PhidgetException.java b/Java/com/phidgets/PhidgetException.java
new file mode 100644
index 0000000..f33d345
--- /dev/null
+++ b/Java/com/phidgets/PhidgetException.java
@@ -0,0 +1,337 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets;
+
+/**
+ * This class represents Phidget related exceptions. All Phidget exceptions originate in the phidget21 C library.
+ * These exceptions can be thrown by most function in the library and cover such things as trying to access
+ * a Phidget before opening it, or before it is attached and ready to use, out of bounds Index and data values,
+ * trying to read data that isn't available, and other less common problems. EPHIDGET_(error) errors are thrown
+ * by any API calls, EEPHIDGET_(error) errors are returned via the {@link com.phidgets.event.ErrorEvent Error} event.
+ */
+public class PhidgetException extends java.lang.Exception {
+ private int errno;
+ private String description;
+
+ /**
+ * Constructor which takes in an error number and description.
+ * These exceptions originate from and are filled in by the phidget 21 C library.
+ */
+ public PhidgetException(int errno, String description) {
+ this.description = description;
+ this.errno = errno;
+ }
+
+ /**
+ * Phidget not found exception. "A Phidget matching the type and or serial number could not be found."
+ * <P>
+ * This exception is not currently used externally.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_NOTFOUND = 1;
+ /**
+ * No memory exception. "Memory could not be allocated."
+ * <P>
+ * This exception is thrown when a memory allocation (malloc) call fails in the c library.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_NOMEMORY = 2;
+ /**
+ * Unexpected exception. "Unexpected Error. Contact Phidgets Inc. for support."
+ * <P>
+ * This exception is thrown when something unexpected happens (more enexpected then another exception). This generally
+ * points to a bug or bad code in the C library, and hopefully won't even be seen.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_UNEXPECTED = 3;
+ /**
+ * Invalid argument exception. "Invalid argument passed to function."
+ * <P>
+ * This exception is thrown whenever a function recieves an unexpected null pointer, or a value that is out of range. ie setting a motor's speed to 101 when the maximum is 100.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_INVALIDARG = 4;
+ /**
+ * Phidget not attached exception. "Phidget not physically attached."
+ * <P>
+ * This exception is thrown when a method is called on a device that is not attached, and the method requires the device to be attached. ie trying to read the serial number, or
+ * the state of an ouput.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_NOTATTACHED = 5;
+ /**
+ * Interrupted exception. "Read/Write operation was interrupted."
+ * <P>
+ * This exception is not currently used externally.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_INTERRUPTED = 6;
+ /**
+ * Invalid error exception. "The Error Code is not defined."
+ * <P>
+ * This exception is thrown when trying to get the string description of an undefined error code. This should not be seen in Java.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_INVALID = 7;
+ /**
+ * Network exception. "Network Error."
+ * <P>
+ * This exception is thrown when a network related error occurs. The {@link #EEPHIDGET_NETWORK EEPHIDGET_NETWORK} code is more often used (in error events)
+ * because most network exceptions come through asynchronously.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_NETWORK = 8;
+ /**
+ * Value unknown exception. "Value is Unknown (State not yet received from device, or not yet set by user)."
+ * <P>
+ * This exception is thrown when a device that is set to unknow is read. ie trying to read the position of a servo before setting it's position.
+ * <p>
+ * Every effort is made in the library to fill in as much of a device's state before the attach event gets thrown, however, many there are some states
+ * that cannot be filled in automatically. ie older interface kits do not return their output states, and so these will be unknown until they are set.
+ * <p>
+ * This is a quite common exception for some devices, and so should always be caught
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_UNKNOWNVAL = 9;
+ /**
+ * Authorization exception. "Authorization Failed."
+ * <P>
+ * This exception has been replaced by {@link #EEPHIDGET_BADPASSWORD EEPHIDGET_BADPASSWORD}.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_BADPASSWORD = 10;
+ /**
+ * Unsupported exception. "Not Supported."
+ * <P>
+ * This exception is thrown when a method is called that is not supported, either by that device, or by the system. ie calling setRatiometric on an interfaceKit that does not have sensors.
+ * <p>
+ * This is also used for methods that are not yet complete, ie setLabel on Windows.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_UNSUPPORTED = 11;
+ /**
+ * Duplicate request exception. "Duplicated request."
+ * <P>
+ * This exception is thrown when open is called twice on a device, without calling close in between. The second call to open is ignored.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_DUPLICATE = 12;
+ /**
+ * Timeout exception. "Given timeout has been exceeded."
+ * <P>
+ * This exception is thrown by {@link com.phidgets.Phidget#waitForAttachment(int) waitForAttachment(int)} if the provided timeout expires before an attach happens.
+ * This may also be thrown by a device set request, if the set times out - though this should not happen, and would generally mean a problem with the device.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_TIMEOUT = 13;
+ /**
+ * Out of bounds exception. "Index out of Bounds."
+ * <P>
+ * This exception is thrown anytime an indexed set or get method is called with an out of bounds index.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_OUTOFBOUNDS = 14;
+ /**
+ * Event exception. "A non-null error code was returned from an event handler."
+ * <P>
+ * This exception is not currently used.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_EVENT = 15;
+ /**
+ * Network not connected exception. "A connection to the server does not exist."
+ * <P>
+ * This exception is thrown when a network specific method is called on a device that was opened remotely, but there is no connection to a server. ie getServerID.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_NETWORK_NOTCONNECTED = 16;
+ /**
+ * Wrong device exception. "Function is not applicable for this device."
+ * <P>
+ * This exception is thrown when a method from device is called by another device. ie casting an InterfaceKit to a Servo and calling setPosition.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_WRONGDEVICE = 17;
+ /**
+ * Phidget closed exception. "Phidget handle was closed."
+ * <P>
+ * This exception is thrown when {@link com.phidgets.Phidget#waitForAttachment waitForAttachment} is called on a Phidget that has not been opened, or was closed.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_CLOSED = 18;
+ /**
+ * Version mismatch exception. "Webservice and Client protocol versions don't match. Update to newest release."
+ * <P>
+ * This exception has been replaced by {@link #EEPHIDGET_BADVERSION EEPHIDGET_BADVERSION}.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EPHIDGET_BADVERSION = 19;
+
+
+ //Error Event codes
+
+ /**
+ * Network exception. "Network Error."
+ * <P>
+ * This exception is sent via the {@link com.phidgets.event.ErrorEvent Error} event. It will be accompanied by a specific Description of the network problem.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EEPHIDGET_NETWORK = 0x8001;
+ /**
+ * Authorization exception. "Authorization Failed."
+ * <P>
+ * This exception is sent via the {@link com.phidgets.event.ErrorEvent Error} event. It means that a connection could not be authenticated because of a passwrod missmatch.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EEPHIDGET_BADPASSWORD = 0x8002;
+ /**
+ * Version mismatch exception. "Webservice and Client protocol versions don't match. Update to newest release."
+ * <P>
+ * This exception is sent via the {@link com.phidgets.event.ErrorEvent Error} event when trying to connect to a remote phidget and the webservice version does not match your client library version.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EEPHIDGET_BADVERSION = 0x8003;
+ /**
+ * Overrun exception. "A sampling overrun happend in firmware."
+ * <P>
+ * This exception sent via in the {@link com.phidgets.event.ErrorEvent Error} event. It is accompanied by a specific {@link #getDescription description}.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EEPHIDGET_OVERRUN = 0x9002;
+ /**
+ * Packet lost exception. "One or more packets were lost."
+ * <P>
+ * This exception sent via in the {@link com.phidgets.event.ErrorEvent Error} event. It is accompanied by a specific {@link #getDescription description}.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EEPHIDGET_PACKETLOST = 0x9003;
+ /**
+ * Wraparound exception. "A variable has wrapped around."
+ * <P>
+ * This exception sent via in the {@link com.phidgets.event.ErrorEvent Error} event. It is accompanied by a specific {@link #getDescription description}.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EEPHIDGET_WRAP = 0x9004;
+ /**
+ * Overtemperature exception. "Overtemperature condition detected."
+ * <P>
+ * This exception sent via in the {@link com.phidgets.event.ErrorEvent Error} event. It is accompanied by a specific {@link #getDescription description}.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EEPHIDGET_OVERTEMP = 0x9005;
+ /**
+ * Overcurrent exception. "Overcurrent condition detected."
+ * <P>
+ * This exception sent via in the {@link com.phidgets.event.ErrorEvent Error} event. It is accompanied by a specific {@link #getDescription description}.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EEPHIDGET_OVERCURRENT = 0x9006;
+ /**
+ * Out of range exception. "Out of range condition detected."
+ * <P>
+ * This exception sent via in the {@link com.phidgets.event.ErrorEvent Error} event. It is accompanied by a specific {@link #getDescription description}.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EEPHIDGET_OUTOFRANGE = 0x9007;
+ /**
+ * Bad power exception. "Power supply problem detected."
+ * <P>
+ * This exception sent via in the {@link com.phidgets.event.ErrorEvent Error} event. It is accompanied by a specific {@link #getDescription description}.
+ * <p>
+ * This is returned by {@link #getErrorNumber getErrorNumber}
+ */
+ public static final int EEPHIDGET_BADPOWER = 0x9008;
+
+ /**
+ * Returns the error number of this exception. This error number will match one of the EPHIDGET_(error) or EEPHIDGET_(error) constants defined in this class.
+ * These numbers are defined in the phidget21 c library and are consistent across all APIs.
+ * <p>
+ * There are 19 error codes defined, as follows:
+ * <br>
+ * {@link #EPHIDGET_NOTFOUND EPHIDGET_NOTFOUND},
+ * {@link #EPHIDGET_NOMEMORY EPHIDGET_NOMEMORY},
+ * {@link #EPHIDGET_UNEXPECTED EPHIDGET_UNEXPECTED},
+ * {@link #EPHIDGET_INVALIDARG EPHIDGET_INVALIDARG},
+ * {@link #EPHIDGET_NOTATTACHED EPHIDGET_NOTATTACHED},
+ * {@link #EPHIDGET_INTERRUPTED EPHIDGET_INTERRUPTED},
+ * {@link #EPHIDGET_INVALID EPHIDGET_INVALID},
+ * {@link #EPHIDGET_NETWORK EPHIDGET_NETWORK},
+ * {@link #EPHIDGET_UNKNOWNVAL EPHIDGET_UNKNOWNVAL},
+ * {@link #EPHIDGET_BADPASSWORD EPHIDGET_BADPASSWORD},
+ * {@link #EPHIDGET_UNSUPPORTED EPHIDGET_UNSUPPORTED},
+ * {@link #EPHIDGET_DUPLICATE EPHIDGET_DUPLICATE},
+ * {@link #EPHIDGET_TIMEOUT EPHIDGET_TIMEOUT},
+ * {@link #EPHIDGET_OUTOFBOUNDS EPHIDGET_OUTOFBOUNDS},
+ * {@link #EPHIDGET_EVENT EPHIDGET_EVENT},
+ * {@link #EPHIDGET_NETWORK_NOTCONNECTED EPHIDGET_NETWORK_NOTCONNECTED},
+ * {@link #EPHIDGET_WRONGDEVICE EPHIDGET_WRONGDEVICE},
+ * {@link #EPHIDGET_CLOSED EPHIDGET_CLOSED} and
+ * {@link #EPHIDGET_BADVERSION EPHIDGET_BADVERSION}</pre>
+ * <p>
+ * There are also 9 error event codes defined, as follows:
+ * <br>
+ * {@link #EEPHIDGET_NETWORK EEPHIDGET_NETWORK},
+ * {@link #EEPHIDGET_BADPASSWORD EEPHIDGET_BADPASSWORD},
+ * {@link #EEPHIDGET_BADVERSION EEPHIDGET_BADVERSION},
+ * {@link #EEPHIDGET_OVERRUN EEPHIDGET_OVERRUN},
+ * {@link #EEPHIDGET_PACKETLOST EEPHIDGET_PACKETLOST},
+ * {@link #EEPHIDGET_WRAP EEPHIDGET_WRAP},
+ * {@link #EEPHIDGET_OVERTEMP EEPHIDGET_OVERTEMP},
+ * {@link #EEPHIDGET_OVERCURRENT EEPHIDGET_OVERCURRENT},
+ * {@link #EEPHIDGET_OUTOFRANGE EEPHIDGET_OUTOFRANGE}</pre>
+ *
+ * @return The error code
+ */
+ public int getErrorNumber() {
+ return errno;
+ }
+
+ /**
+ * Returns a description of this exception. This is an english phrase that describes the exception that
+ * occured. These strings originate in the base phidget21 C library, and should help to diagnose problems.
+ *
+ * @return The error description
+ */
+ public String getDescription() {
+ return description;
+ }
+
+ /**
+ * Returns a string containing the error number and exception description.
+ *
+ * @return A string describing the error
+ */
+ public String toString() {
+ return "PhidgetException " + errno + " (" + description + ")";
+ }
+}
diff --git a/Java/com/phidgets/RFIDPhidget.java b/Java/com/phidgets/RFIDPhidget.java
new file mode 100644
index 0000000..b102b67
--- /dev/null
+++ b/Java/com/phidgets/RFIDPhidget.java
@@ -0,0 +1,197 @@
+
+/*
+ * Copyright 2006 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 RFID Reader. All methods
+ * to read tags and set outputs on the RFID reader are implemented in this class.
+ * <p>
+ * The Phidget RFID reader can read one tag at a time. Both tag and tagloss event handlers are provided,
+ * as well as control over the antenna so that multiple readers can exists in close proximity without interference.
+ *
+ * @author Phidgets Inc.
+ */
+public final class RFIDPhidget extends Phidget
+{
+ public RFIDPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+ /**
+ * Returns the number of outputs. These are the outputs provided by the terminal block.
+ * Older RFID readers do not have these outputs, and this method will return 0.
+ * @return number of outputs
+ * @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 getOutputCount () throws PhidgetException;
+ /**
+ * Returns the state of an output. True indicated activated, False deactivated, which is the default.
+ * @param index index of the output
+ * @return state of the output
+ * @throws PhidgetException If this Phidget is not opened and attached, or 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 boolean getOutputState (int index) throws PhidgetException;
+ /**
+ * Sets the state of a digital output. True indicated activated, False deactivated, which is the default.
+ * @param index index of the output
+ * @param state desired state
+ * @throws PhidgetException If this Phidget is not opened and attached, or 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 void setOutputState (int index, boolean state) throws PhidgetException;
+ /**
+ * Returns the state of the antenna. True indicated that the antenna is active, False indicated inactive.
+ * @return state of the antenna
+ * @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 boolean getAntennaOn () throws PhidgetException;
+ /**
+ * Sets the state of the antenna. True turns the antenna on, False turns it off. The antenna if by default
+ * turned off, and needs to be explicitely activated before tags can be read. Control over the antenna
+ * allows multiple readers to be used in close proximity, as multiple readers will interfere with each other if
+ * their antenna's are activated simultaneously.
+ * @param state new state for the antenna
+ * @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 void setAntennaOn (boolean state) throws PhidgetException;
+ /**
+ * Returns the state of the onboard LED. This LED is by default turned off.
+ * @return state of the LED
+ * @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 boolean getLEDOn () throws PhidgetException;
+ /**
+ * Sets the state of the onboard LED. True turns the LED on, False turns it off. The LED is by default turned off.
+ * @param state new state for the LED
+ * @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 void setLEDOn (boolean state) throws PhidgetException;
+ /**
+ * Returns the last tag read. This method will only return a valid tag after a tag has been seen.
+ * This method can be used even after a tag has been removed from the reader
+ * @return tag
+ * @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 String getLastTag () throws PhidgetException;
+ /**
+ * Returns the state of whether or not a tag is being read by the reader.
+ * True indicated that a tag is on (or near) the reader, false indicates that one is not.
+ * @return tag read state
+ * @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 boolean getTagStatus () throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableTagGainEvents (b && tagGainListeners.size () > 0);
+ enableTagLossEvents (b && tagLossListeners.size () > 0);
+ enableOutputChangeEvents (b && outputChangeListeners.size () > 0);
+ }
+ /**
+ * Adds a tag gained listener. The tag gaiend handler is a method that will be called when a new tag is
+ seen by the reader. The event is only fired one time for a new tag, so the tag has to be removed and then replaced before
+ another tag gained event will fire.
+ * <p>
+ * There is no limit on the number of tag gained change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.TagGainListener TagGainListener} interface
+ */
+ public final void addTagGainListener (TagGainListener l)
+ {
+ synchronized (tagGainListeners)
+ {
+ tagGainListeners.add (l);
+ enableTagGainEvents (true);
+ }} private LinkedList tagGainListeners = new LinkedList ();
+ private long nativeTagGainHandler = 0;
+ public final void removeTagGainListener (TagGainListener l)
+ {
+ synchronized (tagGainListeners)
+ {
+ tagGainListeners.remove (l);
+ enableTagGainEvents (tagGainListeners.size () > 0);
+ }} private void fireTagGain (TagGainEvent e)
+ {
+ synchronized (tagGainListeners)
+ {
+ for (Iterator it = tagGainListeners.iterator (); it.hasNext ();)
+ ((TagGainListener) it.next ()).tagGained (e);
+ }
+ }
+ private native void enableTagGainEvents (boolean b);
+ /**
+ * Adds a tag lost listener. The tag lost handler is a method that will be called when a tag is
+ removed from the reader.
+ * <p>
+ * There is no limit on the number of tag lost change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.TagLossListener TagLossListener} interface
+ */
+ public final void addTagLossListener (TagLossListener l)
+ {
+ synchronized (tagLossListeners)
+ {
+ tagLossListeners.add (l);
+ enableTagLossEvents (true);
+ }} private LinkedList tagLossListeners = new LinkedList ();
+ private long nativeTagLossHandler = 0;
+ public final void removeTagLossListener (TagLossListener l)
+ {
+ synchronized (tagLossListeners)
+ {
+ tagLossListeners.remove (l);
+ enableTagLossEvents (tagLossListeners.size () > 0);
+ }} private void fireTagLoss (TagLossEvent e)
+ {
+ synchronized (tagLossListeners)
+ {
+ for (Iterator it = tagLossListeners.iterator (); it.hasNext ();)
+ ((TagLossListener) it.next ()).tagLost (e);
+ }
+ }
+ private native void enableTagLossEvents (boolean b);
+ /**
+ * Adds an output change listener. The output change handler is a method that will be called when an output has changed.
+ * <p>
+ * There is no limit on the number of output change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.OutputChangeListener OutputChangeListener} interface
+ */
+ public final void addOutputChangeListener (OutputChangeListener l)
+ {
+ synchronized (outputChangeListeners)
+ {
+ outputChangeListeners.add (l);
+ enableOutputChangeEvents (true);
+ }} private LinkedList outputChangeListeners = new LinkedList ();
+ private long nativeOutputChangeHandler = 0;
+ public final void removeOutputChangeListener (OutputChangeListener l)
+ {
+ synchronized (outputChangeListeners)
+ {
+ outputChangeListeners.remove (l);
+ enableOutputChangeEvents (outputChangeListeners.size () > 0);
+ }} private void fireOutputChange (OutputChangeEvent e)
+ {
+ synchronized (outputChangeListeners)
+ {
+ for (Iterator it = outputChangeListeners.iterator (); it.hasNext ();)
+ ((OutputChangeListener) it.next ()).outputChanged (e);
+ }
+ }
+ private native void enableOutputChangeEvents (boolean b);
+}
diff --git a/Java/com/phidgets/ServoPhidget.java b/Java/com/phidgets/ServoPhidget.java
new file mode 100644
index 0000000..aa9f05f
--- /dev/null
+++ b/Java/com/phidgets/ServoPhidget.java
@@ -0,0 +1,286 @@
+
+/*
+ * Copyright 2006 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 servo Controller. All methods
+ * to control a Servo Controller are implemented in this class.
+ * <p>
+ * The Phidget Sevo controller simply outputs varying widths of PWM, which is what
+ * most servo motors take as an input driving signal.
+ *
+ * @author Phidgets Inc.
+ */
+public final class ServoPhidget extends Phidget
+{
+ public ServoPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+
+ /**
+ * Default - This is what the servo API been historically used, originally based on the Futaba FP-S148. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_DEFAULT = 1;
+ /**
+ * Raw us mode - all position, velocity, acceleration functions are specified in microseconds rather then degrees. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_RAW_us_MODE = 2;
+ /**
+ * HiTec HS-322HD Standard Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS322HD = 3;
+ /**
+ * HiTec HS-5245MG Digital Mini Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS5245MG = 4;
+ /**
+ * HiTec HS-805BB Mega Quarter Scale Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_805BB = 5;
+ /**
+ * HiTec HS-422 Standard Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS422 = 6;
+ /**
+ * Tower Pro MG90 Micro Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_TOWERPRO_MG90 = 7;
+ /**
+ * HiTec HSR-1425CR Continuous Rotation Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HSR1425CR = 8;
+ /**
+ * HiTec HS-785HB Sail Winch Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS785HB = 9;
+ /**
+ * HiTec HS-485HB Deluxe Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS485HB = 10;
+ /**
+ * HiTec HS-645MG Ultra Torque Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_HS645MG = 11;
+ /**
+ * HiTec HS-815BB Mega Sail Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_HITEC_815BB = 12;
+ /**
+ * Firgelli L12 Linear Actuator 30mm 50:1. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_FIRGELLI_L12_30_50_06_R = 13;
+ /**
+ * Firgelli L12 Linear Actuator 50mm 100:1. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_FIRGELLI_L12_50_100_06_R = 14;
+ /**
+ * Firgelli L12 Linear Actuator 50mm 210:1. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_FIRGELLI_L12_50_210_06_R = 15;
+ /**
+ * Firgelli L12 Linear Actuator 100mm 50:1. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_FIRGELLI_L12_100_50_06_R = 16;
+ /**
+ * Firgelli L12 Linear Actuator 100mm 100:1. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_FIRGELLI_L12_100_100_06_R = 17;
+ /**
+ * SpringRC SM-S2313M Micro Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S2313M = 18;
+ /**
+ * SpringRC SM-S3317M Small Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S3317M = 19;
+ /**
+ * SpringRC SM-S3317SR Small Continuous Rotation Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S3317SR = 20;
+ /**
+ * SpringRC SM-S4303R Standard Continuous Rotation Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S4303R = 21;
+ /**
+ * SpringRC SM-S4315M High Torque Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S4315M = 22;
+ /**
+ * SpringRC SM-S4315R High Torque Continuous Rotation Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S4315R = 23;
+ /**
+ * SpringRC SM-S4505B Standard Servo. This is used with {@link #getServoType getServoType} and {@link #setServoType setServoType}
+ */
+ public static final int PHIDGET_SERVO_SPRINGRC_SM_S4505B = 24;
+ /**
+ * User Defined servo parameters. This is used with {@link #getServoType getServoType}
+ */
+ public static final int PHIDGET_SERVO_USER_DEFINED = 25;
+
+ /**
+ * Returns the number of motors this Phidget can support. Note that there is no way of programatically
+ * determining how many motors are actaully attached to the board.
+ * @return number of motors
+ */
+ public native int getMotorCount () throws PhidgetException;
+ /**
+ * Returns the position of a servo motor. Note that since servo motors do not offer any feedback in their interface,
+ * this value is simply whatever the servo was last set to. There is no way of determining the position of a servo
+ * that has been plugged in, until it's position has been set. Therefore, if an initial position is important, it
+ * should be set as part of initialization.
+ * <p>
+ * If the servo is not engaged, the position is unknown and calling this function will throw an exception.
+ * <p>
+ * The range here is between {@link #getPositionMin getPositionMin} and {@link #getPositionMax getPositionMax},
+ * and corresponds aproximately to an angle in degrees. Note that most servos will not be able to operate
+ * accross this entire range.
+ * @param index index of the motor
+ * @return current position of the selected motor
+ * @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 getPosition (int index) throws PhidgetException;
+ /**
+ * Returns the maximum position that a servo will accept, or return.
+ * @param index Index of the servo
+ * @return Maximum position in degrees
+ * @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 double getPositionMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum position that a servo will accept, or return.
+ * @param index Index of the servo
+ * @return Minimum position in degrees
+ * @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 double getPositionMin (int index) throws PhidgetException;
+ /**
+ * Sets the position of a servo motor.
+ * <p>
+ * The range here is between {@link #getPositionMin getPositionMin} and {@link #getPositionMax getPositionMax},
+ * and corresponds aproximately to an angle in degrees. Note that most servos will not be able to operate
+ * accross this entire range. Typically, the range might be 25 - 180 degrees, but this depends on the servo
+ * @param index index of the motor
+ * @param position desired position
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index or position is out of range.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setPosition (int index, double position) throws PhidgetException;
+ /**
+ * Engage or disengage a servo motor.
+ * <p>
+ * This engages or disengages the servo. The motor is engaged whenever you set a position,
+ * use this function to disengage, and reengage without setting a position.
+ *
+ * @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 void setEngaged (int index, boolean state) throws PhidgetException;
+ /**
+ * @deprecated Replaced by
+ * {@link #setEngaged}
+ */
+ public native void setMotorOn (int index, boolean state) throws PhidgetException;
+ /**
+ * Returns the engaged state or a servo.
+ *
+ * @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 boolean getEngaged (int index) throws PhidgetException;
+ /**
+ * @deprecated Replaced by
+ * {@link #getEngaged}
+ */
+ public native boolean getMotorOn (int index) throws PhidgetException;
+ /**
+ * Returns the servo type for an index.
+ * The possible values for type are {@link #PHIDGET_SERVO_DEFAULT PHIDGET_SERVO_DEFAULT},
+ * {@link #PHIDGET_SERVO_RAW_us_MODE PHIDGET_SERVO_RAW_us_MODE}, {@link #PHIDGET_SERVO_HITEC_HS322HD PHIDGET_SERVO_HITEC_HS322HD},
+ * {@link #PHIDGET_SERVO_HITEC_HS5245MG PHIDGET_SERVO_HITEC_HS5245MG}, {@link #PHIDGET_SERVO_HITEC_805BB PHIDGET_SERVO_HITEC_805BB},
+ * {@link #PHIDGET_SERVO_HITEC_HS422 PHIDGET_SERVO_HITEC_HS422}, etc.
+ * @param index Input
+ * @return Servo Type
+ * @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 int getServoType (int index) throws PhidgetException;
+ /**
+ * Sets the servo type for an index.
+ * <p>
+ * This constrains the PCM to the valid range of the servo, and sets the degrees-to-PCM ratio to match the actual servo rotation.
+ * <p>
+ * The possible values for type are {@link #PHIDGET_SERVO_DEFAULT PHIDGET_SERVO_DEFAULT},
+ * {@link #PHIDGET_SERVO_RAW_us_MODE PHIDGET_SERVO_RAW_us_MODE}, {@link #PHIDGET_SERVO_HITEC_HS322HD PHIDGET_SERVO_HITEC_HS322HD},
+ * {@link #PHIDGET_SERVO_HITEC_HS5245MG PHIDGET_SERVO_HITEC_HS5245MG}, {@link #PHIDGET_SERVO_HITEC_805BB PHIDGET_SERVO_HITEC_805BB},
+ * {@link #PHIDGET_SERVO_HITEC_HS422 PHIDGET_SERVO_HITEC_HS422}, etc.
+ * <p>
+ * Support for other servo types can be achieved by using {@link #setServoParameters setServoParameters}.
+ * <p>
+ * The default setting is {@link #PHIDGET_SERVO_DEFAULT PHIDGET_SERVO_DEFAULT}, which is used for historical (backwards compatibility) reasons.
+ * @param index Input
+ * @param type Servo Type
+ * @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 void setServoType (int index, int type) throws PhidgetException;
+ /**
+ * Sets the servo parameters for a custom servo definition.
+ * <p>
+ * This constrains the PCM to the valid range of the servo, and sets the degrees-to-PCM ratio to match the actual servo rotation.
+ * <p>
+ * @param index Servo Index
+ * @param minUs Minimum PCM supported in microseconds
+ * @param maxUs Maximum PCM supported in microseconds
+ * @param degrees Degrees of rotation represented by the given PCM range
+ * @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 void setServoParameters (int index, double minUs, double maxUs, double degrees) throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableServoPositionChangeEvents (b && servoPositionChangeListeners.size () > 0);
+ }
+ /**
+ * Adds a servo position change listener. The servo position change handler is a method that will be called when the servo position
+ * has changed. The event will get fired after every call to {@link #setPosition(int, double) setPosition}.
+ * <p>
+ * There is no limit on the number of servo position change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.ServoPositionChangeListener ServoPositionChangeListener} interface
+ */
+ public final void addServoPositionChangeListener (ServoPositionChangeListener l)
+ {
+ synchronized (servoPositionChangeListeners)
+ {
+ servoPositionChangeListeners.add (l);
+ enableServoPositionChangeEvents (true);
+ }} private LinkedList servoPositionChangeListeners = new LinkedList ();
+ private long nativeServoPositionChangeHandler = 0;
+ public final void removeServoPositionChangeListener (ServoPositionChangeListener l)
+ {
+ synchronized (servoPositionChangeListeners)
+ {
+ servoPositionChangeListeners.remove (l);
+ enableServoPositionChangeEvents (servoPositionChangeListeners.size () > 0);
+ }} private void fireServoPositionChange (ServoPositionChangeEvent e)
+ {
+ synchronized (servoPositionChangeListeners)
+ {
+ for (Iterator it = servoPositionChangeListeners.iterator (); it.hasNext ();)
+ ((ServoPositionChangeListener) it.next ()).servoPositionChanged (e);
+ }
+ }
+ private native void enableServoPositionChangeEvents (boolean b);
+}
diff --git a/Java/com/phidgets/SpatialEventData.java b/Java/com/phidgets/SpatialEventData.java
new file mode 100644
index 0000000..0f7f9c9
--- /dev/null
+++ b/Java/com/phidgets/SpatialEventData.java
@@ -0,0 +1,101 @@
+
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets;
+/**
+ * This class represents an a set of spatial data. It's used in the SpatialData event.
+ *
+ * @author Phidget Inc.
+ */
+public final class SpatialEventData
+{
+ private double[] acceleration;
+ private double[] angularRate;
+ private double[] magneticField;
+ private int timeSeconds, timeMicroSeconds;
+
+ /**
+ * Creates a new SpatialEventData object.
+ * @param acceleration the acceleration data
+ * @param angularRate the gyro data
+ * @param magneticField the compass data
+ * @param timeSeconds the timestamp in seconds
+ * @param timeMicroSeconds the time since the last second in microseconds
+ */
+ public SpatialEventData(double[] acceleration, double[] angularRate, double[] magneticField, int timeSeconds, int timeMicroSeconds)
+ {
+ this.acceleration = new double[acceleration.length];
+ this.angularRate = new double[angularRate.length];
+ this.magneticField = new double[magneticField.length];
+ for(int i=0;i<acceleration.length;i++)
+ this.acceleration[i] = acceleration[i];
+ for(int i=0;i<angularRate.length;i++)
+ this.angularRate[i] = angularRate[i];
+ for(int i=0;i<magneticField.length;i++)
+ this.magneticField[i] = magneticField[i];
+ this.timeSeconds = timeSeconds;
+ this.timeMicroSeconds = timeMicroSeconds;
+ }
+
+ /**
+ * Returns the acceleration data.
+ * @return acceleration data
+ */
+ public double[] getAcceleration()
+ {
+ return acceleration;
+ }
+
+ /**
+ * Returns the angularRate data.
+ * @return angularRate data
+ */
+ public double[] getAngularRate()
+ {
+ return angularRate;
+ }
+
+ /**
+ * Returns the magneticField data.
+ * @return magneticField data
+ */
+ public double[] getMagneticField()
+ {
+ return magneticField;
+ }
+
+ /**
+ * Returns the seconds since attach timestamp.
+ * @return whole seconds
+ */
+ public int getTimeSeconds()
+ {
+ return timeSeconds;
+ }
+
+ /**
+ * Returns the microseconds since last second.
+ * @return microseconds
+ */
+ public int getTimeMicroSeconds()
+ {
+ return timeMicroSeconds;
+ }
+
+ /**
+ * Returns time since attach in seconds
+ * @return seconds
+ */
+ public double getTime()
+ {
+ return (timeMicroSeconds/1000000.0 + timeSeconds);
+ }
+
+ public String toString()
+ {
+ return "Spatial Data";
+ }
+}
+
diff --git a/Java/com/phidgets/SpatialPhidget.java b/Java/com/phidgets/SpatialPhidget.java
new file mode 100644
index 0000000..bec1de7
--- /dev/null
+++ b/Java/com/phidgets/SpatialPhidget.java
@@ -0,0 +1,205 @@
+
+/*
+ * Copyright 2006 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 Spatial. All methods for a PhidgetSpatial are implemented in this class.
+ <p>
+ The Phidget Spatial may provide up to 3 axes of acceleration data, 3 axes of angular rate data and 3 axes of magnetic field data.
+
+ * @author Phidgets Inc.
+ */
+public final class SpatialPhidget extends Phidget
+{
+ public SpatialPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+
+ /**
+ * Returns the number of accelerometer axes.
+ * @return number of axes of acceleration
+ */
+ public native int getAccelerationAxisCount () throws PhidgetException;
+ /**
+ * Returns the acceleration of a particular axis.
+ *
+ * @param index index of the axis
+ * @return acceleration of the selected axis
+ * @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 getAcceleration (int index) throws PhidgetException;
+ /**
+ * Returns the maximum acceleration value that this axis will report.
+ * @return maximum acceleration
+ */
+ public native double getAccelerationMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum acceleration value that this axis will report.
+ * @return minimum acceleration
+ */
+ public native double getAccelerationMin (int index) throws PhidgetException;
+
+ /**
+ * Returns the number of gyro axes.
+ * @return number of axes of angularRate
+ */
+ public native int getGyroAxisCount () throws PhidgetException;
+ /**
+ * Returns the angularRate of a particular axis.
+ *
+ * @param index index of the axis
+ * @return angularRate of the selected axis
+ * @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 getAngularRate (int index) throws PhidgetException;
+ /**
+ * Returns the maximum angularRate value that this axis will report.
+ * @return maximum angularRate
+ */
+ public native double getAngularRateMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum angularRate value that this axis will report.
+ * @return minimum angularRate
+ */
+ public native double getAngularRateMin (int index) throws PhidgetException;
+
+ /**
+ * Returns the number of compass axes.
+ * @return number of axes of magneticField
+ */
+ public native int getCompassAxisCount () throws PhidgetException;
+ /**
+ * Returns the magneticField of a particular axis.
+ *
+ * @param index index of the axis
+ * @return magneticField of the selected axis
+ * @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 getMagneticField (int index) throws PhidgetException;
+ /**
+ * Returns the maximum magneticField value that this axis will report.
+ * @return maximum magneticField
+ */
+ public native double getMagneticFieldMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum magneticField value that this axis will report.
+ * @return minimum magneticField
+ */
+ public native double getMagneticFieldMin (int index) throws PhidgetException;
+
+ /**
+ * Returns the data rate, in milliseconds.
+ *
+ * @return data rate
+ * @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 int getDataRate () throws PhidgetException;
+ /**
+ * Sets the data rate, in milliseconds.
+ *
+ * @param rate data rate
+ * @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 void setDataRate (int rate) throws PhidgetException;
+ /**
+ * Returns the minimum data rate, in milliseconds.
+ *
+ * @return minimum data rate
+ * @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 int getDataRateMin () throws PhidgetException;
+ /**
+ * Returns the maximum data rate, in milliseconds.
+ *
+ * @return maximum data rate
+ * @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 int getDataRateMax () throws PhidgetException;
+
+ /**
+ * Zeroes the gyroscope. This takes about two seconds and the gyro zxes will report 0 during the process.
+ * This should only be called when the board is not moving.
+ *
+ * @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 void zeroGyro () throws PhidgetException;
+ /**
+ * Sets the compass correction factors. This can be used to correcting any sensor errors, including hard and soft iron offsets and sensor error factors.
+ *
+ * @param magField Local magnetic field strength.
+ * @param offset0 Axis 0 offset correction.
+ * @param offset1 Axis 1 offset correction.
+ * @param offset2 Axis 2 offset correction.
+ * @param gain0 Axis 0 gain correction.
+ * @param gain1 Axis 1 gain correction.
+ * @param gain2 Axis 2 gain correction.
+ * @param T0 Non-orthogonality correction factor 0.
+ * @param T1 Non-orthogonality correction factor 1.
+ * @param T2 Non-orthogonality correction factor 2.
+ * @param T3 Non-orthogonality correction factor 3.
+ * @param T4 Non-orthogonality correction factor 4.
+ * @param T5 Non-orthogonality correction factor 5.
+ * @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 void setCompassCorrectionParameters (double magField, double offset0, double offset1, double offset2, double gain0, double gain1, double gain2, double T0, double T1, double T2,
+ double T3, double T4, double T5) throws PhidgetException;
+ /**
+ * Resets the compass correction factors. Magnetic field data will be presented directly as reported by the sensor.
+ *
+ * @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 void resetCompassCorrectionParameters () throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableSpatialDataEvents (b && spatialDataListeners.size () > 0);
+ }
+ /**
+ * Adds a spatial data listener. The spatial data handler is a method that will be called at a rate of
+ * {@link #getDataRate() DataRate} that has been set for the device. This event contains data for all axes of all sensors.
+ * <p>
+ * There is no limit on the number of spatial data handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.SpatialDataListener SpatialDataListener} interface
+ */
+ public final void addSpatialDataListener (SpatialDataListener l)
+ {
+ synchronized (spatialDataListeners)
+ {
+ spatialDataListeners.add (l);
+ enableSpatialDataEvents (true);
+ }} private LinkedList spatialDataListeners = new LinkedList ();
+ private long nativeSpatialDataHandler = 0;
+ public final void removeSpatialDataListener (SpatialDataListener l)
+ {
+ synchronized (spatialDataListeners)
+ {
+ spatialDataListeners.remove (l);
+ enableSpatialDataEvents (spatialDataListeners.size () > 0);
+ }} private void fireSpatialData (SpatialDataEvent e)
+ {
+ synchronized (spatialDataListeners)
+ {
+ for (Iterator it = spatialDataListeners.iterator (); it.hasNext ();)
+ ((SpatialDataListener) it.next ()).data (e);
+ }
+ }
+ private native void enableSpatialDataEvents (boolean b);
+}
diff --git a/Java/com/phidgets/StepperPhidget.java b/Java/com/phidgets/StepperPhidget.java
new file mode 100644
index 0000000..83fa772
--- /dev/null
+++ b/Java/com/phidgets/StepperPhidget.java
@@ -0,0 +1,422 @@
+
+/*
+ * Copyright 2006 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 Stepper Controller. All methods
+ * to to control a stepper controller and read back stepper data are implemented in this class.
+ * <p>
+ * The Phidget Stepper is able to control 1 or more Stepper motors. Motor Acceleration and Velocity are
+ * controllable, and micro-stepping is used. The type and number of motors that can be controlled
+ * depend on the Stepper Controller. Digital inputs are available on select Phidget Stepper Controllers.
+ *
+ * @author Phidgets Inc.
+ */
+public final class StepperPhidget extends Phidget
+{
+ public StepperPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+ /**
+ * Returns the number of stepper motors supported by this Phidget. This does not neccesarily correspond
+ to the number of motors actually attached to the board.
+ * @return number of supported motors
+ * @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 getMotorCount () throws PhidgetException;
+ /**
+ * Returns the number of digital inputs. Not all Stepper Controllers have digital inputs.
+ * @return number of digital inputs
+ * @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 getInputCount () throws PhidgetException;
+ /**
+ * Returns the state of a digital input. True means that the input is activated, and False indicated the default state.
+ * @param index index of the input
+ * @return state of the input
+ * @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 getInputState (int index) throws PhidgetException;
+ /**
+ * Returns a motor's acceleration. The valid range is between {@link #getAccelerationMin getAccelerationMin}
+ * and {@link #getAccelerationMax getAccelerationMax}, and refers to how fast the Stepper Controller will change the speed of a motor.
+ * <p>This value is in (micro)steps per second squared. The step unit will depend on the Stepper Controller. For example, the Bipolar
+ * Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second squared.
+ * @param index index of motor
+ * @return acceleration of motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if the acceleration is unknown.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getAcceleration (int index) throws PhidgetException;
+ /**
+ * Returns the maximum acceleration that a motor will accept, or return.
+ * <p>This value uses the same units as {@link #setAcceleration setAcceleration}/{@link #getAcceleration getAcceleration}.
+ * @param index Index of the motor
+ * @return Maximum acceleration
+ * @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 double getAccelerationMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum acceleration that a motor will accept, or return.
+ * <p>This value uses the same units as {@link #setAcceleration setAcceleration}/{@link #getAcceleration getAcceleration}.
+ * @param index Index of the motor
+ * @return Minimum acceleration
+ * @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 double getAccelerationMin (int index) throws PhidgetException;
+ /**
+ * Sets a motor's acceleration.
+ * The valid range is between {@link #getAccelerationMin getAccelerationMin} and {@link #getAccelerationMax getAccelerationMax}.
+ * This controls how fast the motor changes speed.
+ * <p>This value is in (micro)steps per second squared. The step unit will depend on the Stepper Controller. For example, the Bipolar
+ * Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second squared.
+ * @param index index of the motor
+ * @param acceleration requested acceleration for that motor
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index or acceleration are invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setAcceleration (int index, double acceleration) throws PhidgetException;
+ /**
+ * Returns a motor's current velocity. The valid range is between {@link #getVelocityMin getVelocityMin} and {@link #getVelocityMax getVelocityMax},
+ * with 0 being stopped.
+ * <p>This value is in (micro)steps per second. The step unit will depend on the Stepper Controller. For example, the Bipolar
+ * Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second.
+ * @param index index of the motor
+ * @return current speed of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if the velocity in unknown.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getVelocity (int index) throws PhidgetException;
+ /**
+ * Returns the maximum velocity that a stepper motor will accept, or return.
+ * <p>This value uses the same units as {@link #setVelocityLimit setVelocityLimit}/{@link #getVelocityLimit getVelocityLimit} and {@link #getVelocity getVelocity}.
+ * @param index Index of the motor
+ * @return Maximum velocity
+ * @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 double getVelocityMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum velocity that a stepper motor will accept, or return.
+ * <p>This value uses the same units as {@link #setVelocityLimit setVelocityLimit}/{@link #getVelocityLimit getVelocityLimit} and {@link #getVelocity getVelocity}.
+ * @param index Index of the motor
+ * @return Minimum velocity
+ * @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 double getVelocityMin (int index) throws PhidgetException;
+ /**
+ * Sets a motor's velocity limit. This is the maximum velocity that the motor will turn at.
+ * The valid range is between {@link #getVelocityMin getVelocityMin} and {@link #getVelocityMax getVelocityMax},
+ * with 0 being stopped.
+ * <p>This value is in (micro)steps per second. The step unit will depend on the Stepper Controller. For example, the Bipolar
+ * Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second.
+ * @param index index of the motor
+ * @param velocity requested velocity for the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index or velocity are invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setVelocityLimit (int index, double velocity) throws PhidgetException;
+ /**
+ * Returns a motor's velocity limit. This is the maximum velocity that the motor will turn at.
+ * The valid range is between {@link #getVelocityMin getVelocityMin} and {@link #getVelocityMax getVelocityMax},
+ * with 0 being stopped.
+ * <p>This value is in (micro)steps per second. The step unit will depend on the Stepper Controller. For example, the Bipolar
+ * Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps per second.
+ * @param index index of the motor
+ * @return current speed of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if the velocity in unknown.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getVelocityLimit (int index) throws PhidgetException;
+ /**
+ * Returns the maximum position that a stepper motor will accept, or return.
+ * <p>This value uses the same units as
+ * {@link #setTargetPosition setTargetPosition}/{@link #getTargetPosition getTargetPosition} and {@link #setCurrentPosition setCurrentPosition}/{@link #getCurrentPosition getCurrentPosition}.
+ * @param index Index of the motor
+ * @return Maximum position
+ * @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 long getPositionMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum position that a stepper motor will accept, or return.
+ * <p>This value uses the same units as
+ * {@link #setTargetPosition setTargetPosition}/{@link #getTargetPosition getTargetPosition} and {@link #setCurrentPosition setCurrentPosition}/{@link #getCurrentPosition getCurrentPosition}.
+ * @param index Index of the motor
+ * @return Minimum position
+ * @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 long getPositionMin (int index) throws PhidgetException;
+ /**
+ * Sets a motor's current position. Use this is (re)set the current physical position of the motor to a specific position value.
+ * This does not move the motor, and if the motor is moving, calling this will cause it to stop moving. Use {@link #setTargetPosition setTargetPosition}
+ * to move the motor to a position.
+ * The valid range is between {@link #getPositionMin getPositionMin} and {@link #getPositionMax getPositionMax}.
+ * <p>This value is in (micro)steps. The step unit will depend on the Stepper Controller. For example, the Bipolar
+ * Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps.
+ * @param index index of the motor
+ * @param position current position of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index or position are invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setCurrentPosition (int index, long position) throws PhidgetException;
+ /**
+ * Returns a motor's current position. This is the actual step position that the motor is at right now.
+ * The valid range is between {@link #getPositionMin getPositionMin} and {@link #getPositionMax getPositionMax}.
+ * <p>This value is in (micro)steps. The step unit will depend on the Stepper Controller. For example, the Bipolar
+ * Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps.
+ * @param index index of the motor
+ * @return current position of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if the position in unknown.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native long getCurrentPosition (int index) throws PhidgetException;
+ /**
+ * Sets a motor's target position. Use this is set the target position for the stepper. If the stepper is {@link #setEngaged engaged} it will start moving towards
+ * this target position.
+ * The valid range is between {@link #getPositionMin getPositionMin} and {@link #getPositionMax getPositionMax}.
+ * <p>This value is in (micro)steps. The step unit will depend on the Stepper Controller. For example, the Bipolar
+ * Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps.
+ * @param index index of the motor
+ * @param position target position of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the index or position are invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setTargetPosition (int index, long position) throws PhidgetException;
+ /**
+ * Returns a motor's target position. This is the position that the motor wants to be at. If the motor is not moving,
+ * it probably has reached the target position, and this will match {@link #getCurrentPosition current position}.
+ * The valid range is between {@link #getPositionMin getPositionMin} and {@link #getPositionMax getPositionMax}.
+ * <p>This value is in (micro)steps. The step unit will depend on the Stepper Controller. For example, the Bipolar
+ * Stepper controller has an accuracy of 16th steps, so this value would be in 16th steps.
+ * @param index index of the motor
+ * @return target position of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if the position in unknown.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native long getTargetPosition (int index) throws PhidgetException;
+ /**
+ * Returns a motor's current usage. The valid range is between {@link #getCurrentMin getCurrentMin} and {@link #getCurrentMax getCurrentMax}.
+ * This value is in Amps.
+ * <p>Note that this is not supported on all stepper controllers.
+ * @param index index of the motor
+ * @return current usage of the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, if the value is unknown, or if this is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getCurrent (int index) throws PhidgetException;
+ /**
+ * Returns the current limit.
+ * <p>This value is in Amps.
+ * @param index Index of the motor
+ * @return Current Limit
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, if the value is unknown, or if this is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getCurrentLimit (int index) throws PhidgetException;
+ /**
+ * Sets a motor's current usage limit. The valid range is between {@link #getCurrentMin getCurrentMin} and {@link #getCurrentMax getCurrentMax}.
+ * This sets the maximum current that a motor will be allowed to draw. Use this with the Bipolar stepper controller to get smooth micro stepping -
+ * see the product manual for more details. This value is in Amps.
+ * <p>Note that this is not supported on all stepper controllers.
+ * @param index index of the motor
+ * @param current current limit for the motor
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, if the value is unknown, or if this is not supported.
+ *
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setCurrentLimit (int index, double current) throws PhidgetException;
+ /**
+ * Returns the maximum current that a stepper motor will accept, or return.
+ * <p>This value is in Amps.
+ * @param index Index of the motor
+ * @return Maximum current
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if this is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getCurrentMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum current that a stepper motor will accept, or return.
+ * <p>This value is in Amps.
+ * @param index Index of the motor
+ * @return Minimum current
+ * @throws PhidgetException If this Phidget is not opened and attached, if the index is invalid, or if this is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getCurrentMin (int index) throws PhidgetException;
+ /**
+ * Engage or disengage a motor.
+ * <p>
+ * This engages or disengages the stepper motor. The motors are by default disengaged when the stepper controller is plugged in.
+ * When the stepper is disengaged, position, velocity, etc. can all be set, but the motor will not start moving until it is engaged.
+ * If position is read when a motor is disengaged, it will throw an exception.
+ *
+ * @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 void setEngaged (int index, boolean state) throws PhidgetException;
+ /**
+ * Returns the engaged state of a motor.
+ *
+ * @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 boolean getEngaged (int index) throws PhidgetException;
+ /**
+ * Returns the stopped state of a motor. Use this to determine if the motor is moving and/or up to date with the latest commands you have sent.
+ * If this is true, the motor is guaranteed to be stopped and to have processed every command issued. Generally, this would
+ * be polled after a target position is set to wait until that position is reached.
+ *
+ * @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 boolean getStopped (int index) throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableStepperPositionChangeEvents (b && stepperPositionChangeListeners.size () > 0);
+ enableStepperVelocityChangeEvents (b && stepperVelocityChangeListeners.size () > 0);
+ enableCurrentChangeEvents (b && currentChangeListeners.size () > 0);
+ enableInputChangeEvents (b && inputChangeListeners.size () > 0);
+ }
+ /**
+ * Adds a position change listener. The position change handler is a method that will be called when the stepper
+ * position has changed.
+ * <p>
+ * There is no limit on the number of position change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.StepperPositionChangeListener StepperPositionChangeListener} interface
+ */
+ public final void addStepperPositionChangeListener (StepperPositionChangeListener l)
+ {
+ synchronized (stepperPositionChangeListeners)
+ {
+ stepperPositionChangeListeners.add (l);
+ enableStepperPositionChangeEvents (true);
+ }} private LinkedList stepperPositionChangeListeners = new LinkedList ();
+ private long nativeStepperPositionChangeHandler = 0;
+ public final void removeStepperPositionChangeListener (StepperPositionChangeListener l)
+ {
+ synchronized (stepperPositionChangeListeners)
+ {
+ stepperPositionChangeListeners.remove (l);
+ enableStepperPositionChangeEvents (stepperPositionChangeListeners.size () > 0);
+ }} private void fireStepperPositionChange (StepperPositionChangeEvent e)
+ {
+ synchronized (stepperPositionChangeListeners)
+ {
+ for (Iterator it = stepperPositionChangeListeners.iterator (); it.hasNext ();)
+ ((StepperPositionChangeListener) it.next ()).stepperPositionChanged (e);
+ }
+ }
+ private native void enableStepperPositionChangeEvents (boolean b);
+ /**
+ * Adds a velocity change listener. The velocity change handler is a method that will be called when the stepper
+ * velocity has changed.
+ * <p>
+ * There is no limit on the number of velocity change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.StepperVelocityChangeListener StepperVelocityChangeListener} interface
+ */
+ public final void addStepperVelocityChangeListener (StepperVelocityChangeListener l)
+ {
+ synchronized (stepperVelocityChangeListeners)
+ {
+ stepperVelocityChangeListeners.add (l);
+ enableStepperVelocityChangeEvents (true);
+ }} private LinkedList stepperVelocityChangeListeners = new LinkedList ();
+ private long nativeStepperVelocityChangeHandler = 0;
+ public final void removeStepperVelocityChangeListener (StepperVelocityChangeListener l)
+ {
+ synchronized (stepperVelocityChangeListeners)
+ {
+ stepperVelocityChangeListeners.remove (l);
+ enableStepperVelocityChangeEvents (stepperVelocityChangeListeners.size () > 0);
+ }} private void fireStepperVelocityChange (StepperVelocityChangeEvent e)
+ {
+ synchronized (stepperVelocityChangeListeners)
+ {
+ for (Iterator it = stepperVelocityChangeListeners.iterator (); it.hasNext ();)
+ ((StepperVelocityChangeListener) it.next ()).stepperVelocityChanged (e);
+ }
+ }
+ private native void enableStepperVelocityChangeEvents (boolean b);
+ /**
+ * Adds a current change listener. The current change handler is a method that will be called when the stepper
+ * current has changed.
+ * <p>
+ * There is no limit on the number of current change handlers that can be registered for a particular Phidget.
+ * <p>
+ * Note that not all stepper controllers support current sensing.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.CurrentChangeListener CurrentChangeListener} interface
+ */
+ public final void addCurrentChangeListener (CurrentChangeListener l)
+ {
+ synchronized (currentChangeListeners)
+ {
+ currentChangeListeners.add (l);
+ enableCurrentChangeEvents (true);
+ }} private LinkedList currentChangeListeners = new LinkedList ();
+ private long nativeCurrentChangeHandler = 0;
+ public final void removeCurrentChangeListener (CurrentChangeListener l)
+ {
+ synchronized (currentChangeListeners)
+ {
+ currentChangeListeners.remove (l);
+ enableCurrentChangeEvents (currentChangeListeners.size () > 0);
+ }} private void fireCurrentChange (CurrentChangeEvent e)
+ {
+ synchronized (currentChangeListeners)
+ {
+ for (Iterator it = currentChangeListeners.iterator (); it.hasNext ();)
+ ((CurrentChangeListener) it.next ()).currentChanged (e);
+ }
+ }
+ private native void enableCurrentChangeEvents (boolean b);
+ /**
+ * Adds an input change listener. The input change handler is a method that will be called when an input on this
+ * Stepper Controller board has changed.
+ * <p>
+ * There is no limit on the number of input change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.InputChangeListener InputChangeListener} interface
+ */
+ public final void addInputChangeListener (InputChangeListener l)
+ {
+ synchronized (inputChangeListeners)
+ {
+ inputChangeListeners.add (l);
+ enableInputChangeEvents (true);
+ }} private LinkedList inputChangeListeners = new LinkedList ();
+ private long nativeInputChangeHandler = 0;
+ public final void removeInputChangeListener (InputChangeListener l)
+ {
+ synchronized (inputChangeListeners)
+ {
+ inputChangeListeners.remove (l);
+ enableInputChangeEvents (inputChangeListeners.size () > 0);
+ }} private void fireInputChange (InputChangeEvent e)
+ {
+ synchronized (inputChangeListeners)
+ {
+ for (Iterator it = inputChangeListeners.iterator (); it.hasNext ();)
+ ((InputChangeListener) it.next ()).inputChanged (e);
+ }
+ }
+ private native void enableInputChangeEvents (boolean b);
+}
diff --git a/Java/com/phidgets/TemperatureSensorPhidget.java b/Java/com/phidgets/TemperatureSensorPhidget.java
new file mode 100644
index 0000000..baaa589
--- /dev/null
+++ b/Java/com/phidgets/TemperatureSensorPhidget.java
@@ -0,0 +1,213 @@
+
+/*
+ * Copyright 2006 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 temperature Sensor. All methods
+ * to read temperaure data from the sensor are implemented in this class.
+ * <p>
+ * The Temperature Phidget consists of a thermocouple interface, and a temperature
+ * sensing IC, which is used to measure the temperature of the thermocouple cold junction
+ * and calibrate the thermocouple sensed temperature.
+ * <p>
+ * Both the thermocouple and temperature IC temperatures can be read. Value are returned in degrees celcius.
+ *
+ * @author Phidgets Inc.
+ */
+public final class TemperatureSensorPhidget extends Phidget
+{
+ public TemperatureSensorPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+
+ /**
+ * K-Type Thermocouple. This is used with {@link #getThermocoupleType getThermocoupleType} and {@link #setThermocoupleType setThermocoupleType}
+ */
+ public static final int PHIDGET_TEMPERATURE_SENSOR_K_TYPE = 1;
+ /**
+ * J-Type Thermocouple. This is used with {@link #getThermocoupleType getThermocoupleType} and {@link #setThermocoupleType setThermocoupleType}
+ */
+ public static final int PHIDGET_TEMPERATURE_SENSOR_J_TYPE = 2;
+ /**
+ * E-Type Thermocouple. This is used with {@link #getThermocoupleType getThermocoupleType} and {@link #setThermocoupleType setThermocoupleType}
+ */
+ public static final int PHIDGET_TEMPERATURE_SENSOR_E_TYPE = 3;
+ /**
+ * T-Type Thermocouple. This is used with {@link #getThermocoupleType getThermocoupleType} and {@link #setThermocoupleType setThermocoupleType}
+ */
+ public static final int PHIDGET_TEMPERATURE_SENSOR_T_TYPE = 4;
+
+ /**
+ * Returns the number of thermocouples.
+ * @return Number of inputs
+ */
+ public native int getTemperatureInputCount () throws PhidgetException;
+ /**
+ * @deprecated Replaced by
+ * {@link #getTemperatureInputCount}
+ */
+ public native int getSensorCount () throws PhidgetException;
+ /**
+ * Returns the temperature of a thermocouple. This value is returned in degrees celcius but can easily be converted into other units.
+ * This value will always be between {@link #getTemperatureMin getTemperatureMin} and {@link #getTemperatureMax getTemperatureMax}.
+ * The accuracy depends on the thermocouple used. The board is calibrated during manufacture.
+ * @param index Index of the thermocouple
+ * @return Temperature in derees celcius
+ * @throws PhidgetException If this Phidget is not opened and attached, or if a thermocouple sensor is not plugged into the board.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native double getTemperature (int index) throws PhidgetException;
+ /**
+ * Returns the maximum temperature that will be returned by a thermocouple input. This value depends on the thermocouple type.
+ * @param index Index of the thermocouple
+ * @return Maximum temperature in derees celcius
+ * @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 double getTemperatureMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum temperature that will be returned by a thermocouple input. This value depends on the thermocouple type.
+ * @param index Index of the thermocouple
+ * @return Minimum temperature in derees celcius
+ * @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 double getTemperatureMin (int index) throws PhidgetException;
+ /**
+ * Returns the temperature of the ambient sensor. This value is returned in degrees celcius but can easily be converted into other units.
+ * This value will always be between {@link #getAmbientTemperatureMin getAmbientTemperatureMin} and {@link #getAmbientTemperatureMax getAmbientTemperatureMax}.
+ * This is the temperature of the board at the thermocouple cold junction.
+ * @return Temperature in derees celcius
+ * @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 double getAmbientTemperature () throws PhidgetException;
+ /**
+ * Returns the maximum temperature that will be returned by the ambient sensor.
+ * @return Maximum ambient temperature in derees celcius
+ * @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 double getAmbientTemperatureMax () throws PhidgetException;
+ /**
+ * Returns the minimum temperature that will be returned by the ambient sensor.
+ * @return Minimum ambient temperature in derees celcius
+ * @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 double getAmbientTemperatureMin () throws PhidgetException;
+ /**
+ * Returns the potential of a thermocouple input. This value is returned in millivolts.
+ * This value will always be between {@link #getPotentialMin getPotentialMin} and {@link #getPotentialMax getPotentialMax}.
+ * This is very accurate, as it is a raw value from the A/D. This is the value that is internally used to calculate temperature in the library.
+ * @param index Index of the thermocouple
+ * @return Potential in millivolts
+ * @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 double getPotential (int index) throws PhidgetException;
+ /**
+ * Returns the maximum potential that will be returned by a thermocouple input.
+ * @param index Index of the thermocouple
+ * @return Maximum potential in millivolts
+ * @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 double getPotentialMax (int index) throws PhidgetException;
+ /**
+ * Returns the minimum potential that will be returned by a thermocouple input.
+ * @param index Index of the thermocouple
+ * @return Minimum potential in millivolts
+ * @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 double getPotentialMin (int index) throws PhidgetException;
+ /**
+ * Sets the change trigger for an input. This is the ammount by which the sensed temperature must
+ * change between TemperatureChangeEvents. By default this is set to 0.5.
+ * @param index Input
+ * @param newVal Trigger
+ * @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 void setTemperatureChangeTrigger (int index, double newVal) throws PhidgetException;
+ /**
+ * Returns the change trigger for an input. This is the ammount by which the sensed temperature must
+ * change between TemperatureChangeEvents. By default this is set to 0.5.
+ * @param index Input
+ * @return Trigger
+ * @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 getTemperatureChangeTrigger (int index) throws PhidgetException;
+ /**
+ * Returns the thermocouple type for an input.
+ * The possible values for type are {@link #PHIDGET_TEMPERATURE_SENSOR_K_TYPE PHIDGET_TEMPERATURE_SENSOR_K_TYPE},
+ * {@link #PHIDGET_TEMPERATURE_SENSOR_J_TYPE PHIDGET_TEMPERATURE_SENSOR_J_TYPE}, {@link #PHIDGET_TEMPERATURE_SENSOR_E_TYPE PHIDGET_TEMPERATURE_SENSOR_E_TYPE} and
+ * {@link #PHIDGET_TEMPERATURE_SENSOR_T_TYPE PHIDGET_TEMPERATURE_SENSOR_T_TYPE}
+ * @param index Input
+ * @return Thermocouple Type
+ * @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 int getThermocoupleType (int index) throws PhidgetException;
+ /**
+ * Sets the thermocouple type for an input. The Phidget Temperature Sensor board can be used with K, E, J and T-Type Thermocouples.
+ * Support for other thermocouple types, and voltage sources other then thermocouples in the valid range (between {@link #getPotentialMin getPotentialMin} and {@link #getPotentialMax getPotentialMax}) can
+ * be achieved using {@link #getPotential getPotential}.
+ * <p>
+ * The possible values for type are {@link #PHIDGET_TEMPERATURE_SENSOR_K_TYPE PHIDGET_TEMPERATURE_SENSOR_K_TYPE},
+ * {@link #PHIDGET_TEMPERATURE_SENSOR_J_TYPE PHIDGET_TEMPERATURE_SENSOR_J_TYPE}, {@link #PHIDGET_TEMPERATURE_SENSOR_E_TYPE PHIDGET_TEMPERATURE_SENSOR_E_TYPE} and
+ * {@link #PHIDGET_TEMPERATURE_SENSOR_T_TYPE PHIDGET_TEMPERATURE_SENSOR_T_TYPE}
+ * <p>
+ * By default, type is set to {@link #PHIDGET_TEMPERATURE_SENSOR_K_TYPE PHIDGET_TEMPERATURE_SENSOR_K_TYPE}.
+ * @param index Input
+ * @param type Thermocouple Type
+ * @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 void setThermocoupleType (int index, int type) throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableTemperatureChangeEvents (b && temperatureChangeListeners.size () > 0);
+ }
+ /**
+ * Adds a temperature change listener. The temperature change handler is a method that will be called when the temperature
+ * has changed by at least the {@link #getTemperatureChangeTrigger(int) Trigger} that has been set.
+ * <p>
+ * There is no limit on the number of temperature change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.TemperatureChangeListener TemperatureChangeListener} interface
+ */
+ public final void addTemperatureChangeListener (TemperatureChangeListener l)
+ {
+ synchronized (temperatureChangeListeners)
+ {
+ temperatureChangeListeners.add (l);
+ enableTemperatureChangeEvents (true);
+ }} private LinkedList temperatureChangeListeners = new LinkedList ();
+ private long nativeTemperatureChangeHandler = 0;
+ public final void removeTemperatureChangeListener (TemperatureChangeListener l)
+ {
+ synchronized (temperatureChangeListeners)
+ {
+ temperatureChangeListeners.remove (l);
+ enableTemperatureChangeEvents (temperatureChangeListeners.size () > 0);
+ }} private void fireTemperatureChange (TemperatureChangeEvent e)
+ {
+ synchronized (temperatureChangeListeners)
+ {
+ for (Iterator it = temperatureChangeListeners.iterator (); it.hasNext ();)
+ ((TemperatureChangeListener) it.next ()).temperatureChanged (e);
+ }
+ }
+ private native void enableTemperatureChangeEvents (boolean b);
+}
diff --git a/Java/com/phidgets/TextLCDPhidget.java b/Java/com/phidgets/TextLCDPhidget.java
new file mode 100644
index 0000000..ac4c500
--- /dev/null
+++ b/Java/com/phidgets/TextLCDPhidget.java
@@ -0,0 +1,278 @@
+
+/*
+ * Copyright 2011 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 Text LCD. All methods
+ * to control the Text LCD are implemented in this class.
+ * <p>
+ * The TextLCD Phidget consists of a Vacuum Fluorescent display that is capable of
+ * displaying Standard as well as custom characters in multiple rows.
+ *
+ * @author Phidgets Inc.
+ */
+public final class TextLCDPhidget extends Phidget
+{
+ public TextLCDPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+ /**
+ * No screens attached. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_NONE = 1;
+ /**
+ * 1 row, 8 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_1x8 = 2;
+ /**
+ * 2 row, 8 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_2x8 = 3;
+ /**
+ * 1 row, 16 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_1x16 = 4;
+ /**
+ * 2 row, 16 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_2x16 = 5;
+ /**
+ * 4 row, 16 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_4x16 = 6;
+ /**
+ * 2 row, 20 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_2x20 = 7;
+ /**
+ * 4 row, 20 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_4x20 = 8;
+ /**
+ * 2 row, 24 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_2x24 = 9;
+ /**
+ * 1 row, 40 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_1x40 = 10;
+ /**
+ * 2 row, 40 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_2x40 = 11;
+ /**
+ * 4 row, 40 column screen. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_4x40 = 12;
+ /**
+ * Unknown screen size. This is used with {@link #getScreenSize() getScreenSize} and {@link #setScreenSize(int) setScreenSize}
+ */
+ public static final int PHIDGET_TEXTLCD_SCREEN_UNKNOWN = 13;
+ /**
+ * Returns the number of rows available on the display.
+ * @return Number of rows
+ * @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 getRowCount () throws PhidgetException;
+ /**
+ * Returns the number of columns (characters per row) available on the display. This value is
+ * the same for every row.
+ * @return Number of columns
+ * @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 getColumnCount () throws PhidgetException;
+ /**
+ * Returns the number of screens supported by the TextLCD. Not all TextLCDs support this method.
+ * @return Number of screens.
+ * @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 getScreenCount () throws PhidgetException;
+ /**
+ * Returns the active screen. Not all TextLCDs support this method.
+ * @return active screen
+ * @throws PhidgetException If this Phidget is not opened and attached, or screen is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native int getScreen () throws PhidgetException;
+ /**
+ * Sets the active screen. All other API calls depend on this being called first to select the screen that subsequent calls affect.
+ * When making calls from multiple threads, selecting the screen should be synchronized with setting screen properties in order to avoid
+ * having messages go to the wrong display. Not all TextLCDs support this method.
+ * @param screen Screen
+ * @throws PhidgetException If this Phidget is not opened and attached, the screen number is out of range, or screen is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setScreen (int screen) throws PhidgetException;
+
+ /**
+ * Returns the screen size for the active TextLCD display. The TextLCD Adapter supports a pre-defined set of screen sizes to choose from.
+ * By default, all screens are set to {@link #PHIDGET_TEXTLCD_SCREEN_NONE PHIDGET_TEXTLCD_SCREEN_NONE}.
+ * Not all TextLCDs support this method.
+ * <p>
+ * The possible values for screen size are {@link #PHIDGET_TEXTLCD_SCREEN_NONE PHIDGET_TEXTLCD_SCREEN_NONE},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_1x8 PHIDGET_TEXTLCD_SCREEN_1x8}, {@link #PHIDGET_TEXTLCD_SCREEN_2x8 PHIDGET_TEXTLCD_SCREEN_2x8},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_1x16 PHIDGET_TEXTLCD_SCREEN_1x16}, {@link #PHIDGET_TEXTLCD_SCREEN_2x16 PHIDGET_TEXTLCD_SCREEN_2x16},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_4x16 PHIDGET_TEXTLCD_SCREEN_4x16}, {@link #PHIDGET_TEXTLCD_SCREEN_2x20 PHIDGET_TEXTLCD_SCREEN_2x20},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_4x20 PHIDGET_TEXTLCD_SCREEN_4x20}, {@link #PHIDGET_TEXTLCD_SCREEN_2x24 PHIDGET_TEXTLCD_SCREEN_2x24},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_1x40 PHIDGET_TEXTLCD_SCREEN_1x40}, {@link #PHIDGET_TEXTLCD_SCREEN_2x40 PHIDGET_TEXTLCD_SCREEN_2x40},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_4x40 PHIDGET_TEXTLCD_SCREEN_4x40}, {@link #PHIDGET_TEXTLCD_SCREEN_UNKNOWN PHIDGET_TEXTLCD_SCREEN_UNKNOWN}
+ * <p>
+ * By default, all screens are set to {@link #PHIDGET_TEXTLCD_SCREEN_NONE PHIDGET_TEXTLCD_SCREEN_NONE}
+ * <p>
+ * @return screen size
+ * @throws PhidgetException If this Phidget is not opened and attached, or screen size is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native int getScreenSize () throws PhidgetException;
+ /**
+ * Sets the screen size for the active TextLCD display. The TextLCD Adapter supports a pre-defined set of screen sizes to choose from.
+ * This method must always be called when trying to write text to a display.
+ * Not all TextLCDs support this method.
+ * @param screenSize Screen size
+ * The possible values for screen size are {@link #PHIDGET_TEXTLCD_SCREEN_NONE PHIDGET_TEXTLCD_SCREEN_NONE},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_1x8 PHIDGET_TEXTLCD_SCREEN_1x8}, {@link #PHIDGET_TEXTLCD_SCREEN_2x8 PHIDGET_TEXTLCD_SCREEN_2x8},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_1x16 PHIDGET_TEXTLCD_SCREEN_1x16}, {@link #PHIDGET_TEXTLCD_SCREEN_2x16 PHIDGET_TEXTLCD_SCREEN_2x16},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_4x16 PHIDGET_TEXTLCD_SCREEN_4x16}, {@link #PHIDGET_TEXTLCD_SCREEN_2x20 PHIDGET_TEXTLCD_SCREEN_2x20},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_4x20 PHIDGET_TEXTLCD_SCREEN_4x20}, {@link #PHIDGET_TEXTLCD_SCREEN_2x24 PHIDGET_TEXTLCD_SCREEN_2x24},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_1x40 PHIDGET_TEXTLCD_SCREEN_1x40}, {@link #PHIDGET_TEXTLCD_SCREEN_2x40 PHIDGET_TEXTLCD_SCREEN_2x40},
+ * {@link #PHIDGET_TEXTLCD_SCREEN_4x40 PHIDGET_TEXTLCD_SCREEN_4x40}, {@link #PHIDGET_TEXTLCD_SCREEN_UNKNOWN PHIDGET_TEXTLCD_SCREEN_UNKNOWN}
+ * <p>
+ * By default, all screens are set to {@link #PHIDGET_TEXTLCD_SCREEN_NONE PHIDGET_TEXTLCD_SCREEN_NONE}
+ * <p>
+ * @throws PhidgetException If this Phidget is not opened and attached, the screen number is out of range, or screen size is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setScreenSize (int screenSize) throws PhidgetException;
+ /**
+ * Returns the contrast of the display. This is the contrast of the entire display.
+ * @return Current contrast
+ * @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 getContrast () throws PhidgetException;
+ /**
+ * Sets the contrast of the display. The valid range is 0-255. Changing the contrast can increase the readability
+ * of the display in certain viewing situation, such as at an odd angle.
+ * @param contrast New contrast to set
+ * @throws PhidgetException If this Phidget is not opened and attached, or the contrast value is out of range.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setContrast (int contrast) throws PhidgetException;
+ /**
+ * Returns the brightness of the display. This is the brightness of the backlight. Not all TextLCDs support this method.
+ * @return Current brightness
+ * @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, or brightness is not supported.
+ */
+ public native int getBrightness () throws PhidgetException;
+ /**
+ * Sets the brightness of the display. The valid range is 0-255. Changing the brightness can increase the readability of the display in certain viewing situation, such as at an odd angle.
+ * Not all TextLCDs support this method.
+ * @param brightness New brightness to set
+ * @throws PhidgetException If this Phidget is not opened and attached, or the brightness value is out of range, or brightness is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setBrightness (int brightness) throws PhidgetException;
+ /**
+ * Returns the status of the backlight. True indicated that the backlight is on, False indicated that it is off.
+ * The backlight is by default turned on.
+ * @return Status of the backlight
+ * @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 boolean getBacklight () throws PhidgetException;
+ /**
+ * Sets the status of the backlight. True turns the backlight on, False turns it off.
+ * The backlight is by default turned on.
+ * @param backlight New backlight state
+ * @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 void setBacklight (boolean backlight) throws PhidgetException;
+ /**
+ * Returns the status of the cursor. True turns the cursor is on, False turns it off.
+ * The cursor is an underscore which appears directly to the right of the last entered character
+ * on the display. The cursor is by default disabled.
+ * @return Status of the cursor
+ * @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 boolean getCursor () throws PhidgetException;
+ /**
+ * Sets the state of the cursor. True indicates that the cursor on, False indicates that it is off.
+ * The cursor is an underscore which appears directly to the right of the last entered character
+ * on the display. The cursor is by default disabled.
+ * @param cursor New cursor state
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the cursor has not been set
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setCursor (boolean cursor) throws PhidgetException;
+ /**
+ * Returns the status of the cursor blink. True turns the cursor blink on, False turns it off.
+ * The cursor blink is an flashing box which appears directly to the right of the last entered character
+ * on the display, in the same spot as the cursor if it is enabled. The cursor blink is by default disabled.
+ * @return Status of the cursor blink
+ * @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 boolean getCursorBlink () throws PhidgetException;
+ /**
+ * Sets the state of the cursor blink. True indicates that the cursor blink is on, False indicates that it is off.
+ * The cursor blink is an flashing box which appears directly to the right of the last entered character
+ * on the display, in the same spot as the cursor if it is enabled. The cursor blink is by default disabled.
+ * @param cursorblink New cursor blink state
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the cursor has not been set.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setCursorBlink (boolean cursorblink) throws PhidgetException;
+ /**
+ * Sets the display string of a certain row.
+ * @param index row
+ * @param text String
+ * @throws PhidgetException If this Phidget is not opened and attached, if the string is too long, or if the row is invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setDisplayString (int index, String text) throws PhidgetException;
+ /**
+ * Sets the character to display at a certain row and column.
+ * @param row row
+ * @param column column
+ * @param character character
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the row or column is invalid.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setDisplayCharacter (int row, int column, char character) throws PhidgetException;
+ /**
+ * Sets a custom character. You can set up to 8 custom characters, each one is completely defined by two integers, and gets
+ * stored in the character display until power is removed, whence they must be re-programmed. The characters lie in positions 8-15, and
+ * can be displayed by sending these codes to setDisplayString in amongst standard ASCII characters. See the TextLCD Java example for
+ * more information.
+ * @param index position ( 8-15 )
+ * @param param1 first half of the character code
+ * @param param2 second half of the character code
+ * @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 setCustomCharacter (int index, int param1, int param2) throws PhidgetException;
+ /**
+ * Initializes the active TextLCD Display. This runs an initialization routine which sets up and clears the display. This can be used for
+ * activating a display that was plugged in after the TextLCD Adapter was attached, to clear the display after setting/getting the screen size,
+ * and to re-initialize a display if it has become corrupted(display not working). Not all TextLCDs supported this method.
+ * @throws PhidgetException If this Phidget is not opened and attached, or initialize is not supported.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void initialize () throws PhidgetException;
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ }
+}
diff --git a/Java/com/phidgets/TextLEDPhidget.java b/Java/com/phidgets/TextLEDPhidget.java
new file mode 100644
index 0000000..a2f39c8
--- /dev/null
+++ b/Java/com/phidgets/TextLEDPhidget.java
@@ -0,0 +1,68 @@
+
+/*
+ * Copyright 2006 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 Text LED. All methods
+ * to control the Text LED are implemented in this class.
+ * <p>
+ * The Text LED is a Phidget that displays text and numerals on LED
+ * numeric display in rows. The number of rows and size of each row depends on
+ * your configuration.
+ *
+ * @author Phidgets Inc.
+ */
+public final class TextLEDPhidget extends Phidget
+{
+ public TextLEDPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+ /**
+ * Returns the number of rows. This returns the maximum number of rows supported by the device, not neccessarily
+ * the number of rows actually available with your coniguration.
+ * @return rows
+ * @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 getRowCount () throws PhidgetException;
+ /**
+ * Returns the number of columns (Characters per row). This returns the maximum number of columns supported by the device, not neccessarily
+ * the number of columns actually available with your coniguration.
+ * @return columns
+ * @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 getColumnCount () throws PhidgetException;
+ /**
+ * Returns the bringhtness. This is the brightneww of all rows. The Default brightness is 100.
+ * @return brightness
+ * @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 getBrightness () throws PhidgetException;
+ /**
+ * Sets the brightness of all rows. The valid range is 0-100.
+ * @param brightness brightness
+ * @throws PhidgetException If this Phidget is not opened and attached, or the brightness value is out of range.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setBrightness (int brightness) throws PhidgetException;
+ /**
+ * Sets the display string of a certain row. If the string is longer then the row, it will be truncated.
+ * @param index Row
+ * @param text String
+ * @throws PhidgetException If this Phidget is not opened and attached, or if the row is out of range.
+ * See {@link com.phidgets.Phidget#open(int) open} for information on determining if a device is attached.
+ */
+ public native void setDisplayString (int index, String text) throws PhidgetException;
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ }
+}
diff --git a/Java/com/phidgets/WeightSensorPhidget.java b/Java/com/phidgets/WeightSensorPhidget.java
new file mode 100644
index 0000000..b2bd9e8
--- /dev/null
+++ b/Java/com/phidgets/WeightSensorPhidget.java
@@ -0,0 +1,89 @@
+
+/*
+ * Copyright 2006 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 Weight Sensor. All methods
+ * to read weight data from the weight sensor are implemented in this class.
+ * <p>
+ * The Phidget Weight Sensor is simply an electronic scale with a USB interface.
+ * It provides one weight value, in kg.
+ *
+ * @author Phidget Inc.
+ */
+public final class WeightSensorPhidget extends Phidget
+{
+ public WeightSensorPhidget () throws PhidgetException
+ {
+ super (create ());
+ }
+ private static native long create () throws PhidgetException;
+ /**
+ * Returns the sensed weight in kg. This weight is in kg (kilograms), but can
+ * easily be converted into other units. The accuracy, sesitivity and range depends on the scale and version.
+ *
+ * @return The sensed weight
+ * @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 double getWeight () throws PhidgetException;
+ /**
+ * Sets the weight change trigger. This is the ammount by which the sensed weight must
+ * change between WeightChangeEvents. By default this is set to 5.
+ *
+ * @param newVal The new trigger value
+ * @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 void setWeightChangeTrigger (double newVal) throws PhidgetException;
+ /**
+ * Returns the weight change trigger. This is the ammount by which the sensed weight must
+ * change between WeightChangeEvents. By default this is set to 5.
+ *
+ * @return The trigger value
+ * @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 double getWeightChangeTrigger () throws PhidgetException;
+
+ private final void enableDeviceSpecificEvents (boolean b)
+ {
+ enableWeightChangeEvents (b && weightChangeListeners.size () > 0);
+ }
+ /**
+ * Adds a weight change listener. The weight change handler is a method that will be called when the weight
+ * has changed by at least the {@link #getWeightChangeTrigger() Trigger} that has been set.
+ * <p>
+ * There is no limit on the number of weight change handlers that can be registered for a particular Phidget.
+ *
+ * @param l An implemetation of the {@link com.phidgets.event.WeightChangeListener WeightChangeListener} interface
+ */
+ public final void addWeightChangeListener (WeightChangeListener l)
+ {
+ synchronized (weightChangeListeners)
+ {
+ weightChangeListeners.add (l);
+ enableWeightChangeEvents (true);
+ }} private LinkedList weightChangeListeners = new LinkedList ();
+ private long nativeWeightChangeHandler = 0;
+ public final void removeWeightChangeListener (WeightChangeListener l)
+ {
+ synchronized (weightChangeListeners)
+ {
+ weightChangeListeners.remove (l);
+ enableWeightChangeEvents (weightChangeListeners.size () > 0);
+ }} private void fireWeightChange (WeightChangeEvent e)
+ {
+ synchronized (weightChangeListeners)
+ {
+ for (Iterator it = weightChangeListeners.iterator (); it.hasNext ();)
+ ((WeightChangeListener) it.next ()).weightChanged (e);
+ }
+ }
+ private native void enableWeightChangeEvents (boolean b);
+}
diff --git a/Java/com/phidgets/event/AccelerationChangeEvent.java b/Java/com/phidgets/event/AccelerationChangeEvent.java
new file mode 100644
index 0000000..92f9c69
--- /dev/null
+++ b/Java/com/phidgets/event/AccelerationChangeEvent.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for an AccelerationChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class AccelerationChangeEvent
+{
+ Phidget source;
+ int index;
+ double value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public AccelerationChangeEvent(Phidget source, int index, double value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the axis.
+ *
+ * @return the index of the axis
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the acceleration. This is returned in g's
+ *
+ * @return the acceleration of the axis
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Acceleration " + index + " changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/AccelerationChangeListener.java b/Java/com/phidgets/event/AccelerationChangeListener.java
new file mode 100644
index 0000000..b97172e
--- /dev/null
+++ b/Java/com/phidgets/event/AccelerationChangeListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a AccelerationChangeEvent. This event originates from the Phidget Accelerometer
+ *
+ * @author Phidgets Inc.
+ */
+public interface AccelerationChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void accelerationChanged(AccelerationChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/AttachEvent.java b/Java/com/phidgets/event/AttachEvent.java
new file mode 100644
index 0000000..eecb7b0
--- /dev/null
+++ b/Java/com/phidgets/event/AttachEvent.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a AttachEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class AttachEvent
+{
+ Phidget source;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public AttachEvent(Phidget source) {
+ this.source = source;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString();
+ }
+}
diff --git a/Java/com/phidgets/event/AttachListener.java b/Java/com/phidgets/event/AttachListener.java
new file mode 100644
index 0000000..5fe8c00
--- /dev/null
+++ b/Java/com/phidgets/event/AttachListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a AttachEvent. This event originates from all Phidgets.
+ *
+ * @author Phidgets Inc.
+ */
+public interface AttachListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void attached(AttachEvent ae);
+}
diff --git a/Java/com/phidgets/event/BackEMFUpdateEvent.java b/Java/com/phidgets/event/BackEMFUpdateEvent.java
new file mode 100644
index 0000000..7dace73
--- /dev/null
+++ b/Java/com/phidgets/event/BackEMFUpdateEvent.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a BackEMFUpdateEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class BackEMFUpdateEvent
+{
+ Phidget source;
+ int index;
+ double voltage;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public BackEMFUpdateEvent(Phidget source, int index, double voltage)
+ {
+ this.source = source;
+ this.index = index;
+ this.voltage = voltage;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the motor.
+ *
+ * @return the index of the motor
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the backEMF value.
+ *
+ * @return the backEMF value
+ */
+ public double getVoltage() {
+ return voltage;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " BackEMF Value " + index + " is "
+ + voltage;
+ }
+}
diff --git a/Java/com/phidgets/event/BackEMFUpdateListener.java b/Java/com/phidgets/event/BackEMFUpdateListener.java
new file mode 100644
index 0000000..9a99a97
--- /dev/null
+++ b/Java/com/phidgets/event/BackEMFUpdateListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a BackEMFUpdateEvent. This event originates from the
+ * Phidget Motor Control. This event is not supported by all Motor Controllers.
+ *
+ * @author Phidgets Inc.
+ */
+public interface BackEMFUpdateListener
+{
+ /**
+ * This method is called with the event data every 16ms, when back EMF sensing is enabled for that motor.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void backEMFUpdated(BackEMFUpdateEvent ae);
+}
diff --git a/Java/com/phidgets/event/BridgeDataEvent.java b/Java/com/phidgets/event/BridgeDataEvent.java
new file mode 100644
index 0000000..3dd1578
--- /dev/null
+++ b/Java/com/phidgets/event/BridgeDataEvent.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a BridgeDataEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class BridgeDataEvent
+{
+ Phidget source;
+ int index;
+ double value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public BridgeDataEvent(Phidget source, int index, double value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the bridge.
+ *
+ * @return the index of the bridge
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Retuns the bridge value, in mV/V.
+ *
+ * @return the bridge value
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " bridge " + index + " value changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/BridgeDataListener.java b/Java/com/phidgets/event/BridgeDataListener.java
new file mode 100644
index 0000000..de2f993
--- /dev/null
+++ b/Java/com/phidgets/event/BridgeDataListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+/**
+ * This interface represents a BridgeDataEvent. This event originates from the Phidget Bridge
+ *
+ * @author Phidgets Inc.
+ */
+public interface BridgeDataListener
+{
+ /**
+ * This method is called with the event data when a new event arrives. The event is issued at the specified data rate, for
+ * each enabled bridge.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void bridgeData(BridgeDataEvent ae);
+}
diff --git a/Java/com/phidgets/event/CodeEvent.java b/Java/com/phidgets/event/CodeEvent.java
new file mode 100644
index 0000000..0cb5336
--- /dev/null
+++ b/Java/com/phidgets/event/CodeEvent.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+import com.phidgets.IRCode;
+
+/**
+ * This class represents the data for a CodeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class CodeEvent
+{
+ Phidget source;
+ IRCode code;
+ boolean repeat;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ * @param code the IR code
+ * @param repeat whether the code is a repeat
+ */
+ public CodeEvent(Phidget source, IRCode code, boolean repeat)
+ {
+ this.source = source;
+ this.code = code;
+ this.repeat = repeat;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the code.
+ *
+ * @return the code
+ */
+ public IRCode getCode() {
+ return code;
+ }
+
+ /**
+ * Returns the repeat identifier.
+ *
+ * @return whether this is a repeat
+ */
+ public boolean getRepeat() {
+ return repeat;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Code: "
+ + code.toString();
+ }
+}
diff --git a/Java/com/phidgets/event/CodeListener.java b/Java/com/phidgets/event/CodeListener.java
new file mode 100644
index 0000000..30bdde1
--- /dev/null
+++ b/Java/com/phidgets/event/CodeListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a CodeEvent. This event originates from the Phidget IR.
+ * This event occurs when a code is seen by the reader.
+ *
+ * @author Phidgets Inc.
+ */
+public interface CodeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void code(CodeEvent ae);
+}
diff --git a/Java/com/phidgets/event/CurrentChangeEvent.java b/Java/com/phidgets/event/CurrentChangeEvent.java
new file mode 100644
index 0000000..b279ce8
--- /dev/null
+++ b/Java/com/phidgets/event/CurrentChangeEvent.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a CurrentChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class CurrentChangeEvent
+{
+ Phidget source;
+ int index;
+ double value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public CurrentChangeEvent(Phidget source, int index, double value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the motor.
+ *
+ * @return the index of the motor
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the current of the motor. This is a representation of the ammount of current being used by the motor.
+ *
+ * @return the motor's current draw
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " current " + index + " changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/CurrentChangeListener.java b/Java/com/phidgets/event/CurrentChangeListener.java
new file mode 100644
index 0000000..f45681c
--- /dev/null
+++ b/Java/com/phidgets/event/CurrentChangeListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a CurrentChangeEvent. This event originates from the Phidget Motor Controller.
+ * This event is not supported by all Motor Controllers.
+ *
+ * @author Phidgets Inc.
+ */
+public interface CurrentChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void currentChanged(CurrentChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/CurrentUpdateEvent.java b/Java/com/phidgets/event/CurrentUpdateEvent.java
new file mode 100644
index 0000000..12265e5
--- /dev/null
+++ b/Java/com/phidgets/event/CurrentUpdateEvent.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a CurrentUpdateEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class CurrentUpdateEvent
+{
+ Phidget source;
+ int index;
+ double value;
+
+ /**
+ * Class constructor. This is called internally by the Phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public CurrentUpdateEvent(Phidget source, int index, double value)
+ {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the motor.
+ *
+ * @return the index of the motor
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the current of the motor. This is a representation of the amount of current being used by the motor.
+ *
+ * @return the motor's current draw
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " current " + index + " is "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/CurrentUpdateListener.java b/Java/com/phidgets/event/CurrentUpdateListener.java
new file mode 100644
index 0000000..20a6784
--- /dev/null
+++ b/Java/com/phidgets/event/CurrentUpdateListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a CurrentUpdateEvent. This event originates from the Phidget Motor Controller. This event is not supported by all Motor Controllers.
+ *
+ * @author Phidgets Inc.
+ */
+public interface CurrentUpdateListener
+{
+ /**
+ * This method is called with every 8ms.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void currentUpdated(CurrentUpdateEvent ae);
+}
diff --git a/Java/com/phidgets/event/DetachEvent.java b/Java/com/phidgets/event/DetachEvent.java
new file mode 100644
index 0000000..97bfe29
--- /dev/null
+++ b/Java/com/phidgets/event/DetachEvent.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a DetachEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class DetachEvent
+{
+ Phidget source;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public DetachEvent(Phidget source) {
+ this.source = source;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString();
+ }
+}
diff --git a/Java/com/phidgets/event/DetachListener.java b/Java/com/phidgets/event/DetachListener.java
new file mode 100644
index 0000000..b74e0ec
--- /dev/null
+++ b/Java/com/phidgets/event/DetachListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a DetachEvent. This event originates from all Phidgets, as well as the Phidget Manager.
+ *
+ * @author Phidgets Inc.
+ */
+public interface DetachListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void detached(DetachEvent ae);
+}
diff --git a/Java/com/phidgets/event/EncoderPositionChangeEvent.java b/Java/com/phidgets/event/EncoderPositionChangeEvent.java
new file mode 100644
index 0000000..52118a7
--- /dev/null
+++ b/Java/com/phidgets/event/EncoderPositionChangeEvent.java
@@ -0,0 +1,84 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a EncoderPositionChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class EncoderPositionChangeEvent
+{
+ Phidget source;
+ int index;
+ int value;
+ int time;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public EncoderPositionChangeEvent(Phidget source, int index, int time, int value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ this.time = time;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the encoder.
+ *
+ * @return the index of the encoder
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the position change of the encoder. This is the amount of change in the encoder's position
+ * since the last {@link #EncoderPositionChangeEvent}.
+ *
+ * @return the change in position of the encoder
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Returns the timestamp of this position change. This is the time since the last {@link #EncoderPositionChangeEvent}.
+ * This time is not represented in a real quantitly such as seconds, but can be used as a qualitative quantity.
+ *
+ * @return the timestamp of this change event
+ */
+ public int getTime()
+ {
+ return time;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+
+ return source.toString() + " encoder position " + index + " changed by "
+ + value + " Time: " + time;
+ }
+}
diff --git a/Java/com/phidgets/event/EncoderPositionChangeListener.java b/Java/com/phidgets/event/EncoderPositionChangeListener.java
new file mode 100644
index 0000000..dabdb08
--- /dev/null
+++ b/Java/com/phidgets/event/EncoderPositionChangeListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents an EncoderPositionChangeEvent. This event originates from the Phidget Encoder and the Phidget Motor Controller. This event is not supported by all Motor Controllers.
+ *
+ * @author Phidgets Inc.
+ */
+public interface EncoderPositionChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void encoderPositionChanged(EncoderPositionChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/EncoderPositionUpdateEvent.java b/Java/com/phidgets/event/EncoderPositionUpdateEvent.java
new file mode 100644
index 0000000..8124b04
--- /dev/null
+++ b/Java/com/phidgets/event/EncoderPositionUpdateEvent.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a EncoderPositionUpdateEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class EncoderPositionUpdateEvent
+{
+ Phidget source;
+ int index;
+ int value;
+
+ /**
+ * Class constructor. This is called internally by the Phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public EncoderPositionUpdateEvent(Phidget source, int index, int value)
+ {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the encoder.
+ *
+ * @return the index of the encoder
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the position change of the encoder. This is the amount of change in the encoder's position
+ * since the last {@link #EncoderPositionUpdateEvent}.
+ *
+ * @return the change in position of the encoder
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+
+ return source.toString() + " encoder position " + index + " is "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/EncoderPositionUpdateListener.java b/Java/com/phidgets/event/EncoderPositionUpdateListener.java
new file mode 100644
index 0000000..f16c899
--- /dev/null
+++ b/Java/com/phidgets/event/EncoderPositionUpdateListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents an EncoderPositionUpdateEvent. This event originates from the Phidget Motor Controller. This event is not supported by all Motor Controllers.
+ *
+ * @author Phidgets Inc.
+ */
+public interface EncoderPositionUpdateListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void encoderPositionUpdated(EncoderPositionUpdateEvent ae);
+}
diff --git a/Java/com/phidgets/event/ErrorEvent.java b/Java/com/phidgets/event/ErrorEvent.java
new file mode 100644
index 0000000..e0dc374
--- /dev/null
+++ b/Java/com/phidgets/event/ErrorEvent.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+import com.phidgets.PhidgetException;
+
+/**
+ * This class represents the data for a ErrorEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class ErrorEvent
+{
+ Phidget source;
+ PhidgetException exception;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public ErrorEvent(Phidget source, PhidgetException ex) {
+ this.source = source;
+ this.exception = ex;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the exception that describes the error.
+ *
+ * @return the event exception
+ */
+ public PhidgetException getException()
+ {
+ return exception;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return "Error Event (" + exception.getErrorNumber() + "): " + exception.getDescription();
+ }
+}
diff --git a/Java/com/phidgets/event/ErrorListener.java b/Java/com/phidgets/event/ErrorListener.java
new file mode 100644
index 0000000..a1a0207
--- /dev/null
+++ b/Java/com/phidgets/event/ErrorListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a ErrorEvent. This event originates from all Phidgets.
+ * It is used for asynchronous error handling.
+ *
+ * @author Phidgets Inc.
+ */
+public interface ErrorListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void error(ErrorEvent ae);
+}
diff --git a/Java/com/phidgets/event/FrequencyCounterCountEvent.java b/Java/com/phidgets/event/FrequencyCounterCountEvent.java
new file mode 100644
index 0000000..4a9291b
--- /dev/null
+++ b/Java/com/phidgets/event/FrequencyCounterCountEvent.java
@@ -0,0 +1,81 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a FrequencyCounterCountEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class FrequencyCounterCountEvent
+{
+ Phidget source;
+ int index;
+ int time;
+ int count;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public FrequencyCounterCountEvent(Phidget source, int index, int time, int count) {
+ this.source = source;
+ this.index = index;
+ this.time = time;
+ this.count = count;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the channel.
+ *
+ * @return the index of the channel
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the amount of time in which the number of counts occured, in microseconds.
+ *
+ * @return the amount of time in which the number of counts occured
+ */
+ public int getTime() {
+ return time;
+ }
+
+ /**
+ * Returns the number of counts detected.
+ *
+ * @return the number of counts detected
+ */
+ public int getCount() {
+ return count;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+
+ return source.toString() + " Channel " + index + ": " + count + " pulses in "
+ + time + " miroseconds";
+ }
+}
diff --git a/Java/com/phidgets/event/FrequencyCounterCountListener.java b/Java/com/phidgets/event/FrequencyCounterCountListener.java
new file mode 100644
index 0000000..fd19348
--- /dev/null
+++ b/Java/com/phidgets/event/FrequencyCounterCountListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a FrequencyCounterCountEvent. This event originates from the Phidget Frequency Counter
+ *
+ * @author Phidgets Inc.
+ */
+public interface FrequencyCounterCountListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void frequencyCounterCounted(FrequencyCounterCountEvent ae);
+}
diff --git a/Java/com/phidgets/event/GPSPositionChangeEvent.java b/Java/com/phidgets/event/GPSPositionChangeEvent.java
new file mode 100644
index 0000000..42b9199
--- /dev/null
+++ b/Java/com/phidgets/event/GPSPositionChangeEvent.java
@@ -0,0 +1,80 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a GPSPositionChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class GPSPositionChangeEvent
+{
+ Phidget source;
+ double latitude;
+ double longitude;
+ double altitude;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public GPSPositionChangeEvent(Phidget source, double latitude, double longitude, double altitude) {
+ this.source = source;
+ this.latitude = latitude;
+ this.longitude = longitude;
+ this.altitude = altitude;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the latitude of the GPS, in signed degrees format.
+ *
+ * @return the latitude
+ */
+ public double getLatitude() {
+ return latitude;
+ }
+
+ /**
+ * Returns the longitude of the GPS, in signed degrees format
+ *
+ * @return the longitude
+ */
+ public double getLongitude() {
+ return longitude;
+ }
+
+ /**
+ * Returns the altitude of the GPS, in meters.
+ *
+ * @return the altitude
+ */
+ public double getAltitude() {
+ return altitude;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return("Position is - Latitude: "+ latitude + " degrees" +
+ ", Longitude: " + longitude + " degrees" + ", Altitude: "+ altitude + "m");
+ }
+}
diff --git a/Java/com/phidgets/event/GPSPositionChangeListener.java b/Java/com/phidgets/event/GPSPositionChangeListener.java
new file mode 100644
index 0000000..dceb712
--- /dev/null
+++ b/Java/com/phidgets/event/GPSPositionChangeListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a GPSPositionChangeEvent. This event originates from the Phidget GPS
+ *
+ * @author Phidgets Inc.
+ */
+public interface GPSPositionChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void gpsPositionChanged(GPSPositionChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/GPSPositionFixStatusChangeEvent.java b/Java/com/phidgets/event/GPSPositionFixStatusChangeEvent.java
new file mode 100644
index 0000000..94f08a9
--- /dev/null
+++ b/Java/com/phidgets/event/GPSPositionFixStatusChangeEvent.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a GPSPositionFixStatusChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class GPSPositionFixStatusChangeEvent
+{
+ Phidget source;
+ boolean status;
+
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public GPSPositionFixStatusChangeEvent(Phidget source, boolean status) {
+ this.source = source;
+ this.status = status;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the position fix status of the GPS.
+ *
+ * @return the position fix status
+ */
+ public boolean getStatus() {
+ return status;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return("Position fix status IS : " + status);
+ }
+}
diff --git a/Java/com/phidgets/event/GPSPositionFixStatusChangeListener.java b/Java/com/phidgets/event/GPSPositionFixStatusChangeListener.java
new file mode 100644
index 0000000..2768cea
--- /dev/null
+++ b/Java/com/phidgets/event/GPSPositionFixStatusChangeListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a GPSPositionFixStatusChangeEvent. This event originates from the Phidget GPS
+ *
+ * @author Phidgets Inc.
+ */
+public interface GPSPositionFixStatusChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void gpsPositionFixStatusChanged(GPSPositionFixStatusChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/InputChangeEvent.java b/Java/com/phidgets/event/InputChangeEvent.java
new file mode 100644
index 0000000..273bb9b
--- /dev/null
+++ b/Java/com/phidgets/event/InputChangeEvent.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a InputChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class InputChangeEvent
+{
+ Phidget source;
+ int index;
+ boolean state;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public InputChangeEvent(Phidget source, int index, boolean state) {
+ this.source = source;
+ this.index = index;
+ this.state = state;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the digital input.
+ *
+ * @return the index of the input
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the state of the input. True indicates that it is activated, False indicated the default state.
+ *
+ * @return the state of the input
+ */
+ public boolean getState() {
+ return state;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " input " + index + " changed to "
+ + state;
+ }
+}
diff --git a/Java/com/phidgets/event/InputChangeListener.java b/Java/com/phidgets/event/InputChangeListener.java
new file mode 100644
index 0000000..c63ade9
--- /dev/null
+++ b/Java/com/phidgets/event/InputChangeListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a InputChangeEvent. This event originates from the Phidget Encoder, the Phidget InterfaceKit,
+ * and the Phidget Motor Controller.
+ *
+ * @author Phidgets Inc.
+ */
+public interface InputChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void inputChanged(InputChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/KeyChangeEvent.java b/Java/com/phidgets/event/KeyChangeEvent.java
new file mode 100644
index 0000000..fe86cda
--- /dev/null
+++ b/Java/com/phidgets/event/KeyChangeEvent.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2006 Dictionarys Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Dictionary;
+
+/**
+ * This class represents the data for a KeyChangeEvent.
+ *
+ * @author Dictionarys Inc.
+ */
+public class KeyChangeEvent
+{
+ Dictionary source;
+ String value;
+ String key;
+
+ /**
+ * Class constructor. This is called internally by the Dictionary library when creating this event.
+ *
+ * @param source the Dictionary object from which this event originated
+ */
+ public KeyChangeEvent(Dictionary source, String key, String value)
+ {
+ this.source = source;
+ this.value = value;
+ this.key = key;
+ }
+
+ /**
+ * Returns the source Dictionary of this event. This is a reference to the Dictionary object from which this
+ * event was called. This object can be cast into a specific type of Dictionary object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Dictionary getSource() {
+ return source;
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString()
+ {
+ return source.toString() + " Key changed: "
+ + key + ":" + value;
+ }
+}
diff --git a/Java/com/phidgets/event/KeyChangeListener.java b/Java/com/phidgets/event/KeyChangeListener.java
new file mode 100644
index 0000000..07772c2
--- /dev/null
+++ b/Java/com/phidgets/event/KeyChangeListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a KeyChangeEvent. This event originates from the Phidget Dictionary. Key Change events
+ * occur when key that matches the listen pattern is either added or changes in the Dictionary.
+ *
+ * @author Phidgets Inc.
+ */
+public interface KeyChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void keyChanged(KeyChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/KeyRemovalEvent.java b/Java/com/phidgets/event/KeyRemovalEvent.java
new file mode 100644
index 0000000..1a7fe9f
--- /dev/null
+++ b/Java/com/phidgets/event/KeyRemovalEvent.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2006 Dictionarys Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Dictionary;
+
+/**
+ * This class represents the data for a KeyRemovalEvent.
+ *
+ * @author Dictionarys Inc.
+ */
+public class KeyRemovalEvent
+{
+ Dictionary source;
+ String value;
+ String key;
+
+ /**
+ * Class constructor. This is called internally by the Dictionary library when creating this event.
+ *
+ * @param source the Dictionary object from which this event originated
+ */
+ public KeyRemovalEvent(Dictionary source, String key, String value)
+ {
+ this.source = source;
+ this.value = value;
+ this.key = key;
+ }
+
+ /**
+ * Returns the source Dictionary of this event. This is a reference to the Dictionary object from which this
+ * event was called. This object can be cast into a specific type of Dictionary object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Dictionary getSource() {
+ return source;
+ }
+
+ public String getKey()
+ {
+ return key;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Key removed: "
+ + key + ":" + value;
+ }
+}
diff --git a/Java/com/phidgets/event/KeyRemovalListener.java b/Java/com/phidgets/event/KeyRemovalListener.java
new file mode 100644
index 0000000..bac9a92
--- /dev/null
+++ b/Java/com/phidgets/event/KeyRemovalListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a KeyRemovalEvent. This event originates from the Phidget Dictionary.
+ * This event occurs key that matches the listen pattern is removed.
+ *
+ * @author Phidgets Inc.
+ */
+public interface KeyRemovalListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void keyRemoved(KeyRemovalEvent ae);
+}
diff --git a/Java/com/phidgets/event/LearnEvent.java b/Java/com/phidgets/event/LearnEvent.java
new file mode 100644
index 0000000..f0a784d
--- /dev/null
+++ b/Java/com/phidgets/event/LearnEvent.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+import com.phidgets.IRLearnedCode;
+
+/**
+ * This class represents the data for a LearnEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class LearnEvent
+{
+ Phidget source;
+ IRLearnedCode value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public LearnEvent(Phidget source, IRLearnedCode value)
+ {
+ this.source = source;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the learned code.
+ *
+ * @return the learned code
+ */
+ public IRLearnedCode getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Learned Code: "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/LearnListener.java b/Java/com/phidgets/event/LearnListener.java
new file mode 100644
index 0000000..174aa30
--- /dev/null
+++ b/Java/com/phidgets/event/LearnListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a LearnEvent. This event originates from the Phidget IR.
+ * This event occurs when a code is learned by the reader.
+ *
+ * @author Phidgets Inc.
+ */
+public interface LearnListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void learn(LearnEvent ae);
+}
diff --git a/Java/com/phidgets/event/MotorVelocityChangeEvent.java b/Java/com/phidgets/event/MotorVelocityChangeEvent.java
new file mode 100644
index 0000000..b3aef63
--- /dev/null
+++ b/Java/com/phidgets/event/MotorVelocityChangeEvent.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a MotorVelocityChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class MotorVelocityChangeEvent
+{
+ Phidget source;
+ int index;
+ double value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public MotorVelocityChangeEvent(Phidget source, int index, double value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the motor.
+ *
+ * @return the index of the motor
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Return the velocity of the motor. This is reported back from the motor controller as the motor changes speed.
+ *
+ * @return the motor velocity
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " motor velocity " + index + " changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/MotorVelocityChangeListener.java b/Java/com/phidgets/event/MotorVelocityChangeListener.java
new file mode 100644
index 0000000..88cd722
--- /dev/null
+++ b/Java/com/phidgets/event/MotorVelocityChangeListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a MotorVelocityChangeEvent. This event originates from the Phidget Motor Controller
+ *
+ * @author Phidgets Inc.
+ */
+public interface MotorVelocityChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void motorVelocityChanged(MotorVelocityChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/OutputChangeEvent.java b/Java/com/phidgets/event/OutputChangeEvent.java
new file mode 100644
index 0000000..01e6af5
--- /dev/null
+++ b/Java/com/phidgets/event/OutputChangeEvent.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a OutputChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class OutputChangeEvent
+{
+ Phidget source;
+ int index;
+ boolean state;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public OutputChangeEvent(Phidget source, int index, boolean state) {
+ this.source = source;
+ this.index = index;
+ this.state = state;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the output.
+ *
+ * @return the index of the output
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the state of the output. True indicated that the output is active, False indicated the default inactive state.
+ *
+ * @return the state of the output
+ */
+ public boolean getState() {
+ return state;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " output " + index + " changed to "
+ + state;
+ }
+}
diff --git a/Java/com/phidgets/event/OutputChangeListener.java b/Java/com/phidgets/event/OutputChangeListener.java
new file mode 100644
index 0000000..998ffbf
--- /dev/null
+++ b/Java/com/phidgets/event/OutputChangeListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a OutputChangeEvent. This event originates from the
+ * Phidget Interface Kit and the Phidget RFID Reader
+ *
+ * @author Phidgets Inc.
+ */
+public interface OutputChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void outputChanged(OutputChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/PHChangeEvent.java b/Java/com/phidgets/event/PHChangeEvent.java
new file mode 100644
index 0000000..a885132
--- /dev/null
+++ b/Java/com/phidgets/event/PHChangeEvent.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a PHChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class PHChangeEvent
+{
+ Phidget source;
+ double value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public PHChangeEvent(Phidget source, double value) {
+ this.source = source;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the pH. This value can range from 0-14
+ *
+ * @return the pH
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " ph changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/PHChangeListener.java b/Java/com/phidgets/event/PHChangeListener.java
new file mode 100644
index 0000000..0791631
--- /dev/null
+++ b/Java/com/phidgets/event/PHChangeListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a PHChangeEvent. This event originates from the Phidget PH Sensor
+ *
+ * @author Phidgets Inc.
+ */
+public interface PHChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void phChanged(PHChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/RawDataEvent.java b/Java/com/phidgets/event/RawDataEvent.java
new file mode 100644
index 0000000..ba0c644
--- /dev/null
+++ b/Java/com/phidgets/event/RawDataEvent.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a RawDataEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class RawDataEvent
+{
+ Phidget source;
+ int[] data;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public RawDataEvent(Phidget source, int[] data)
+ {
+ this.source = source;
+ this.data = new int[data.length];
+ for(int i=0;i<data.length;i++)
+ this.data[i] = data[i];
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the raw data.
+ *
+ * @return the raw data
+ */
+ public int[] getData() {
+ return data;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ String out = " Raw data:";
+ for(int i=0;i<data.length;i++)
+ {
+ if(i%8 == 0) out = out + "\n";
+ if(data[i]==com.phidgets.IRPhidget.RAWDATA_LONGSPACE)
+ out = out + "LONG";
+ else
+ out = out + data[i];
+ if((i+1)%8 != 0) out = out + ", ";
+ }
+ return out;
+ }
+}
diff --git a/Java/com/phidgets/event/RawDataListener.java b/Java/com/phidgets/event/RawDataListener.java
new file mode 100644
index 0000000..2a656bd
--- /dev/null
+++ b/Java/com/phidgets/event/RawDataListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a RawDataEvent. This event originates from the Phidget IR.
+ * This event occurs when the reader sees IR data.
+ *
+ * @author Phidgets Inc.
+ */
+public interface RawDataListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void rawData(RawDataEvent ae);
+}
diff --git a/Java/com/phidgets/event/SensorChangeEvent.java b/Java/com/phidgets/event/SensorChangeEvent.java
new file mode 100644
index 0000000..fce96ca
--- /dev/null
+++ b/Java/com/phidgets/event/SensorChangeEvent.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a SensorChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class SensorChangeEvent
+{
+ Phidget source;
+ int index;
+ int value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public SensorChangeEvent(Phidget source, int index, int value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the sensor.
+ *
+ * @return the index of the sensor
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Retuns the value of the sensor. This value can range from 0-1000.
+ *
+ * @return the value of the sensor
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " sensor " + index + " changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/SensorChangeListener.java b/Java/com/phidgets/event/SensorChangeListener.java
new file mode 100644
index 0000000..5a4cb40
--- /dev/null
+++ b/Java/com/phidgets/event/SensorChangeListener.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+/**
+ * This interface represents a SensorChangeEvent. This event originates from the Phidget Interface Kit
+ *
+ * @author Phidgets Inc.
+ */
+public interface SensorChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void sensorChanged(SensorChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/SensorUpdateEvent.java b/Java/com/phidgets/event/SensorUpdateEvent.java
new file mode 100644
index 0000000..24edd6e
--- /dev/null
+++ b/Java/com/phidgets/event/SensorUpdateEvent.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a SensorUpdateEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class SensorUpdateEvent
+{
+ Phidget source;
+ int index;
+ int value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public SensorUpdateEvent(Phidget source, int index, int value)
+ {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the sensor.
+ *
+ * @return the index of the sensor
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Retuns the value of the sensor. This value ranges from 0-1000.
+ *
+ * @return the value of the sensor
+ */
+ public int getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " sensor " + index + " is "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/SensorUpdateListener.java b/Java/com/phidgets/event/SensorUpdateListener.java
new file mode 100644
index 0000000..5c491cc
--- /dev/null
+++ b/Java/com/phidgets/event/SensorUpdateListener.java
@@ -0,0 +1,19 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+/**
+ * This interface represents a SensorUpdateEvent. This event originates from the Phidget Motor Control
+ *
+ * @author Phidgets Inc.
+ */
+public interface SensorUpdateListener
+{
+ /**
+ * This method is called with the event data every 8ms.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void sensorUpdated(SensorUpdateEvent ae);
+}
diff --git a/Java/com/phidgets/event/ServerConnectEvent.java b/Java/com/phidgets/event/ServerConnectEvent.java
new file mode 100644
index 0000000..cc89dde
--- /dev/null
+++ b/Java/com/phidgets/event/ServerConnectEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a ServerConnectEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class ServerConnectEvent
+{
+ Object source;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the object from which this event originated
+ */
+ public ServerConnectEvent(Object source)
+ {
+ this.source = source;
+ }
+
+ /**
+ * Returns the source Object of this event. This is a reference to the object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Object getSource()
+ {
+ return source;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString();
+ }
+}
diff --git a/Java/com/phidgets/event/ServerConnectListener.java b/Java/com/phidgets/event/ServerConnectListener.java
new file mode 100644
index 0000000..5667a30
--- /dev/null
+++ b/Java/com/phidgets/event/ServerConnectListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a ServerConnectEvent. This event originates from all Phidgets.
+ *
+ * @author Phidgets Inc.
+ */
+public interface ServerConnectListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void serverConnected(ServerConnectEvent ae);
+}
diff --git a/Java/com/phidgets/event/ServerDisconnectEvent.java b/Java/com/phidgets/event/ServerDisconnectEvent.java
new file mode 100644
index 0000000..1b4740d
--- /dev/null
+++ b/Java/com/phidgets/event/ServerDisconnectEvent.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a ServerDisconnectEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class ServerDisconnectEvent
+{
+ Object source;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the object from which this event originated
+ */
+ public ServerDisconnectEvent(Object source)
+ {
+ this.source = source;
+ }
+
+ /**
+ * Returns the source Object of this event. This is a reference to the object from which this
+ * event was called. This object can be cast into a specific type of object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Object getSource()
+ {
+ return source;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString();
+ }
+}
diff --git a/Java/com/phidgets/event/ServerDisconnectListener.java b/Java/com/phidgets/event/ServerDisconnectListener.java
new file mode 100644
index 0000000..93df8f9
--- /dev/null
+++ b/Java/com/phidgets/event/ServerDisconnectListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a ServerDisconnectEvent. This event originates from all Phidgets.
+ *
+ * @author Phidgets Inc.
+ */
+public interface ServerDisconnectListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void serverDisconnected(ServerDisconnectEvent ae);
+}
diff --git a/Java/com/phidgets/event/ServoPositionChangeEvent.java b/Java/com/phidgets/event/ServoPositionChangeEvent.java
new file mode 100644
index 0000000..f685964
--- /dev/null
+++ b/Java/com/phidgets/event/ServoPositionChangeEvent.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a ServoPositionChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class ServoPositionChangeEvent
+{
+ Phidget source;
+ int index;
+ double value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public ServoPositionChangeEvent(Phidget source, int index, double value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the servo motor.
+ *
+ * @return index of the servo
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the position of the servo motor. This is esentially just the last position that the
+ * servo was set to, echoed back from the controller board.
+ *
+ * @return position of the servo
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " servo position " + index + " changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/ServoPositionChangeListener.java b/Java/com/phidgets/event/ServoPositionChangeListener.java
new file mode 100644
index 0000000..00e8cf8
--- /dev/null
+++ b/Java/com/phidgets/event/ServoPositionChangeListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a ServoPositionChangeEvent. This event originates from the Phidget Servo Controller and the
+ * Phidget Advanced Servo Controller.
+ *
+ * @author Phidgets Inc.
+ */
+public interface ServoPositionChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void servoPositionChanged(ServoPositionChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/ServoVelocityChangeEvent.java b/Java/com/phidgets/event/ServoVelocityChangeEvent.java
new file mode 100644
index 0000000..9c43651
--- /dev/null
+++ b/Java/com/phidgets/event/ServoVelocityChangeEvent.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a ServoVelocityChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class ServoVelocityChangeEvent
+{
+ Phidget source;
+ int index;
+ double value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public ServoVelocityChangeEvent(Phidget source, int index, double value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the Servo.
+ *
+ * @return the index of the servo
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Return the velocity of the Servo. This is reported back from the Servo controller as the Servo changes speed.
+ *
+ * @return the Servo velocity
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Servo velocity " + index + " changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/ServoVelocityChangeListener.java b/Java/com/phidgets/event/ServoVelocityChangeListener.java
new file mode 100644
index 0000000..962ca53
--- /dev/null
+++ b/Java/com/phidgets/event/ServoVelocityChangeListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a ServoVelocityChangeEvent. This event originates from the Phidget Advanced Servo Controller
+ *
+ * @author Phidgets Inc.
+ */
+public interface ServoVelocityChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void servoVelocityChanged(ServoVelocityChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/SpatialDataEvent.java b/Java/com/phidgets/event/SpatialDataEvent.java
new file mode 100644
index 0000000..e6c6dae
--- /dev/null
+++ b/Java/com/phidgets/event/SpatialDataEvent.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+import com.phidgets.SpatialEventData;
+
+/**
+ * This class represents the data for a SpatialDataEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class SpatialDataEvent
+{
+ Phidget source;
+ SpatialEventData[] data;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ * @param data the spatial data
+ */
+ public SpatialDataEvent(Phidget source, SpatialEventData[] data)
+ {
+ this.source = source;
+ this.data = data;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the data. This may contain multiple sets of data for high data rates.
+ *
+ * @return the data
+ */
+ public SpatialEventData[] getData() {
+ return data;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Spatial Data";
+ }
+}
diff --git a/Java/com/phidgets/event/SpatialDataListener.java b/Java/com/phidgets/event/SpatialDataListener.java
new file mode 100644
index 0000000..a381777
--- /dev/null
+++ b/Java/com/phidgets/event/SpatialDataListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a SpatialDataEvent. This event originates from the Phidget Spatial.
+ * This event occurs when spatial data comes in
+ *
+ * @author Phidgets Inc.
+ */
+public interface SpatialDataListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void data(SpatialDataEvent ae);
+}
diff --git a/Java/com/phidgets/event/StepperPositionChangeEvent.java b/Java/com/phidgets/event/StepperPositionChangeEvent.java
new file mode 100644
index 0000000..e002dd9
--- /dev/null
+++ b/Java/com/phidgets/event/StepperPositionChangeEvent.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a StepperPositionChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class StepperPositionChangeEvent
+{
+ Phidget source;
+ int index;
+ long value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public StepperPositionChangeEvent(Phidget source, int index, long value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the Stepper motor.
+ *
+ * @return index of the Stepper
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the position of the Stepper motor. This is esentially just the last position that the
+ * Stepper was set to, echoed back from the controller board.
+ *
+ * @return position of the Stepper
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Stepper position " + index + " changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/StepperPositionChangeListener.java b/Java/com/phidgets/event/StepperPositionChangeListener.java
new file mode 100644
index 0000000..b1cf3fc
--- /dev/null
+++ b/Java/com/phidgets/event/StepperPositionChangeListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a StepperPositionChangeEvent. This event originates from the Phidget Stepper Controller and the
+ * Phidget Advanced Stepper Controller.
+ *
+ * @author Phidgets Inc.
+ */
+public interface StepperPositionChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void stepperPositionChanged(StepperPositionChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/StepperVelocityChangeEvent.java b/Java/com/phidgets/event/StepperVelocityChangeEvent.java
new file mode 100644
index 0000000..6154170
--- /dev/null
+++ b/Java/com/phidgets/event/StepperVelocityChangeEvent.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a StepperVelocityChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class StepperVelocityChangeEvent
+{
+ Phidget source;
+ int index;
+ double value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public StepperVelocityChangeEvent(Phidget source, int index, double value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the Stepper.
+ *
+ * @return the index of the Stepper
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Return the velocity of the Stepper. This is reported back from the Stepper controller as the Stepper changes speed.
+ *
+ * @return the Stepper velocity
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Stepper velocity " + index + " changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/StepperVelocityChangeListener.java b/Java/com/phidgets/event/StepperVelocityChangeListener.java
new file mode 100644
index 0000000..b416441
--- /dev/null
+++ b/Java/com/phidgets/event/StepperVelocityChangeListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a StepperVelocityChangeEvent. This event originates from the Phidget Stepper Controller
+ *
+ * @author Phidgets Inc.
+ */
+public interface StepperVelocityChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void stepperVelocityChanged(StepperVelocityChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/TagGainEvent.java b/Java/com/phidgets/event/TagGainEvent.java
new file mode 100644
index 0000000..6cb7a74
--- /dev/null
+++ b/Java/com/phidgets/event/TagGainEvent.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a TagGainEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class TagGainEvent
+{
+ Phidget source;
+ String value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public TagGainEvent(Phidget source, String value)
+ {
+ this.source = source;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the gained tag. The tag is a 10 digit hex number represented as a string.
+ *
+ * @return the gained tag
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Tag Gained: "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/TagGainListener.java b/Java/com/phidgets/event/TagGainListener.java
new file mode 100644
index 0000000..df7b43f
--- /dev/null
+++ b/Java/com/phidgets/event/TagGainListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a TagGainEvent. This event originates from the Phidget RFID Reader.
+ * This event occurs when a tag is placed on a reader.
+ *
+ * @author Phidgets Inc.
+ */
+public interface TagGainListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void tagGained(TagGainEvent ae);
+}
diff --git a/Java/com/phidgets/event/TagLossEvent.java b/Java/com/phidgets/event/TagLossEvent.java
new file mode 100644
index 0000000..ccca4fe
--- /dev/null
+++ b/Java/com/phidgets/event/TagLossEvent.java
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a TagLossEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class TagLossEvent
+{
+ Phidget source;
+ String value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public TagLossEvent(Phidget source, String value)
+ {
+ this.source = source;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the Tag that was lost. This is a 10 digit hex number as a string.
+ *
+ * @return the lost tag
+ */
+ public String getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Tag lost: "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/TagLossListener.java b/Java/com/phidgets/event/TagLossListener.java
new file mode 100644
index 0000000..66a3a8a
--- /dev/null
+++ b/Java/com/phidgets/event/TagLossListener.java
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a TagLossEvent. This event originates from the Phidget RFID reader. Tag loss events
+ * occur when a tag is removed from the RFID reader.
+ *
+ * @author Phidgets Inc.
+ */
+public interface TagLossListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void tagLost(TagLossEvent ae);
+}
diff --git a/Java/com/phidgets/event/TemperatureChangeEvent.java b/Java/com/phidgets/event/TemperatureChangeEvent.java
new file mode 100644
index 0000000..5de528c
--- /dev/null
+++ b/Java/com/phidgets/event/TemperatureChangeEvent.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a TemperatureChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class TemperatureChangeEvent
+{
+ Phidget source;
+ int index;
+ double value;
+
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public TemperatureChangeEvent(Phidget source, int index, double value) {
+ this.source = source;
+ this.index = index;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the index of the temperature sensor. An index of 0 indicated the Cold Juction Temperature sensing IC.
+ * An index of 1 indicated the thermocouple.
+ *
+ * @return the index of the sensor
+ */
+ public int getIndex() {
+ return index;
+ }
+
+ /**
+ * Returns the temperature of the sensor is degrees celcius.
+ *
+ * @return the temperature of the sensor
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Temperature " + index + " changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/TemperatureChangeListener.java b/Java/com/phidgets/event/TemperatureChangeListener.java
new file mode 100644
index 0000000..a9eccb7
--- /dev/null
+++ b/Java/com/phidgets/event/TemperatureChangeListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a TemperatureChangeEvent. This event originates from the Phidget Temperature Sensor
+ *
+ * @author Phidgets Inc.
+ */
+public interface TemperatureChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void temperatureChanged(TemperatureChangeEvent ae);
+}
diff --git a/Java/com/phidgets/event/WeightChangeEvent.java b/Java/com/phidgets/event/WeightChangeEvent.java
new file mode 100644
index 0000000..1277003
--- /dev/null
+++ b/Java/com/phidgets/event/WeightChangeEvent.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+import com.phidgets.Phidget;
+
+/**
+ * This class represents the data for a WeightChangeEvent.
+ *
+ * @author Phidgets Inc.
+ */
+public class WeightChangeEvent
+{
+ Phidget source;
+ double value;
+ /**
+ * Class constructor. This is called internally by the phidget library when creating this event.
+ *
+ * @param source the Phidget object from which this event originated
+ */
+ public WeightChangeEvent(Phidget source, double value)
+ {
+ this.source = source;
+ this.value = value;
+ }
+
+ /**
+ * Returns the source Phidget of this event. This is a reference to the Phidget object from which this
+ * event was called. This object can be cast into a specific type of Phidget object to call specific
+ * device calls on it.
+ *
+ * @return the event caller
+ */
+ public Phidget getSource() {
+ return source;
+ }
+
+ /**
+ * Returns the weight in kg.
+ *
+ * @return the weight
+ */
+ public double getValue() {
+ return value;
+ }
+
+ /**
+ * Returns a string containing information about the event.
+ *
+ * @return an informative event string
+ */
+ public String toString() {
+ return source.toString() + " Weight changed to "
+ + value;
+ }
+}
diff --git a/Java/com/phidgets/event/WeightChangeListener.java b/Java/com/phidgets/event/WeightChangeListener.java
new file mode 100644
index 0000000..d6794db
--- /dev/null
+++ b/Java/com/phidgets/event/WeightChangeListener.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2006 Phidgets Inc. All rights reserved.
+ */
+
+package com.phidgets.event;
+
+/**
+ * This interface represents a WeightChangeEvent. This event originates from the Phidget Weight Sensor
+ *
+ * @author Phidgets Inc.
+ */
+public interface WeightChangeListener
+{
+ /**
+ * This method is called with the event data when a new event arrives.
+ *
+ * @param ae the event data object containing event data
+ */
+ public void weightChanged(WeightChangeEvent ae);
+}
diff --git a/Java/com/phidgets/macros/BridgePhidget.jm b/Java/com/phidgets/macros/BridgePhidget.jm
new file mode 100644
index 0000000..d2c2cf5
--- /dev/null
+++ b/Java/com/phidgets/macros/BridgePhidget.jm
@@ -0,0 +1,171 @@
+/*
+ * Copyright 2011 Phidgets Inc. All rights reserved.
+ */
+
+ #include "javamacros.h"
+PACKAGEIMPORTS
+/**
+ * This class represents a Phidget Bridge. All methods
+ * to manipulate the Phidget Bridge are implemented in this class.
+ * <p>
+ *
+ * @author Phidgets Inc.
+ */
+CLASSDEF(Bridge)
+ /**
+ * 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,)
+ /**
+ * 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)
+ /**
+ * 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)
+ /**
+ * 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)
+ /**
+ * 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)
+ /**
+ * 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)
+ /**
+ * 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)
+ /**
+ * 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)
+ /**
+ * 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,)
+ /**
+ * 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)
+ /**
+ * 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,)
+ /**
+ * 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,)
+
+ ENABLE_EVENTS
+ {
+ EVENT_ENABLE(bridgeData, BridgeData)
+ }
+ /**
+ * 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
+ */
+ EVENT(bridgeData, BridgeData, bridgeData)
+} \ No newline at end of file