# QR Code Scanner

# QR Code Scanner

This module manages the entire process of capturing, decoding and getting the device parameters from a QR code.

## Summary

It also saves and loads the device parameters to and from the external storage.

| ### Functions ||
|---|---|
| `https://developers.google.com/cardboard/reference/c/group/qrcode-scanner#group__qrcode-scanner_1gaab54d0d46eb5857287e774f96c9788d8(const uint8_t *encoded_device_params)` | `void` Releases memory used by the provided encoded_device_params array. |
| `https://developers.google.com/cardboard/reference/c/group/qrcode-scanner#group__qrcode-scanner_1gaff73f4881bb9404f0b7c0c33b4045025(uint8_t **encoded_device_params, int *size)` | `void` Gets Cardboard V1 device parameters. |
| `https://developers.google.com/cardboard/reference/c/group/qrcode-scanner#group__qrcode-scanner_1gaf0a71fb74c6b9b3857beb383ff8e85da()` | `int` Gets the count of successful device parameters read and save operations. |
| `https://developers.google.com/cardboard/reference/c/group/qrcode-scanner#group__qrcode-scanner_1ga50e736dab99e572c773d90aa91321c3b(uint8_t **encoded_device_params, int *size)` | `void` Gets currently saved devices parameters. |
| `https://developers.google.com/cardboard/reference/c/group/qrcode-scanner#group__qrcode-scanner_1ga152b744b27fe7eedacc53c45eb81e58e(const uint8_t *uri, int size)` | `void` Saves the encoded device parameters provided by an URI. |
| `https://developers.google.com/cardboard/reference/c/group/qrcode-scanner#group__qrcode-scanner_1ga3bf36a2d41651e22344dd95030eea324()` | `void` Scans a QR code and saves the encoded device parameters. |

## Functions

### CardboardQrCode_destroy

```
void CardboardQrCode_destroy(
  const uint8_t *encoded_device_params
)
```
Releases memory used by the provided encoded_device_params array.

`encoded_device_params` Must not be null. When it is unmet, a call to this function results in a no-op.

| Details ||
|---|---|
| Parameters | |---|---| | `encoded_device_params` | The device parameters serialized using cardboard_device.proto. | |

### CardboardQrCode_getCardboardV1DeviceParams

```
void CardboardQrCode_getCardboardV1DeviceParams(
  uint8_t **encoded_device_params,
  int *size
)
```
Gets Cardboard V1 device parameters.

This function does not use external storage, and stores into `encoded_device_params` the value of a pointer storing proto buffer. Users of this API should not free memory.

`encoded_device_params` Must not be null. `size` Must not be null. When it is unmet, a call to this function results in a no-op and default values are returned (empty values). Does not require a prior call to `https://developers.google.com/cardboard/reference/c/group/initialization#group__initialization_1gaf3bcb627b96ad8045ef58e5ab6d6b04f` in Android devices.

| Details ||
|---|---|
| Parameters | |---|---| | `encoded_device_params` | Reference to the device parameters. | | `size` | Size in bytes of `encoded_device_params`. | |

### CardboardQrCode_getDeviceParamsChangedCount

```
int CardboardQrCode_getDeviceParamsChangedCount()
```
Gets the count of successful device parameters read and save operations.

<br />

| Details ||
|---|---|
| **Returns** | The count of successful device parameters read and save operations. |

### CardboardQrCode_getSavedDeviceParams

```
void CardboardQrCode_getSavedDeviceParams(
  uint8_t **encoded_device_params,
  int *size
)
```
Gets currently saved devices parameters.

This function allocates memory for the parameters, so it must be released using `https://developers.google.com/cardboard/reference/c/group/qrcode-scanner#group__qrcode-scanner_1gaab54d0d46eb5857287e774f96c9788d8`.

`encoded_device_params` Must not be null. `size` Must not be null. When it is unmet, a call to this function results in a no-op and default values are returned (empty values).

| Details ||
|---|---|
| Parameters | |---|---| | `encoded_device_params` | Reference to the device parameters serialized using cardboard_device.proto. | | `size` | Size in bytes of encoded_device_params. | |

### CardboardQrCode_saveDeviceParams

```
void CardboardQrCode_saveDeviceParams(
  const uint8_t *uri,
  int size
)
```
Saves the encoded device parameters provided by an URI.

This function obtains the encoded device parameters by parsing a URI string and then saves them.

Expected URI format for:

- Cardboard Viewer v1: <https://g.co/cardboard>
- Cardboard Viewer v2: <https://google.com/cardboard/cfd?p=deviceParams> (for example, <https://google.com/cardboard/cfg?p=CgZHb29nbGUSEkNhcmRib2FyZCBJL08gMjAxNR0rGBU9JQHegj0qEAAASEIAAEhCAABIQgAASEJYADUpXA89OggeZnc-Ej6aPlAAYAM>). Redirection is also supported up to a maximum of 5 possible redirects before reaching the proper pattern. This function only supports HTTPS connections. In case a URI containing an HTTP scheme is provided, it will be replaced by an HTTPS one. Upon termination, it will increment a counter that can be queried via **See also:** [CardboardQrCode_getDeviceParamsChangedCount()](https://developers.google.com/cardboard/reference/c/group/qrcode-scanner#group__qrcode-scanner_1gaf0a71fb74c6b9b3857beb383ff8e85da) when new device parameters were successfully saved.`uri` Must not be null. `size` Must be higher than 0. Parameters

  |---|---|
  | `uri` | UTF-8 URI string. See above for supported formats. |
  | `size` | Size in bytes of `uri` |

<br />

### CardboardQrCode_scanQrCodeAndSaveDeviceParams

```
void CardboardQrCode_scanQrCodeAndSaveDeviceParams()
```
Scans a QR code and saves the encoded device parameters.

Upon termination, it will increment a counter that can be queried via `https://developers.google.com/cardboard/reference/c/group/qrcode-scanner#group__qrcode-scanner_1gaf0a71fb74c6b9b3857beb383ff8e85da` when new device parameters where successfully saved.