bluez

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 4, 2019 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

bluez package handles interaction with dbus for Bluetooth discovery on Linux.

plan: open /org/bluez. call Introspect to get the full list of objects. (but also subscribe to change notifications) we don't care about GattService, just Adapter and Device how to identify unpaired devices? MAC? Name? (obviously .Paired==false)

(!) Set all controllers to Trusted for easy autoreconnect. The controller will only "trust" the last device to assign it a player number

Need a RemoveAllSyncRecords() function - if bluez is holding on to old pairing record, device needs to be deleted

errors from Connect(): already connected: "device busy" generic (not in range..): "i/o error (36)"

when a Device1 is found or changes:

  1. if adapter is blacklisted, skip
  2. if .Connected and .Trusted, everything is fine. emit an input device recheck with MAC
  3. if not .Paired: send an async Pair() method when that returns, if success or "already exists": send ConnectProfile(HID) method (? DEBUG THIS) wait for .Connected changes (algorithm restarts)
  4. if .Connected up but not .Trusted: emit an unpaired input device recheck with MAC -> once L+R is pressed, we set .Trusted to true

Index

Constants

View Source
const (
	BlueZBusName  = "org.bluez"
	BlueZRootPath = "/org/bluez"
	//Device1Interface the bluez interface for Device1
	Device1Interface = "org.bluez.Device1"
	//Adapter1Interface the bluez interface for Adapter1
	Adapter1Interface = "org.bluez.Adapter1"
	//GattService1Interface the bluez interface for GattService1
	GattService1Interface = "org.bluez.GattService1"
	//GattCharacteristic1Interface the bluez interface for GattCharacteristic1
	GattCharacteristic1Interface = "org.bluez.GattCharacteristic1"
	//GattDescriptor1Interface the bluez interface for GattDescriptor1
	GattDescriptor1Interface = "org.bluez.GattDescriptor1"

	//ObjectManagerInterface the dbus object manager interface
	ObjectManagerInterface = "org.freedesktop.DBus.ObjectManager"
	//InterfacesRemoved the DBus signal member for InterfacesRemoved
	InterfacesRemoved = "org.freedesktop.DBus.ObjectManager.InterfacesRemoved"
	//InterfacesAdded the DBus signal member for InterfacesAdded
	InterfacesAdded = "org.freedesktop.DBus.ObjectManager.InterfacesAdded"

	//PropertiesInterface the DBus properties interface
	PropertiesInterface = "org.freedesktop.DBus.Properties"
	//PropertiesChanged the DBus properties interface and member
	PropertiesChanged = "org.freedesktop.DBus.Properties.PropertiesChanged"
)
View Source
const (
	FlagCharacteristicBroadcast                 = "broadcast"
	FlagCharacteristicRead                      = "read"
	FlagCharacteristicWriteWithoutResponse      = "write-without-response"
	FlagCharacteristicWrite                     = "write"
	FlagCharacteristicNotify                    = "notify"
	FlagCharacteristicIndicate                  = "indicate"
	FlagCharacteristicAuthenticatedSignedWrites = "authenticated-signed-writes"
	FlagCharacteristicReliableWrite             = "reliable-write"
	FlagCharacteristicWritableAuxiliaries       = "writable-auxiliaries"
	FlagCharacteristicEncryptRead               = "encrypt-read"
	FlagCharacteristicEncryptWrite              = "encrypt-write"
	FlagCharacteristicEncryptAuthenticatedRead  = "encrypt-authenticated-read"
	FlagCharacteristicEncryptAuthenticatedWrite = "encrypt-authenticated-write"
	FlagCharacteristicSecureRead                = "secure-read"
	FlagCharacteristicSecureWrite               = "secure-write"
)

Defines how the characteristic value can be used. See Core spec "Table 3.5: Characteristic Properties bit field", and "Table 3.8: Characteristic Extended Properties bit field"

View Source
const (
	FlagDescriptorRead                      = "read"
	FlagDescriptorWrite                     = "write"
	FlagDescriptorEncryptRead               = "encrypt-read"
	FlagDescriptorEncryptWrite              = "encrypt-write"
	FlagDescriptorEncryptAuthenticatedRead  = "encrypt-authenticated-read"
	FlagDescriptorEncryptAuthenticatedWrite = "encrypt-authenticated-write"
	FlagDescriptorSecureRead                = "secure-read"
	FlagDescriptorSecureWrite               = "secure-write"
)

Descriptor specific flags

