Repository navigation
Expand file tree
/
Copy pathadapter.go
More file actions
57 lines (49 loc) · 2.05 KB
/
Copy pathadapter.go
File metadata and controls
57 lines (49 loc) · 2.05 KB
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
57
package bluetooth
// BLEAdapter is the shared interface that all platform-specific Adapter types must implement.
type BLEAdapter interface {
Connect(address Address, params ConnectionParams) (Device, error)
Enable() error
Reset() error
Scan(callback func(*Adapter, ScanResult)) (err error)
SetConnectHandler(c func(device Device, connected bool))
SetConnectionStateHandler(c func(device Device, state ConnectionState))
StopScan() error
}
// ConnectionState is passed to the connect handler when a device connects or
// disconnects.
type ConnectionState struct {
// Connected is true when the device connected, and false when it disconnected.
Connected bool
// Err is why the device disconnected. It is nil when Connected is true,
// when this side ended the connection, or when the platform gives no reason.
Err error
}
// SetConnectionStateHandler sets a handler function to be called whenever the adapter connects
// or disconnects. You must call this before you call adapter.Connect() for centrals
// or advertisement.Start() for peripherals in order for it to work.
func (a *Adapter) SetConnectionStateHandler(c func(device Device, state ConnectionState)) {
a.connectHandler = c
}
// SetConnectHandler sets a handler that only gets whether the device is connected.
//
// Deprecated: Use SetConnectionStateHandler, and run go fix to update callers.
//
//go:fix inline
func (a *Adapter) SetConnectHandler(c func(device Device, connected bool)) {
a.SetConnectionStateHandler(func(device Device, state ConnectionState) {
if c != nil {
c(device, state.Connected)
}
})
}
// DCSupplyStage selects a regulator stage. The two stages are in series,
// because REG0 supplies VDD from VDDH and VDD is the input to REG1.
// See nRF52840 Product Specification v1.11 section 5.4, Power management.
type DCSupplyStage uint8
const (
// DCSupplyMain is the REG1 stage, which supplies the core from VDD.
DCSupplyMain DCSupplyStage = iota
// DCSupplyHighVoltage is the REG0 stage, which needs VDDH power. The gain
// is small unless VDDH is much higher than VDD.
DCSupplyHighVoltage
)