1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
|
package bluetooth
import (
"github.com/jouyouyun/hardware/utils"
)
const (
blueSysfsDir = "/sys/class/bluetooth"
)
// Bluetooth store bluetooth info
type Bluetooth struct {
utils.CardInfo
}
// BluetoothList store bluetooth list
type BluetoothList []*Bluetooth
// GetBluetoothList return bluetooth device list
func GetBluetoothList() (BluetoothList, error) {
list, err := utils.ScanDir(blueSysfsDir, utils.FilterBluetoothName)
if err != nil {
return nil, err
}
var blueList BluetoothList
for _, name := range list {
blue, err := newBluetooth(blueSysfsDir, name)
if err != nil {
return nil, err
}
blueList = append(blueList, blue)
}
return blueList, nil
}
func newBluetooth(dir, name string) (*Bluetooth, error) {
card, err := utils.NewCardInfo(dir, name)
if err != nil {
return nil, err
}
return &Bluetooth{CardInfo: *card}, nil
}
|