View Source
const (
	HIDProfileShort    = 0x1124
	HIDProfileUUIDStrU = "00001124-0000-1000-8000-00805F9B34FB"
	HIDProfileUUIDStrL = "00001124-0000-1000-8000-00805f9b34fb"
)

The Bluetooth profile of interest to us.

View Source
const Device1IntrospectDataString = `` /* 1601-byte string literal not displayed */

Device1IntrospectDataString interface definition

View Source
const GattCharacteristic1IntrospectDataString = `` /* 694-byte string literal not displayed */

GattCharacteristic1IntrospectDataString interface definition

View Source
const GattDescriptor1IntrospectDataString = `` /* 428-byte string literal not displayed */

GattDescriptor1IntrospectDataString interface definition

View Source
const GattService1IntrospectDataString = `` /* 309-byte string literal not displayed */

GattService1IntrospectDataString interface definition

View Source
const ObjectManagerIntrospectDataString = `` /* 410-byte string literal not displayed */

ObjectManagerIntrospectDataString introspect ObjectManager description

Variables

View Source
var GattService1IntrospectData = introspect.Interface{
	Name: "org.bluez.GattService1",
	Properties: []introspect.Property{
		{
			Name:   "UUID",
			Access: "read",
			Type:   "s",
		},
		{
			Name:   "Device",
			Access: "read",
			Type:   "o",
		},
		{
			Name:   "Primary",
			Access: "read",
			Type:   "b",
		},
		{
			Name:   "Characteristics",
			Access: "read",
			Type:   "ao",
		},
	},
}

GattService1IntrospectData interface definition

View Source
var ObjectManagerIntrospectData = introspect.Interface{
	Name: "org.freedesktop.DBus.ObjectManager",
	Methods: []introspect.Method{
		{
			Name: "GetManagedObjects",
			Args: []introspect.Arg{
				{
					Name:      "objects",
					Type:      "a{oa{sa{sv}}}",
					Direction: "out",
				},
			},
		},
	},
	Signals: []introspect.Signal{
		{
			Name: "InterfacesAdded",
			Args: []introspect.Arg{
				{
					Name: "object",
					Type: "o",
				},
				{
					Name: "interfaces",
					Type: "a{sa{sv}}",
				},
			},
		},
		{
			Name: "InterfacesRemoved",
			Args: []introspect.Arg{
				{
					Name: "object",
					Type: "o",
				},
				{
					Name: "interfaces",
					Type: "as",
				},
			},
		},
	},
}

ObjectManagerIntrospectData introspect ObjectManager description

Functions

This section is empty.

Types

type JoyconAPI

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

JoyconAPI presents a manageable surface area for the rest of the code to use. Eventually it will be turned into an interface for multi-OS functionality.

func New

func New() (*JoyconAPI, error)

func (*JoyconAPI) DeletePairingInfo

func (a *JoyconAPI) DeletePairingInfo()

Call this when the user holds the device sync button down.

func (*JoyconAPI) InitialScan

func (a *JoyconAPI) InitialScan()

func (*JoyconAPI) IsDiscoveryEnabled

func (a *JoyconAPI) IsDiscoveryEnabled() bool

Returns whether the manager object thinks Bluetooth discovery is enabled.

func (*JoyconAPI) NotifyChannel

func (a *JoyconAPI) NotifyChannel() <-chan jcpc.BluetoothDeviceNotification

func (*JoyconAPI) SavePairingInfo

func (a *JoyconAPI) SavePairingInfo(mac [6]byte)

marks the device as Trusted

func (*JoyconAPI) StartDiscovery

func (a *JoyconAPI) StartDiscovery()

Request discovery of Bluetooth devices (e.g., entered the "change controller config" screen).

func (*JoyconAPI) StopDiscovery

func (a *JoyconAPI) StopDiscovery()

Stop automatic discovery of Bluetooth devices.

type Properties

type Properties interface {
	ToMap() (map[string]interface{}, error)
}

Properties dbus serializable struct Use struct tags to control how the field is handled by Properties interface Example: field `dbus:writable,emit,myCallback` See Prop in github.com/godbus/dbus/prop for configuration details Options: - writable: set the property as writable (Set will updated it). Omit for read-only - emit|invalidates: emit PropertyChanged, invalidates emit without disclosing the value. Omit for read-only - callback: a callable function in the struct compatible with the signature of Prop.Callback. Omit for no callback

Jump to

Keyboard shortcuts

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