104 lines
2.2 KiB
Go
104 lines
2.2 KiB
Go
package ble
|
|
|
|
import (
|
|
"gioui.org/app"
|
|
)
|
|
|
|
// Types required for ble.go
|
|
|
|
type bleState string
|
|
|
|
type bleHandle struct {
|
|
}
|
|
|
|
type Peripheral struct {
|
|
Name string
|
|
RSSI int
|
|
Identifier string
|
|
}
|
|
|
|
type Service string
|
|
type Characteristic string
|
|
|
|
// Internal global variables
|
|
|
|
// Functions required by API
|
|
|
|
//Init needs to be called before the BLE library can be used. On Android we
|
|
//need to set up the JVM by calling setJVM in jni_android.go.
|
|
func Init() {
|
|
h := app.PlatformHandle()
|
|
setJVM(h.JVM, h.Context)
|
|
}
|
|
|
|
//peripheralLookup returns a pointer to a BLE struct related to the given
|
|
//Peripheral.
|
|
func peripheralLookup(p Peripheral) *BLE {
|
|
return &BLE{}
|
|
}
|
|
|
|
//newPeripheral creates a new Peripheral struct
|
|
func newPeripheral() Peripheral {
|
|
return Peripheral{}
|
|
}
|
|
|
|
func (p Peripheral) IsIncomplete() bool {
|
|
return false
|
|
}
|
|
|
|
func (p Peripheral) Retain() {
|
|
}
|
|
|
|
//stringState returns a string version of the BLE state
|
|
func (b *BLE) stringState() string {
|
|
return ""
|
|
}
|
|
|
|
//readyToScan returns true if the hardware is ready to initiate a scan
|
|
func (b *BLE) readyToScan() bool {
|
|
return true
|
|
}
|
|
|
|
//scan puts the BLE hardware into scanning mode
|
|
func (b *BLE) scan() {
|
|
}
|
|
|
|
//stopScan stops a scan in progress
|
|
func (b *BLE) stopScan() {
|
|
}
|
|
|
|
//connectPeripheral attempts to connect to a Peripheral
|
|
func (b *BLE) connectPeripheral(x Peripheral) {
|
|
}
|
|
|
|
//cancelConnection cancels an in-progress connection attempt
|
|
func (b *BLE) cancelConnection(p Peripheral) {
|
|
}
|
|
|
|
//knownPeripheral returns a Peripheral that is known to the system without
|
|
//scanning
|
|
func (b *BLE) knownPeripheral(p Peripheral) (Peripheral, bool) {
|
|
return Peripheral{}, false
|
|
}
|
|
|
|
//DiscoverServices asks a Peripheral for its Services
|
|
func (x Peripheral) DiscoverServices() {
|
|
}
|
|
|
|
//DiscoverCharacteristics asks a Peripheral for the Characteristics related
|
|
//to a Service
|
|
func (p Peripheral) DiscoverCharacteristics(serv Service) {
|
|
}
|
|
|
|
//SetNotifyValue subscribes to a characteristic
|
|
func (p Peripheral) SetNotifyValue(c Characteristic) {
|
|
}
|
|
|
|
//NewBLE returns a pointer to a BLE struct after setting up the OS
|
|
//Bluetooth API.
|
|
func NewBLE() *BLE {
|
|
ps := Peripherals{items: make([]PeripheralListItem, 0)}
|
|
return &BLE{events: make(chan interface{}), peripherals: ps}
|
|
}
|
|
|