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:
- if adapter is blacklisted, skip
- if .Connected and .Trusted, everything is fine. emit an input device recheck with MAC
- 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)
- 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
- Variables
- type JoyconAPI
- func (a *JoyconAPI) DeletePairingInfo()
- func (a *JoyconAPI) InitialScan()
- func (a *JoyconAPI) IsDiscoveryEnabled() bool
- func (a *JoyconAPI) NotifyChannel() <-chan jcpc.BluetoothDeviceNotification
- func (a *JoyconAPI) SavePairingInfo(mac [6]byte)
- func (a *JoyconAPI) StartDiscovery()
- func (a *JoyconAPI) StopDiscovery()
- type Properties
Constants ¶
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" )
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"
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
const ( HIDProfileShort = 0x1124 HIDProfileUUIDStrU = "00001124-0000-1000-8000-00805F9B34FB" HIDProfileUUIDStrL = "00001124-0000-1000-8000-00805f9b34fb" )
The Bluetooth profile of interest to us.
const Device1IntrospectDataString = `` /* 1601-byte string literal not displayed */
Device1IntrospectDataString interface definition
const GattCharacteristic1IntrospectDataString = `` /* 694-byte string literal not displayed */
GattCharacteristic1IntrospectDataString interface definition
const GattDescriptor1IntrospectDataString = `` /* 428-byte string literal not displayed */
GattDescriptor1IntrospectDataString interface definition
const GattService1IntrospectDataString = `` /* 309-byte string literal not displayed */
GattService1IntrospectDataString interface definition
const ObjectManagerIntrospectDataString = `` /* 410-byte string literal not displayed */
ObjectManagerIntrospectDataString introspect ObjectManager description
Variables ¶
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
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 (*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 ¶
Returns whether the manager object thinks Bluetooth discovery is enabled.
func (*JoyconAPI) NotifyChannel ¶
func (a *JoyconAPI) NotifyChannel() <-chan jcpc.BluetoothDeviceNotification
func (*JoyconAPI) SavePairingInfo ¶
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 ¶
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