This commit is contained in:
cuu 2018-12-17 14:26:57 +08:00
parent fa855f9ca8
commit 598a93d684
2 changed files with 63 additions and 6 deletions

View File

@ -10,7 +10,8 @@ import (
bleapi "github.com/muka/go-bluetooth/api"
"github.com/muka/go-bluetooth/bluez/profile"
"github.com/cuu/LauncherGoDev/sysgo/UI"
)
func showDeviceInfo(dev *bleapi.Device) {
@ -534,7 +535,7 @@ func (self *BluetoothPage) GenNetworkList() {
start_y := 0
for i v := range self.Devices {
for i v := range self.Devices { // v == bleapi.Device
props, err := v.GetProperties()
if err != nil {
@ -551,7 +552,8 @@ func (self *BluetoothPage) GenNetworkList() {
ni.FontObj = self.ListFontObj
ni.Path = v.Path
ni.Props = props
ni.Parent = self
ni.Device = &v
if props.Name != "" {
ni.Init(props.Name)
}else {

View File

@ -2,8 +2,9 @@ package Bluetooth
import (
bleapi "github.com/muka/go-bluetooth/api"
"github.com/muka/go-bluetooth/bluez/profile"
"github.com/cuu/LauncherGoDev/sysgo/UI"
)
var NetItemDefaultHeight = 30
@ -67,9 +68,10 @@ type NetItem struct {
FontObj *ttf.Font
RSSI int // 0
MacAddr string //
Parent *BluetoothPage
Path string ///org/bluez/hci0/dev_34_88_5D_97_FF_26
Props *profile.Device1Properties
Device *bleapi.Device
}
@ -92,8 +94,61 @@ func (self *NetItem) SetActive(act bool) {
}
func (self *NetItem) Init(path string ) {
func (self *NetItem) Init( _label string) {
self.MacAddr = self.Props.Address
self.SetActive(self.Props.Connected)
name_label := UI.NewLabel()
name_label.PosX = 12
name_label.CanvasHWND = self.Parent.CanvasHWND
mac_addr := self.MacAddr
if len(self.Props.Name) > 3 {
mac_addr = self.Props.Name
}
self.RSSI = int(self.Props.RSSI)
name_label.Init(mac_addr,self.FontObj,nil)
self.Labels["mac_addr"] = name_label
done_icon := NewNetItemIcon()
done_icon.ImgSurf = UI.MyIconPool.GetImgSurf("done")
done_icon.CanvasHWND = self.Parent.GetCanvasHWND()
done_icon.Parent = self
self.Icons["done"] = done_icon
}
func (self *NetItem) Connect() {
if self.Device != nil {
self.Device.Connect()
}
}
func (self *NetItem) Draw() {
for k,v := range self.Labels {
x,y := v.Coord()
_,h := v.Size()
self.Labels[k].NewCoord(x, self.PosY+(self.Height - h)/2)
self.Labels[k].Draw()
}
if self.IsActive {
self.Icons["done"].NewCoord(UI.Width-22, self.PosY)
self.Icons["done"].Draw()
}
draw.Line(self.Parent.CanvasHWND,&color.Color{169,169,169,255},
self.PosX,self.PosY+self.Height-1,
self.PosX+self.Width,self.PosY+self.Height-1,
1)
}