Commit 76d64512 authored by Tzu-Jung Lee's avatar Tzu-Jung Lee
Browse files

option: bring the option support back

parent b5f4ebbd
......@@ -78,6 +78,15 @@ func NewDevice(role int) (*Device, error) {
return d, nil
}
// Option sets the options specified.
func (d *Device) Option(opts ...Option) error {
var err error
for _, opt := range opts {
err = opt(d)
}
return err
}
// Init ...
func (d *Device) Init(f func(Device, State)) error {
rsp := d.sendReq(1, xpc.Dict{
......
package darwin
// An Option is a configuration function, which configures the device.
type Option func(*Device) error
// OptPeripheralRole configures the device to perform Peripheral tasks.
func OptPeripheralRole() Option {
return func(d *Device) error {
d.role = 0
return nil
}
}
// OptCentralRole configures the device to perform Central tasks.
func OptCentralRole() Option {
return func(d *Device) error {
d.role = 1
return nil
}
}
......@@ -78,6 +78,15 @@ type HCI struct {
done chan bool
}
// Option sets the options specified.
func (h *HCI) Option(opts ...Option) error {
var err error
for _, opt := range opts {
err = opt(h)
}
return err
}
// Init ...
func (h *HCI) Init(id int) error {
skt, err := skt.NewSocket(id)
......
package hci
import (
"github.com/currantlabs/ble/linux/hci/cmd"
)
// An Option is a configuration function, which configures the device.
type Option func(*HCI) error
// OptScanParams sets scanning parameters.
func OptScanParams(p ScanParams) Option {
return func(h *HCI) error {
h.states.scanParams = cmd.LESetScanParameters(p)
return nil
}
}
// OptAdvParams sets advertising parameters.
func OptAdvParams(p AdvParams) Option {
return func(h *HCI) error {
h.states.advParams = cmd.LESetAdvertisingParameters(p)
return nil
}
}
// OptConnParams ...
func OptConnParams(p ConnParams) Option {
return func(h *HCI) error {
h.states.connParams = cmd.LECreateConnection(p)
return nil
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment