ble

package
v0.0.0-...-7cec17d Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 12, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewGoBleClient

func NewGoBleClient(init GoBleInitFunc) (*bleClient, error)

Types

type Advertisement struct {
	Addr     string
	Name     string
	Services []string
}

type AdvertisementHandler

type AdvertisementHandler func(adv Advertisement)

type Characteristic

type Characteristic interface {
	Uuid() string

	WriteCharacteristic(data []byte, resp WriteCharacteristicType) error
	Subscribe(subType SubscriptionType, f func([]byte)) error
	Unsubscribe(subType SubscriptionType) error
}

type Client

type Client interface {
	ConnectName(name string, timeout time.Duration) (Peripheral, error)
	ConnectAddress(address string, timeout time.Duration) (Peripheral, error)
	Scan(duration time.Duration, handler AdvertisementHandler) error
}

func NewClient

func NewClient() (b Client, err error)

type GoBleInitFunc

type GoBleInitFunc func() (ble.Device, error)

type Peripheral

type Peripheral interface {
	Addr() string

	Disconnect() error

	FindService(uuid string) Service
	FindCharacteristic(uuid string) Characteristic

	WriteCharacteristic(uuid string, data []byte, resp WriteCharacteristicType) error
	Subscribe(uuid string, subType SubscriptionType, callback func([]byte)) error
	Unsubscribe(uuid string, subType SubscriptionType) error
}

type Service

type Service interface {
	Uuid() string
	FindCharacteristic(uuid string) Characteristic
}

type SubscriptionType

type SubscriptionType byte
const (
	SubscriptionTypeNotification SubscriptionType = 1
	SubscriptionTypeIndication   SubscriptionType = 2
)

type WriteCharacteristicType

type WriteCharacteristicType byte
const (
	NoResponse   WriteCharacteristicType = 1
	WithResponse WriteCharacteristicType = 2
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL