ble

package module
v0.0.0-...-90ab682 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2020 License: MIT Imports: 5 Imported by: 0

README

BLE

A modern, cross-platform Go library for Bluetooth Low Energy

This package is a working but incomplete interface for access to Bluetooth Low Energy devices. It is intended to support multiple operating systems with a uniform API. Currently, MacOS and Android are supported. Android support requires the use of Gio.

The API is asyncrhonous and event driven. To access Bluetooth hardware, first create a BLE variable with NewBLE(). On Android, you must also call Enable with a pointer to your Gio Window.

import (
	...
	"git.wow.st/gmp/ble"
	"gioui.org/app"
)

func runloop() {
	b := ble.NewBle()
	w := app.NewWindow()
	b.Enable(w)
	...

Once enabled, you can call the primary API functions, Scan, StopScan, Connect, and CancelConnection. You can also query the state of the Bluetooth hardware by calling State.

Calling Events on your BLE object returns a channel on which API events are delivered. These events notify your program when the state of the BLE hardware changes (e.g. powered on or off), peripherals are connected, services or characteristics are discovered, or values for characteristics are updated.

Using Gio, your main event loop will look something like this:

	for {
		select {
		case e := <-b.Events():
			switch e := e.(type) {
				// Handle BLE Events
			}
		}
		case e := <-w.Events():
			switch e := e.(type) {
				// Handle Gio events
			}
		}
	}

An example heart rate monitor app can be found at git.wow.st/gmp/hrm.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CancelConnection

func CancelConnection(p Peripheral)

func Disconnect

func Disconnect(p Peripheral)

Types

type BLE

type BLE struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*BLE) Connect

func (b *BLE) Connect(p Peripheral) bool

func (*BLE) Events

func (b *BLE) Events() chan interface{}

func (*BLE) Scan

func (b *BLE) Scan()

func (*BLE) State

func (b *BLE) State() string

func (*BLE) StopScan

func (b *BLE) StopScan()

type ConnectEvent

type ConnectEvent struct {
	Peripheral Peripheral
}

type ConnectTimeoutEvent

type ConnectTimeoutEvent struct {
	Peripheral Peripheral
}

type ConnectionListItem

type ConnectionListItem struct {
	// contains filtered or unexported fields
}

type Connections

type Connections struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Connections) Add

func (cs *Connections) Add(x ConnectionListItem) bool

func (*Connections) UpdateState

func (c *Connections) UpdateState(p Peripheral, s string)

type DisconnectEvent

type DisconnectEvent struct {
	Peripheral Peripheral
}

type DiscoverCharacteristicEvent

type DiscoverCharacteristicEvent struct {
	Peripheral     Peripheral
	Gatt           gatt.Characteristic
	Service        Service
	Characteristic Characteristic
}

FIXME: create a Characteristic type that is platform dependent to make the event platform independent

type DiscoverPeripheralEvent

type DiscoverPeripheralEvent struct {
	Peripheral Peripheral
}

type DiscoverServiceEvent

type DiscoverServiceEvent struct {
	Peripheral Peripheral
	Gatt       gatt.Service
	Service    Service
}

FIXME: create a Service type that is platform dependent to make the event platform independent

type PeripheralListItem

type PeripheralListItem struct {
	// contains filtered or unexported fields
}

type Peripherals

type Peripherals struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func (*Peripherals) Add

func (ps *Peripherals) Add(x Peripheral) bool

type UpdageValueEvent

type UpdageValueEvent struct {
	Peripheral     Peripheral
	Characteristic gatt.Characteristic
}

type UpdateStateEvent

type UpdateStateEvent struct {
	State string
}

type UpdateValueEvent

type UpdateValueEvent struct {
	Peripheral     Peripheral
	Characteristic Characteristic
	Data           []byte
}

FIXME: create a Characteristic type that is platform dependent to make the event platform independent

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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