ketai.net.bluetooth

## Class KetaiBluetooth

- java.lang.Object
- - ketai.net.bluetooth.KetaiBluetooth

-     public class KetaiBluetooth
      extends java.lang.Object

  The Class KetaiBluetooth manages the bluetooth connections and service on the android device. This class has been tested and can manage multiple simultaneous bluetooth connections. The maximum number of connections varied by device limitations but 3 simultaneous connections were typical. To receive data from bluetooth connections a sketch should define the following method:
  void onBluetoothDataEvent(String who, byte[] data)
  who - the name of the device sending the data
  data - byte array of the data received

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected android.bluetooth.BluetoothAdapter` | `bluetoothAdapter` The bluetooth adapter.
    `protected java.util.UUID` | `MY_UUID_INSECURE` The my uuid insecure.
    `protected java.util.UUID` | `MY_UUID_SECURE` The my uuid secure.
    `protected java.lang.String` | `NAME_INSECURE` The name insecure.
    `protected java.lang.String` | `NAME_SECURE` The name secure.
    `protected java.lang.reflect.Method` | `onBluetoothDataEventMethod` The on bluetooth data event method.
    `protected processing.core.PApplet` | `parent` The parent.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `KetaiBluetooth(processing.core.PApplet _parent)` Instantiates a new ketai bluetooth instance

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `broadcast(byte[] data)` Send data to all conencted devices.
    `boolean` | `connectDevice(android.bluetooth.BluetoothSocket _socket)` Connect device.
    `boolean` | `connectDevice(java.lang.String _hwAddress)` Connect device by hardware address (more reliable since HW addresses are supposed to be unique.
    `boolean` | `connectDeviceUsingSLIP(java.lang.String _hwAddress)` Connect device using slip.
    `boolean` | `connectToDeviceByName(java.lang.String _name)` Connect to device by name.
    `void` | `discoverDevices()` Discover devices.
    `void` | `dispose()`
    `java.lang.String` | `getAddress()` Gets our hardware address.
    `android.bluetooth.BluetoothAdapter` | `getBluetoothAdapater()` Gets the bluetooth adapater.
    `java.util.ArrayList<java.lang.String>` | `getConnectedDeviceNames()` Gets the connected device names.
    `java.util.ArrayList<java.lang.String>` | `getDiscoveredDeviceNames()` Gets the discovered device names.
    `java.util.ArrayList<java.lang.String>` | `getPairedDeviceNames()` Gets the paired device names.
    `boolean` | `isDiscoverable()` Checks if we're discoverable.
    `boolean` | `isDiscovering()` Checks if we are discovering devices.
    `boolean` | `isStarted()` Checks if we've started.
    `java.lang.String` | `lookupAddressByName(java.lang.String _name)` Lookup address by name.
    `void` | `makeDiscoverable()` Make discoverable.
    `void` | `onActivityResult(int requestCode, int resultCode, android.content.Intent data)` On activity result.
    `protected void` | `removeConnection(KBluetoothConnection c)` Removes the connection.
    `void` | `setSLIPMode(boolean _flag)` Sets the sLIP mode(experimental).
    `boolean` | `start()` Start the service
    `void` | `stop()` Stop.
    `java.lang.String` | `toString()`
    `void` | `write(java.lang.String _deviceAddress, byte[] data)` Write data to a device through their hardware address
    `void` | `writeToDeviceName(java.lang.String _name, byte[] data)` Write to device name.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### parent

          protected processing.core.PApplet parent

      The parent.

    - #### bluetoothAdapter

          protected android.bluetooth.BluetoothAdapter bluetoothAdapter

      The bluetooth adapter.

    - #### onBluetoothDataEventMethod

          protected java.lang.reflect.Method onBluetoothDataEventMethod

      The on bluetooth data event method.

    - #### MY_UUID_SECURE

          protected java.util.UUID MY_UUID_SECURE

      The my uuid secure.

    - #### MY_UUID_INSECURE

          protected java.util.UUID MY_UUID_INSECURE

      The my uuid insecure.

    - #### NAME_SECURE

          protected java.lang.String NAME_SECURE

      The name secure.

    - #### NAME_INSECURE

          protected java.lang.String NAME_INSECURE

      The name insecure.

  - ### Constructor Detail

    - #### KetaiBluetooth

          public KetaiBluetooth(processing.core.PApplet _parent)

      Instantiates a new ketai bluetooth instance
      Parameters:
        `_parent` - the calling sketch/activity

  - ### Method Detail

    - #### setSLIPMode

          public void setSLIPMode(boolean _flag)

      Sets the sLIP mode(experimental).
      Parameters:
        `_flag` - the new sLIP mode

    - #### isStarted

          public boolean isStarted()

      Checks if we've started.
      Returns:
        true, if is started

    - #### getBluetoothAdapater

          public android.bluetooth.BluetoothAdapter getBluetoothAdapater()

      Gets the bluetooth adapater.
      Returns:
        the bluetooth adapater

    - #### isDiscovering

          public boolean isDiscovering()

      Checks if we are discovering devices.
      Returns:
        true, if we're discovering

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### onActivityResult

          public void onActivityResult(int requestCode,
                                       int resultCode,
                                       android.content.Intent data)

      On activity result.
      Parameters:
        `requestCode` - the request code
        `resultCode` - the result code
        `data` - the data from the activty result

    - #### isDiscoverable

          public boolean isDiscoverable()

      Checks if we're discoverable.
      Returns:
        true, if we're discoverable

    - #### start

          public boolean start()

      Start the service
      Returns:
        true, if successful

    - #### getAddress

          public java.lang.String getAddress()

      Gets our hardware address.
      Returns:
        the address

    - #### getDiscoveredDeviceNames

          public java.util.ArrayList<java.lang.String> getDiscoveredDeviceNames()

      Gets the discovered device names.
      Returns:
        discovered device names

    - #### getPairedDeviceNames

          public java.util.ArrayList<java.lang.String> getPairedDeviceNames()

      Gets the paired device names.
      Returns:
        paired device names

    - #### getConnectedDeviceNames

          public java.util.ArrayList<java.lang.String> getConnectedDeviceNames()

      Gets the connected device names.
      Returns:
        the connected device names

    - #### connectToDeviceByName

          public boolean connectToDeviceByName(java.lang.String _name)

      Connect to device by name.
      Parameters:
        `_name` - the _name
      Returns:
        true, if successful

    - #### connectDevice

          public boolean connectDevice(java.lang.String _hwAddress)

      Connect device by hardware address (more reliable since HW addresses are supposed to be unique.
      Parameters:
        `_hwAddress` - the _hw address
      Returns:
        true, if successful

    - #### connectDeviceUsingSLIP

          public boolean connectDeviceUsingSLIP(java.lang.String _hwAddress)

      Connect device using slip.
      Parameters:
        `_hwAddress` - the _hw address
      Returns:
        true, if successful

    - #### connectDevice

          public boolean connectDevice(android.bluetooth.BluetoothSocket _socket)

      Connect device.
      Parameters:
        `_socket` - the _socket
      Returns:
        true, if successful

    - #### discoverDevices

          public void discoverDevices()

      Discover devices.

    - #### lookupAddressByName

          public java.lang.String lookupAddressByName(java.lang.String _name)

      Lookup address by name.
      Parameters:
        `_name` - the _name
      Returns:
        the string

    - #### writeToDeviceName

          public void writeToDeviceName(java.lang.String _name,
                                        byte[] data)

      Write to device name.
      Parameters:
        `_name` - the _name of the device/connection
        `data` - the data

    - #### write

          public void write(java.lang.String _deviceAddress,
                            byte[] data)

      Write data to a device through their hardware address
      Parameters:
        `_deviceAddress` - the _device hardware address
        `data` - the data

    - #### broadcast

          public void broadcast(byte[] data)

      Send data to all conencted devices.
      Parameters:
        `data` - the data

    - #### removeConnection

          protected void removeConnection(KBluetoothConnection c)

      Removes the connection.
      Parameters:
        `c` - the connection reference

    - #### makeDiscoverable

          public void makeDiscoverable()

      Make discoverable.

    - #### stop

          public void stop()

      Stop.

    - #### dispose

          public void dispose()