NanoKVMGo.Bluetooth (nano_kvm_go v0.4.0)

Copy Markdown View Source

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

Summary

Types

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

Functions

Returns a specification to start this module under a supervisor.

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

Forgets a device and its pairing.

The controller: its name, address and state.

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.

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

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

Types

address()

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

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

device()

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

info()

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

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

close_pairing()

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

connect(address)

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

devices()

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

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

disconnect(address)

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

forget(address)

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

Forgets a device and its pairing.

info()

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

The controller: its name, address and state.

open_pairing(seconds \\ 120, opts \\ [])

@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(address)

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

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

scan(on?)

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

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

start_link(opts \\ [])

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

subscribe()

@spec subscribe() :: :ok