# Driver

Canonical page: https://docs.ovok.com/flutter-sdk/reference/ovok_flutter/driver

{/* Generated by scripts/generate_reference.dart; do not edit. */}

## BluetoothDeviceDefinition [#bluetoothdevicedefinition]

```dart
class BluetoothDeviceDefinition
```

A custom device definition with an advertisement matcher and protocol.

### Constructors [#constructors]

#### BluetoothDeviceDefinition.new [#bluetoothdevicedefinitionnew]

```dart
BluetoothDeviceDefinition({
  required String key,
  required bool Function(BluetoothAdvertisement) matches,
  required BluetoothDeviceProtocol protocol,
})
```

Creates a custom device definition.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `key` | `String` | required named |  |
| `matches` | `bool Function(BluetoothAdvertisement)` | required named |  |
| `protocol` | `BluetoothDeviceProtocol` | required named |  |

### Properties [#properties]

#### BluetoothDeviceDefinition.key [#bluetoothdevicedefinitionkey]

```dart
final String key
```

A unique device key reported with readings.

#### BluetoothDeviceDefinition.matches [#bluetoothdevicedefinitionmatches]

```dart
final bool Function(BluetoothAdvertisement) matches
```

Whether an advertisement belongs to this device.

#### BluetoothDeviceDefinition.protocol [#bluetoothdevicedefinitionprotocol]

```dart
final BluetoothDeviceProtocol protocol
```

Reads this device's bytes and yields decoded measurements.


## BluetoothDeviceErrorEvent [#bluetoothdeviceerrorevent]

```dart
final class BluetoothDeviceErrorEvent extends BluetoothDeviceEvent
```

A device or protocol error that does not end the connection.

### Constructors [#constructors-1]

#### BluetoothDeviceErrorEvent.new [#bluetoothdeviceerroreventnew]

```dart
BluetoothDeviceErrorEvent(BluetoothError error)
```

Creates a recoverable device error event.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `error` | `BluetoothError` | positional |  |

### Properties [#properties-1]

#### BluetoothDeviceErrorEvent.error [#bluetoothdeviceerroreventerror]

```dart
final BluetoothError error
```

The reported device failure.


## BluetoothDeviceEvent [#bluetoothdeviceevent]

```dart
sealed class BluetoothDeviceEvent
```

An event a Bluetooth driver reports while it runs.

### Constructors [#constructors-2]

#### BluetoothDeviceEvent.new [#bluetoothdeviceeventnew]

```dart
BluetoothDeviceEvent()
```

Creates a driver event.


## BluetoothDeviceMatch [#bluetoothdevicematch]

```dart
class BluetoothDeviceMatch
```

The result of matching an advertisement to a device driver.

### Constructors [#constructors-3]

#### BluetoothDeviceMatch.new [#bluetoothdevicematchnew]

```dart
BluetoothDeviceMatch({required String key, required BluetoothDriver driver})
```

Creates a match for a device [`key`](#bluetoothdevicematchkey) and [`driver`](#bluetoothdevicematchdriver).

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `key` | `String` | required named |  |
| `driver` | `BluetoothDriver` | required named |  |

### Properties [#properties-2]

#### BluetoothDeviceMatch.key [#bluetoothdevicematchkey]

```dart
final String key
```

The device key reported with readings.

#### BluetoothDeviceMatch.driver [#bluetoothdevicematchdriver]

```dart
final BluetoothDriver driver
```

The driver that reads this peripheral.


## BluetoothDeviceProtocol [#bluetoothdeviceprotocol]

```dart
typedef BluetoothDeviceProtocol = Stream<Map<String, dynamic>> Function(BluetoothLink)
```

A device protocol reads measurements from an open GATT link.


## BluetoothDeviceSupport [#bluetoothdevicesupport]

```dart
abstract interface class BluetoothDeviceSupport
```

Support that recognizes peripherals from their advertisements.

### Methods [#methods]

#### BluetoothDeviceSupport.match [#bluetoothdevicesupportmatch]

```dart
BluetoothDeviceMatch? match(BluetoothAdvertisement advertisement)
```

Returns this support's match, or null when it does not recognize the ad.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `advertisement` | `BluetoothAdvertisement` | positional |  |

Returns `BluetoothDeviceMatch?`.


## BluetoothDriver [#bluetoothdriver]

```dart
typedef BluetoothDriver = Stream<BluetoothDeviceEvent> Function(BluetoothPeripheral, BluetoothCancellation)
```

A driver connects to one peripheral and reports events until it disconnects.


## BluetoothDriverStatus [#bluetoothdriverstatus]

```dart
enum BluetoothDriverStatus
```

A status that a device driver can report.

### Values [#values]

#### BluetoothDriverStatus.connected [#bluetoothdriverstatusconnected]

```dart
static const BluetoothDriverStatus connected
```

The device link is open.

#### BluetoothDriverStatus.measuring [#bluetoothdriverstatusmeasuring]

```dart
static const BluetoothDriverStatus measuring
```

The device is sending measurements.

#### BluetoothDriverStatus.disconnected [#bluetoothdriverstatusdisconnected]

```dart
static const BluetoothDriverStatus disconnected
```

The device link has closed.


## BluetoothReadingEvent [#bluetoothreadingevent]

```dart
final class BluetoothReadingEvent extends BluetoothDeviceEvent
```

A reading reported by a device driver.

### Constructors [#constructors-4]

#### BluetoothReadingEvent.new [#bluetoothreadingeventnew]

```dart
BluetoothReadingEvent({required String? id, required JsonMap reading})
```

Creates a reading event.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `id` | `String?` | required named |  |
| `reading` | `JsonMap` | required named |  |

### Properties [#properties-3]

#### BluetoothReadingEvent.id [#bluetoothreadingeventid]

```dart
final String? id
```

A stable device reading ID, or null if it cannot be recognized on resend.

#### BluetoothReadingEvent.reading [#bluetoothreadingeventreading]

```dart
final JsonMap reading
```

The decoded measurement.


## BluetoothStatusEvent [#bluetoothstatusevent]

```dart
final class BluetoothStatusEvent extends BluetoothDeviceEvent
```

A device connection state event.

### Constructors [#constructors-5]

#### BluetoothStatusEvent.new [#bluetoothstatuseventnew]

```dart
BluetoothStatusEvent(BluetoothDriverStatus status)
```

Creates a connection status event.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `status` | `BluetoothDriverStatus` | positional |  |

### Properties [#properties-4]

#### BluetoothStatusEvent.status [#bluetoothstatuseventstatus]

```dart
final BluetoothDriverStatus status
```

The new connection state.


## defineDevice [#definedevice]

```dart
BluetoothDeviceSupport defineDevice(BluetoothDeviceDefinition device)
```

Builds a [`BluetoothDeviceSupport`](#bluetoothdevicesupport) for a custom GATT `protocol`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `device` | `BluetoothDeviceDefinition` | positional |  |


## gattDriver [#gattdriver]

```dart
BluetoothDriver gattDriver(String key, BluetoothDeviceProtocol protocol)
```

Connects to a peripheral and runs a device protocol over its GATT link.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `key` | `String` | positional |  |
| `protocol` | `BluetoothDeviceProtocol` | positional |  |
