Current section
Files
Jump to
Current section
Files
src/rockbox@bluetooth.erl
-module(rockbox@bluetooth).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/rockbox/bluetooth.gleam").
-export([devices/1, scan/2, connect/2, disconnect/2]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(" Bluetooth device pairing and connection (Linux only).\n").
-file("src/rockbox/bluetooth.gleam", 18).
?DOC(" Known/paired devices.\n").
-spec devices(rockbox:client()) -> {ok, list(rockbox@types:bluetooth_device())} |
{error, rockbox@error:error()}.
devices(Client) ->
Decoder = begin
gleam@dynamic@decode:field(
<<"bluetoothDevices"/utf8>>,
gleam@dynamic@decode:list(rockbox@types:bluetooth_device_decoder()),
fun(Devices) -> gleam@dynamic@decode:success(Devices) end
)
end,
Q = <<"
fragment BluetoothDeviceFields on BluetoothDevice {
address name paired trusted connected rssi
}
"/utf8,
"
query BluetoothDevices { bluetoothDevices { ...BluetoothDeviceFields } }
"/utf8>>,
rockbox:'query'(Client, Q, gleam@json:object([]), Decoder).
-file("src/rockbox/bluetooth.gleam", 34).
?DOC(
" Trigger an active scan. `timeout_secs` of `option.None` uses the firmware\n"
" default.\n"
).
-spec scan(rockbox:client(), gleam@option:option(integer())) -> {ok,
list(rockbox@types:bluetooth_device())} |
{error, rockbox@error:error()}.
scan(Client, Timeout_secs) ->
Decoder = begin
gleam@dynamic@decode:field(
<<"bluetoothScan"/utf8>>,
gleam@dynamic@decode:list(rockbox@types:bluetooth_device_decoder()),
fun(Devices) -> gleam@dynamic@decode:success(Devices) end
)
end,
Vars = rockbox@internal@transport:variables(
[{<<"timeoutSecs"/utf8>>,
gleam@option:map(Timeout_secs, fun gleam@json:int/1)}]
),
Q = <<"
fragment BluetoothDeviceFields on BluetoothDevice {
address name paired trusted connected rssi
}
"/utf8,
"
mutation BluetoothScan($timeoutSecs: Int) {
bluetoothScan(timeoutSecs: $timeoutSecs) { ...BluetoothDeviceFields }
}
"/utf8>>,
rockbox:'query'(Client, Q, Vars, Decoder).
-file("src/rockbox/bluetooth.gleam", 57).
-spec connect(rockbox:client(), binary()) -> {ok, nil} |
{error, rockbox@error:error()}.
connect(Client, Address) ->
rockbox:execute(
Client,
<<"mutation BluetoothConnect($address: String!) { bluetoothConnect(address: $address) }"/utf8>>,
gleam@json:object([{<<"address"/utf8>>, gleam@json:string(Address)}])
).
-file("src/rockbox/bluetooth.gleam", 65).
-spec disconnect(rockbox:client(), binary()) -> {ok, nil} |
{error, rockbox@error:error()}.
disconnect(Client, Address) ->
rockbox:execute(
Client,
<<"mutation BluetoothDisconnect($address: String!) { bluetoothDisconnect(address: $address) }"/utf8>>,
gleam@json:object([{<<"address"/utf8>>, gleam@json:string(Address)}])
).