frog.plugin
Interface Plugin

All Known Implementing Classes:
BluetoothPlugin, SpotPlugin

public interface Plugin

This interface should be implemented by any developer seeking to write code that will allow them to use their device with the FROG Recognizer of Gestures.

The class implementing this interface should create Device objects that have a unique ID as well as a type. Those Device objects will have a pointer back to the Plugin that created them to perform their methods. Device objects have a notifier method for when accelerations are streaming in. It would be a good idea to create an Object such as "FormalConnection" when a Device is connected and sending gesture data. This "FormalConnection" object would be able to call Device.notifyAcceleration(frog.Accel3D) method to get the acceleration data up to the FROG and GUI levels.

Author:
Team Better Recognize

Method Summary
 void addFilter(Device device, int id, String arg)
          Instruct the device to add a new filter to its filtering pipeline.
 void calibrate(Device device)
          Calibrates the accelerometers of the target device.
 void connect(Device device)
          Formally connect to a specified device.
 void disconnect(Device device)
          Disconnect a connected device.
 void disconnectAll()
          Disconnect from all devices known to this Plugin.
 void discover(Vector<Device> deviceList)
          A non-blocking method for finding nearby discoverable devices.
 String[] getActiveFilters(Device device)
          Returns a list of filters currently active on the device.
 String[] getAvailFilters()
          Returns a list of available filters that this device supports.
 int getSampleRate(Device device)
          Gets the current sampling rate of this Device in hertz.
 void removeFilter(Device device, int index)
          Removes a filter from the list of active filters on the Device.
 void resetFilters(Device device)
          Removes any filters currently active on the Device.
 void setSampleRate(Device device, int rate)
          Instructs this device to sample at a given rate.
 

Method Detail

addFilter

void addFilter(Device device,
               int id,
               String arg)
               throws IOException
Instruct the device to add a new filter to its filtering pipeline. If the device supports on-board filtering, this method should communicate both what type of filter to use as well as an argument string for that filter. The id should come from the getAvailFilters method (it is the index of the array of the desired filter).

Parameters:
device - the device to send the new filter information to
id - the filter desired. This should be the index from the array of filters.
arg - the argument String for this filter
Throws:
IOException - if any communication error occurs
See Also:
getAvailFilters(), Device.addFilter(int, String)

calibrate

void calibrate(Device device)
               throws IOException
Calibrates the accelerometers of the target device. If the device requires calibration or any adjustment before use, this method can be called to provide a custom GUI instructing the user on how to set up their device (such as setting it flat on a table or throwing it out a window).

Parameters:
device - the device to be calibrated
Throws:
IOException - if any communication error occurs
See Also:
Device.calibrate()

connect

void connect(Device device)
             throws IOException
Formally connect to a specified device. After the user has been presented with a list of discovered devices, the one they pick must be connected to so that a formal connection (and probably a new Thread) can be established and they can begin using the device.

Parameters:
device - the device to connect to
Throws:
IOException - if any communication error occurs. It should be assumed that if this exception is thrown, the device is NOT connected.
See Also:
Device.connect(DeviceListener)

disconnect

void disconnect(Device device)
                throws IOException
Disconnect a connected device. This method should tear down any facilities that were set up to support the device. This should be called by the user when they wish to disconnect the device.

Unlike unexpected disconnects (disconnects resulting from battery or communication failure), the disconnect() method should not notify DeviceListeners of anything. A call to this method means the disconnect is deliberate and expected.

Parameters:
device - the device to disconnect from
Throws:
IOException - if the device cannot be sent a disconnect signal. Regardless, a best attempt must be made to tear down any local resources tied to this device.
See Also:
Device.disconnect()

disconnectAll

void disconnectAll()
                   throws IOException
Disconnect from all devices known to this Plugin. Convenience method for FROG. Most likely to be called when FROG is in the process of shutting down.

Throws:
IOException - if any of the connected devices could not be sent a disconnect message. Regardless, FROG is probably shutting down and any local resources should be freed.

discover

void discover(Vector<Device> deviceList)
              throws IOException
A non-blocking method for finding nearby discoverable devices. Ideally this Plugin should broadcast a message looking for nearby devices. As devices are found, they should be placed on the deviceList. Implementing classes are encouraged to try and make the discovery of devices within 10 seconds. Devices that are found should not be connected to, but rather added to the given Vector<Device> so that the caller can view devices as they become available.

This method is expected to be non-blocking. That is, a Plugin should launch the discovery process in a separate Thread to allow other Plugins to perform their respective discoveries simultaneously.

Throws:
IOException - any catastrophic errors occur. Should ideally be thrown if the radio or other hardware is missing. Communication errors between the plugin and a device are not a sufficient cause to throw this exception.

getActiveFilters

String[] getActiveFilters(Device device)
                          throws IOException
Returns a list of filters currently active on the device. If the Device does not support on-device filtering, a null or empty array may be returned.

Returns:
the list of currently active filters on the device in the order in which they were instantiated
Throws:
IOException - if a list of active filters could not be obtained from the Device.
See Also:
Device.getActiveFilters()

getAvailFilters

String[] getAvailFilters()
Returns a list of available filters that this device supports. The array of strings returned by this method should be in a specific order as the index of the array will be used to communicate with the device later.

Returns:
a list of Strings containing the names of the filters supported
See Also:
Device.getAvailFilters()

getSampleRate

int getSampleRate(Device device)
                  throws IOException
Gets the current sampling rate of this Device in hertz.

Returns:
the sampling rate of this device in hertz
Throws:
IOException - if the current sample rate could not be obtained from the Device
See Also:
Device.getSampleRate()

removeFilter

void removeFilter(Device device,
                  int index)
                  throws IOException
Removes a filter from the list of active filters on the Device. This method does nothing at all if on-device filtering is not supported.

Parameters:
device - the Device to delete a filter from
index - the position on the Device's active filters list to remove
Throws:
IOException - if the filter on the Device could not be removed

resetFilters

void resetFilters(Device device)
                  throws IOException
Removes any filters currently active on the Device. This method makes it possible for the user to edit or remove filters the Device is performing. This method does nothing if on-device filtering cannot be done by this type of Device.

Parameters:
device - the Device to clear the filters on
Throws:
IOException - if any communication error occurs
See Also:
addFilter(Device, int, String), Device.resetFilters()

setSampleRate

void setSampleRate(Device device,
                   int rate)
                   throws IOException
Instructs this device to sample at a given rate. If this device is incompatible with setting a different sampling rate, this method does nothing.

Parameters:
rate - the rate to sample at in hertz
Throws:
IOException - if any communication error occurs