mirror of
https://github.com/clockworkpi/LauncherGoDev.git
synced 2025-12-13 00:18:52 +01:00
add GetDevices in bluetooth_page
This commit is contained in:
parent
cf9c0985e7
commit
22ab9c463f
@ -18,7 +18,7 @@ import (
|
|||||||
"github.com/cuu/gogame/font"
|
"github.com/cuu/gogame/font"
|
||||||
|
|
||||||
bleapi "github.com/muka/go-bluetooth/api"
|
bleapi "github.com/muka/go-bluetooth/api"
|
||||||
|
"github.com/muka/go-bluetooth/bluez"
|
||||||
"github.com/muka/go-bluetooth/bluez/profile"
|
"github.com/muka/go-bluetooth/bluez/profile"
|
||||||
|
|
||||||
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
|
"github.com/clockworkpi/LauncherGoDev/sysgo/UI"
|
||||||
@ -604,12 +604,43 @@ func (self *BluetoothPage) TryConnect() {
|
|||||||
self.Screen.FootBar.ResetNavText()
|
self.Screen.FootBar.ResetNavText()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GetDevices returns a list of bluetooth discovered Devices
|
||||||
|
func (self *BluetoothPage) GetDevices() ([]bleapi.Device, error) {
|
||||||
|
|
||||||
|
manager, err := bleapi.GetManager()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
manager.LoadObjects()
|
||||||
|
|
||||||
|
list, err := bleapi.GetDeviceList()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
objects := manager.GetObjects()
|
||||||
|
|
||||||
|
var devices = make([]bleapi.Device, 0)
|
||||||
|
for _, path := range list {
|
||||||
|
props := (*objects)[path][bluez.Device1Interface]
|
||||||
|
dev, err := bleapi.ParseDevice(path, props)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err)
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
devices = append(devices, *dev)
|
||||||
|
}
|
||||||
|
|
||||||
|
return devices, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (self *BluetoothPage) RefreshDevices() {
|
func (self *BluetoothPage) RefreshDevices() {
|
||||||
|
|
||||||
// sync the cached devices
|
// sync the cached devices
|
||||||
self.Devices = nil
|
self.Devices = nil
|
||||||
|
|
||||||
devices, err := bleapi.GetDevices()
|
devices, err := self.GetDevices()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user