> ## Documentation Index
> Fetch the complete documentation index at: https://darkgrade.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Cameras

> The Camera class provides a high-level interface for interacting with PTP-compatible cameras. It automatically selects the appropriate vendor-specific implementation (Sony, Nikon, Canon, or Generic) based on the connected device.

## Import

```typescript theme={null}
import { Camera } from '@darkgrade/slate'
```

## Constructor

```typescript theme={null}
constructor(options?: CameraOptions)
```

### Parameters

| Parameter | Type | Required | Description |
| - | - | - | - |
| **options** | `CameraOptions` | | Optional configuration for the camera instance. |
| **options.logger** | `Partial&lt;LoggerConfig&gt;` | | Optional logger configuration; console capture and terminal rendering are off by default for `Camera`. |
| **options.device** | `DeviceDescriptor` | | Device descriptor for the camera. If provided, the appropriate vendor-specific implementation will be selected automatically. |

## Methods

### getCapabilities, getExposureTime, setExposureTime, setControl

Use the [shared control model](https://darkgrade.com/docs/slate/getting_started/controls.md) for application
settings. It exposes only observed properties and re-checks current choices before
writes. Shutter speed and shutter angle share the `shutterSpeed` id (`exposureTime`
is a search alias); converting units requires the actual frame rate. Native angle
mode is preserved.

```typescript theme={null}
const { controls } = await camera.getCapabilities()
const exposure = await camera.getExposureTime()
await camera.setExposureTime('180°', { framesPerSecond: 25 })
await camera.setControl('colorTemperature', 5600)
```

These writes require writable, advertised values; the examples do not establish
support on every camera or in every shooting mode.

### connect

Connect to a camera device.

```typescript theme={null}
async connect(device?: DeviceDescriptor): Promise&lt;void&gt;
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **device** | `DeviceDescriptor` | | Optional device descriptor. If not provided, uses the device from the constructor options. |

### disconnect

Disconnect from the camera device.

```typescript theme={null}
async disconnect(): Promise&lt;void&gt;
```

### send

Send a PTP operation to the camera.

```typescript theme={null}
async send<Op extends OperationDefinition>(
  operation: Op,
  params: OperationParams<Op>,
  data?: Uint8Array,
  maxDataLength?: number
): Promise&lt;OperationResponse<Op>&gt;
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **operation** | `OperationDefinition` | ✓ | The operation definition to send. |
| **params** | `OperationParams&lt;Op&gt;` | ✓ | Parameters inferred from the concrete definition. |
| **data** | `Uint8Array` | | Optional data payload. |
| **maxDataLength** | `number` | | Optional maximum data length. |

### get

Get a camera property value.

```typescript theme={null}
async get<P extends PropertyDefinition>(property: P): Promise&lt;CodecType<P['codec']>&gt;
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **property** | `PropertyDefinition` | ✓ | The property definition to get. |

### set

Set a camera property value.

```typescript theme={null}
async set<P extends PropertyDefinition>(
  property: P,
  value: CodecType<P['codec']>
): Promise&lt;void&gt;
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **property** | `PropertyDefinition` | ✓ | The property definition to set. |
| **value** | `CodecType&lt;P['codec']&gt;` | ✓ | The concrete property's decoded value type. |

### getStandardPropertyStates

Read the standard PTP properties advertised by the connected body and current USB mode. Each state includes `code`, `codeHex`, `name`, decoded `value`, raw value, `writable`, form (`none`, `range`, or `enum`), and any advertised choices/range.

```typescript theme={null}
async getStandardPropertyStates(): Promise&lt;StandardPropertyState[]&gt;
```

Use this method before building controls for a generic or Olympus camera. Vendor recognition alone does not prove that a body publishes ISO, aperture, focus, or capture operations.

### setStandardProperty

Set one recognized standard property. Darkgrade re-reads the live property descriptors, rejects absent and read-only properties, and rejects enum values the body did not advertise.

```typescript theme={null}
async setStandardProperty(
  propertyNameOrCode: string | number,
  value: string | number
): Promise&lt;void&gt;
```

```typescript theme={null}
const properties = await camera.getStandardPropertyStates()
if (properties.find(property => property.name === 'ExposureIndex')?.writable) {
  await camera.setStandardProperty('ExposureIndex', 'ISO 400')
}
```

The physically tested Olympus E-PL5 MTP mode publishes battery level and writable date/time, but no exposure, focus, or remote-capture control. Newer Olympus bodies automatically expose any standard properties they actually advertise.

### on

Register an event handler.

```typescript theme={null}
on(
  event: EventDefinition,
  handler: function
): void
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **event** | `EventDefinition` | ✓ | The event definition to listen for. |
| **handler** | `function` | ✓ | The handler function to call when the event occurs. |

### off

Unregister an event handler.

```typescript theme={null}
off(
  event: EventDefinition,
  handler?: function
): void
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **event** | `EventDefinition` | ✓ | The event definition to stop listening for. |
| **handler** | `function` | | Optional handler function. If not provided, all handlers for the event are removed. |

### getAperture

Get the current aperture value.

```typescript theme={null}
async getAperture(): Promise&lt;string&gt;
```

### setAperture

Set the aperture value.

```typescript theme={null}
async setAperture(value: string): Promise&lt;void&gt;
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **value** | `string` | ✓ | The aperture value to set. |

### getShutterSpeed

Get the current shutter speed value.

```typescript theme={null}
async getShutterSpeed(): Promise&lt;string&gt;
```

### setShutterSpeed

Set the shutter speed value.

```typescript theme={null}
async setShutterSpeed(value: string): Promise&lt;void&gt;
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **value** | `string` | ✓ | The shutter speed value to set. |

### getIso

Get the current ISO value.

```typescript theme={null}
async getIso(): Promise&lt;string&gt;
```

### setIso

Set the ISO value.

```typescript theme={null}
async setIso(value: string): Promise&lt;void&gt;
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **value** | `string` | ✓ | The ISO value to set. |

### captureImage

Capture an image from the camera.

```typescript theme={null}
async captureImage(params?: object)
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **params** | `object` | | Capture parameters. |
| **params.includeInfo** | `boolean` | | Whether to include object info in the response. Defaults to `true`. |
| **params.includeData** | `boolean` | | Whether to include image data in the response. Defaults to `true`. |

### captureLiveView

Capture a live view frame from the camera.

```typescript theme={null}
async captureLiveView(params?: object)
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **params** | `object` | | Live view capture parameters. |
| **params.includeInfo** | `boolean` | | Whether to include object info in the response. Defaults to `true`. |
| **params.includeData** | `boolean` | | Whether to include image data in the response. Defaults to `true`. |

### startRecording

Start video recording.

```typescript theme={null}
async startRecording(): Promise&lt;void&gt;
```

### stopRecording

Stop video recording.

```typescript theme={null}
async stopRecording(): Promise&lt;void&gt;
```

### listObjects

List all objects stored on the camera.

```typescript theme={null}
async listObjects(): Promise&lt;object&gt;
```

### getObject

Retrieve an object from the camera.

```typescript theme={null}
async getObject(
  objectHandle: number,
  objectSize: number
): Promise&lt;Uint8Array&gt;
```

| Parameter | Type | Required | Description |
| - | - | - | - |
| **objectHandle** | `number` | ✓ | The handle of the object to retrieve. |
| **objectSize** | `number` | ✓ | The size of the object in bytes. |

## Exports

The module also exports the vendor-specific camera implementations:

* `CanonCamera`
* `GenericCamera`
* `NikonCamera`
* `SonyCamera`

These can be imported directly if you need vendor-specific functionality:

```typescript theme={null}
import { SonyCamera } from '@packages/slate/src/camera'
import { GenericCamera } from '@packages/slate/src/camera'
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.