-
Notifications
You must be signed in to change notification settings - Fork 14
/
adapter.go
56 lines (47 loc) · 1.52 KB
/
adapter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package ble
import (
"log"
"time"
)
const (
adapterInterface = "org.bluez.Adapter1"
)
// The Adapter type corresponds to the org.bluez.Adapter1 interface.
// See bluez/doc/adapter-api.txt
//
// StartDiscovery starts discovery on the adapter.
//
// StopDiscovery stops discovery on the adapter.
//
// RemoveDevice removes the specified device and its pairing information.
//
// SetDiscoveryFilter sets the discovery filter to require
// LE transport and the given UUIDs.
//
// Discover performs discovery for a device with the given UUIDs,
// for at most the specified timeout, or indefinitely if timeout is 0.
// See also the Discover method of the ObjectCache type.
type Adapter interface {
BaseObject
StartDiscovery() error
StopDiscovery() error
RemoveDevice(Device) error
SetDiscoveryFilter(uuids ...string) error
Discover(timeout time.Duration, uuids ...string) error
}
// GetAdapter finds an Adapter in the object cache and returns it.
func (conn *Connection) GetAdapter() (Adapter, error) {
return conn.findObject(adapterInterface, func(_ *blob) bool { return true })
}
func (adapter *blob) StartDiscovery() error {
log.Printf("%s: starting discovery", adapter.Name())
return adapter.call("StartDiscovery")
}
func (adapter *blob) StopDiscovery() error {
log.Printf("%s: stopping discovery", adapter.Name())
return adapter.call("StopDiscovery")
}
func (adapter *blob) RemoveDevice(device Device) error {
log.Printf("%s: removing device %s", adapter.Name(), device.Name())
return adapter.call("RemoveDevice", device.Path())
}