# `NanoKVMGo.Bluetooth`
[🔗](https://github.com/cocoa-xu/nano_kvm_go/blob/v0.4.0/lib/nano_kvm_go/bluetooth.ex#L1)

Bluetooth through BlueZ: the controller in the board's AIC8800 Wi-Fi
chip, its pairings and the devices it knows.

The supervisor starts the system's D-Bus and bluetoothd, then talks to
BlueZ over D-Bus. Pairings are kept on the data partition. Other devices
pair only while pairing is open (`open_pairing/1`), so the KVM does not
take a keyboard or a host that nobody let in.

    children = [NanoKVMGo.Bluetooth]

Events go to the processes that `subscribe/0`, as
`{NanoKVMGo.Bluetooth, event}`:

  * `{:adapter, info}` - `info/0` changed
  * `{:device, device}` - a device appeared or changed
  * `{:device_removed, address}` - a device was forgotten or went away

`NanoKVMGo.Bluetooth.HID` makes the board a Bluetooth LE keyboard, mouse
or other HID device.

## Options

  * `:name` - the name other devices see, the host name by default

# `address`

```elixir
@type address() :: String.t()
```

A Bluetooth address, `"AA:BB:CC:DD:EE:FF"`.

# `device`

```elixir
@type device() :: %{
  address: address(),
  name: String.t() | nil,
  icon: String.t() | nil,
  paired: boolean(),
  bonded: boolean(),
  trusted: boolean(),
  connected: boolean(),
  rssi: integer() | nil
}
```

# `info`

```elixir
@type info() :: %{
  name: String.t(),
  address: address(),
  powered: boolean(),
  discoverable: boolean(),
  pairable: boolean(),
  discovering: boolean(),
  pairing: boolean()
}
```

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `close_pairing`

```elixir
@spec close_pairing() :: :ok | {:error, term()}
```

# `connect`

```elixir
@spec connect(address()) :: :ok | {:error, term()}
```

# `devices`

```elixir
@spec devices() :: [device()]
```

The devices BlueZ knows: paired ones and those seen while scanning.

# `disconnect`

```elixir
@spec disconnect(address()) :: :ok | {:error, term()}
```

# `forget`

```elixir
@spec forget(address()) :: :ok | {:error, term()}
```

Forgets a device and its pairing.

# `info`

```elixir
@spec info() :: {:ok, info()} | {:error, :not_ready}
```

The controller: its name, address and state.

# `open_pairing`

```elixir
@spec open_pairing(pos_integer(), [{:discoverable, boolean()}]) ::
  :ok | {:error, term()}
```

Lets other devices pair with the board for `seconds`, 2 minutes by
default. They find it by an advertisement, such as
`NanoKVMGo.Bluetooth.HID`'s; with `discoverable: true` by the
controller's own as well.

# `pair`

```elixir
@spec pair(address()) :: :ok | {:error, term()}
```

Pairs with a device the board found, such as a keyboard.

# `scan`

```elixir
@spec scan(boolean()) :: :ok | {:error, term()}
```

Starts or stops looking for devices, which show up in `devices/0`.

# `start_link`

```elixir
@spec start_link(keyword()) :: Supervisor.on_start()
```

# `subscribe`

```elixir
@spec subscribe() :: :ok
```

---

*Consult [api-reference.md](api-reference.md) for complete listing*
