File: bluetooth.go

package info (click to toggle)
golang-github-jouyouyun-hardware 0.1.8-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 184 kB
  • sloc: ansic: 43; makefile: 4
file content (42 lines) | stat: -rw-r--r-- 865 bytes parent folder | download | duplicates (2)
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
}