Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion adapter.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package bluetooth

// SetConnectHandler sets a handler function to be called whenever the adaptor connects
// 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
Scan(callback func(*Adapter, ScanResult)) (err error)
SetConnectHandler(c func(device Device, connected bool))
StopScan() error
}

// SetConnectHandler 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) SetConnectHandler(c func(device Device, connected bool)) {
Expand Down
2 changes: 2 additions & 0 deletions adapter_cyw43439.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

const maxConnections = 1

var _ BLEAdapter = &Adapter{}
Comment thread
acouvreur marked this conversation as resolved.
Outdated

// Adapter represents a SPI connection to the HCI controller on an attached CYW4349 module.
type Adapter struct {
hciAdapter
Expand Down
2 changes: 2 additions & 0 deletions adapter_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"github.com/tinygo-org/cbgo"
)

var _ BLEAdapter = &Adapter{}
Comment thread
acouvreur marked this conversation as resolved.
Outdated

// Adapter is a connection to BLE devices.
type Adapter struct {
cmd *centralManagerDelegate
Expand Down
2 changes: 2 additions & 0 deletions adapter_hci_uart.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (

const maxConnections = 1

var _ BLEAdapter = &Adapter{}

// Adapter represents a "plain" UART connection to the HCI controller.
type Adapter struct {
hciAdapter
Expand Down
2 changes: 2 additions & 0 deletions adapter_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

const defaultAdapter = "hci0"

var _ BLEAdapter = &Adapter{}

type Adapter struct {
id string
scanCancelChan chan struct{}
Expand Down
2 changes: 2 additions & 0 deletions adapter_ninafw.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

const maxConnections = 1

var _ BLEAdapter = &Adapter{}

// Adapter represents the HCI connection to the NINA fw using the hardware UART.
type Adapter struct {
hciAdapter
Expand Down
21 changes: 21 additions & 0 deletions adapter_nrf51.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,24 @@ func makeMACAddress(addr C.ble_gap_addr_t) MACAddress {
isRandom: addr.addr_type != 0,
}
}

// Connect starts a connection attempt to the given peripheral device address.
//
// Not yet implemented on the nrf51.
func (a *Adapter) Connect(address Address, params ConnectionParams) (Device, error) {
return Device{}, errNotYetImplmented
}

// Scan starts a BLE scan. It is stopped by a call to StopScan.
//
// Not yet implemented on the nrf51.
func (a *Adapter) Scan(callback func(*Adapter, ScanResult)) (err error) {
return errNotYetImplmented
}

// StopScan stops any in-progress scan.
//
// Not yet implemented on the nrf51.
func (a *Adapter) StopScan() error {
return errNotYetImplmented
}
21 changes: 21 additions & 0 deletions adapter_s113v7.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,24 @@ package bluetooth
nrf_nvic_state_t nrf_nvic_state = {0};
*/
import "C"

// Connect starts a connection attempt to the given peripheral device address.
//
// Not yet implemented on the s113v7.
Comment thread
acouvreur marked this conversation as resolved.
Outdated
func (a *Adapter) Connect(address Address, params ConnectionParams) (Device, error) {
return Device{}, errNotYetImplmented
}

// Scan starts a BLE scan. It is stopped by a call to StopScan.
//
// Not yet implemented on the s113v7.
func (a *Adapter) Scan(callback func(*Adapter, ScanResult)) (err error) {
return errNotYetImplmented
}

// StopScan stops any in-progress scan.
//
// Not yet implemented on the s113v7.
func (a *Adapter) StopScan() error {
return errNotYetImplmented
}
2 changes: 2 additions & 0 deletions adapter_sd.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func init() {
secModeOpen.set_bitfield_lv(1)
}

var _ BLEAdapter = &Adapter{}

// Adapter is a dummy adapter: it represents the connection to the (only)
// SoftDevice on the chip.
type Adapter struct {
Expand Down
2 changes: 2 additions & 0 deletions adapter_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (
"github.com/saltosystems/winrt-go/windows/foundation"
)

var _ BLEAdapter = &Adapter{}

type Adapter struct {
watcher *advertisement.BluetoothLEAdvertisementWatcher

Expand Down
9 changes: 9 additions & 0 deletions gap_nrf51.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,30 @@ func (a *Adapter) SetRandomAddress(mac MAC) error {
}

// Disconnect from the BLE device.
//
// Not yet implemented on the nrf51.
func (d Device) Disconnect() error {
return errNotYetImplmented
}

// DiscoverServices starts a service discovery procedure.
//
// Not yet implemented on the nrf51.
func (d Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) {
return nil, errNotYetImplmented
}

// RequestConnectionParams requests a different connection latency and timeout
// of the given device connection.
//
// Not yet implemented on the nrf51.
func (d Device) RequestConnectionParams(params ConnectionParams) error {
return errNotYetImplmented
}

// Connected returns whether the device is currently connected.
//
// Not yet implemented on the nrf51.
func (d Device) Connected() (bool, error) {
return false, errNotYetImplmented
}
Expand Down
9 changes: 9 additions & 0 deletions gap_s113v7.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,30 @@ package bluetooth
import "C"

// Disconnect from the BLE device.
//
// Not yet implemented on the s113v7.
func (d Device) Disconnect() error {
return errNotYetImplmented
}

// DiscoverServices starts a service discovery procedure.
//
// Not yet implemented on the s113v7.
func (d Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) {
return nil, errNotYetImplmented
Comment thread
acouvreur marked this conversation as resolved.
Outdated
}

// RequestConnectionParams requests a different connection latency and timeout
// of the given device connection.
//
// Not yet implemented on the s113v7.
func (d Device) RequestConnectionParams(params ConnectionParams) error {
return errNotYetImplmented
}

// Connected returns whether the device is currently connected.
//
// Not yet implemented on the s113v7.
func (d Device) Connected() (bool, error) {
return false, errNotYetImplmented
}
Expand Down
Loading