Revert "Add bluetooth device battery module"
This reverts commit 4749cf4e38
.
This commit is contained in:
parent
4749cf4e38
commit
ef7e72b1e4
3 changed files with 6 additions and 96 deletions
|
@ -51,7 +51,6 @@ func run() error {
|
|||
providers.NewMemory(7, 5),
|
||||
providers.NewCPU(20, 50),
|
||||
providers.NewDisk("/", 30, 10),
|
||||
providers.NewBluetoothBattery(80, 30, 20),
|
||||
providers.NewBattery("BAT0", 80, 30, 20),
|
||||
providers.NewWiFi("wlp0s20f3", 75),
|
||||
providers.NewIPAddress("wlp0s20f3"),
|
||||
|
|
|
@ -131,12 +131,12 @@ func (b *I3bar) tick(override bool) error {
|
|||
TextColor: defaultColorSet.Bad,
|
||||
}
|
||||
}
|
||||
// if block == nil {
|
||||
// block = &Block{
|
||||
// FullText: "MISSING",
|
||||
// TextColor: defaultColorSet.Warning,
|
||||
// }
|
||||
// }
|
||||
if block == nil {
|
||||
block = &Block{
|
||||
FullText: "MISSING",
|
||||
TextColor: defaultColorSet.Warning,
|
||||
}
|
||||
}
|
||||
|
||||
if block != gen.Last {
|
||||
gen.Last = block
|
||||
|
|
|
@ -1,89 +0,0 @@
|
|||
package providers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"github.com/codemicro/bar/internal/i3bar"
|
||||
)
|
||||
|
||||
type BluetoothBattery struct {
|
||||
FullThreshold float32
|
||||
OkThreshold float32
|
||||
WarningThreshold float32
|
||||
|
||||
name string
|
||||
previousWasBackgroundWarning bool
|
||||
isAlert bool
|
||||
}
|
||||
|
||||
func NewBluetoothBattery(fullThreshold, okThreshold, warningThreshold float32) i3bar.BlockGenerator {
|
||||
return &BluetoothBattery{
|
||||
FullThreshold: fullThreshold,
|
||||
OkThreshold: okThreshold,
|
||||
WarningThreshold: warningThreshold,
|
||||
name: "btbattery",
|
||||
}
|
||||
}
|
||||
|
||||
func (g *BluetoothBattery) Frequency() uint8 {
|
||||
if g.isAlert {
|
||||
return 1
|
||||
}
|
||||
return 5
|
||||
}
|
||||
|
||||
type btBatteryState struct {
|
||||
DeviceName string
|
||||
Percentage uint
|
||||
}
|
||||
|
||||
func (g *BluetoothBattery) getDevicePercentage() (*btBatteryState, error) {
|
||||
rawInfo, err := runCommand("bluetoothctl", "info")
|
||||
if err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
s := new(btBatteryState)
|
||||
|
||||
for i, line := range bytes.Split(rawInfo, []byte("\n")) {
|
||||
if i != 0 && !bytes.HasPrefix(line, []byte{'\t'}) {
|
||||
break
|
||||
}
|
||||
if bytes.HasPrefix(line, []byte("\tName:")) {
|
||||
s.DeviceName = string(bytes.TrimPrefix(line, []byte("\tName: ")))
|
||||
} else if bytes.HasPrefix(line, []byte("\tBattery Percentage:")) {
|
||||
b := bytes.TrimPrefix(bytes.Fields(bytes.TrimPrefix(line, []byte("\tBattery Percentage: ")))[0], []byte("0x"))
|
||||
ui, err := strconv.ParseUint(string(b), 16, 8)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Percentage = uint(ui)
|
||||
}
|
||||
}
|
||||
|
||||
return s, nil
|
||||
}
|
||||
|
||||
func (g *BluetoothBattery) Block(colors *i3bar.ColorSet) (*i3bar.Block, error) {
|
||||
percentage, err := g.getDevicePercentage()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if percentage == nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return &i3bar.Block{
|
||||
Name: g.name,
|
||||
Instance: percentage.DeviceName,
|
||||
FullText: fmt.Sprintf("BT BAT %d%%", percentage.Percentage),
|
||||
ShortText: fmt.Sprintf("BT %d%%", percentage.Percentage),
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (g *BluetoothBattery) GetNameAndInstance() (string, string) {
|
||||
return g.name, ""
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue