Fix "no batt" case, when one of the batteries have dodgy driver
This commit is contained in:
1
Makefile
1
Makefile
@@ -13,6 +13,7 @@ build:
|
|||||||
go build ${BUILDOPTS} -o ${BINARY} ./cmd/${BINARY}
|
go build ${BUILDOPTS} -o ${BINARY} ./cmd/${BINARY}
|
||||||
|
|
||||||
battery-test:
|
battery-test:
|
||||||
|
rm -rf ${TEST1}
|
||||||
go build ${BUILDOPTS} -o ${TEST1} ./cmd/${TEST1}
|
go build ${BUILDOPTS} -o ${TEST1} ./cmd/${TEST1}
|
||||||
|
|
||||||
## Remove binary with golang compiler' means
|
## Remove binary with golang compiler' means
|
||||||
|
|||||||
@@ -11,13 +11,12 @@ import (
|
|||||||
// Program entry point.
|
// Program entry point.
|
||||||
func main() {
|
func main() {
|
||||||
for {
|
for {
|
||||||
batteries, err := battery.GetAll()
|
batteries, _ := battery.GetAll()
|
||||||
|
|
||||||
if err != nil {
|
for index, battery := range batteries {
|
||||||
fmt.Printf("Unable to get battery info: %w", err)
|
fmt.Printf("Battery %s: %s\n", index, spew.Sdump(battery))
|
||||||
}
|
}
|
||||||
|
|
||||||
spew.Dump(batteries)
|
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,21 +14,23 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
ch int
|
ch int
|
||||||
status string
|
status string
|
||||||
Batts string
|
Batts string
|
||||||
|
InitialDelay time.Duration = 100 * time.Millisecond
|
||||||
|
LoopIterationDelay time.Duration = 5 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
for {
|
Delay := InitialDelay
|
||||||
batteries, err := battery.GetAll()
|
ticker := time.NewTicker(Delay)
|
||||||
|
|
||||||
|
for range ticker.C {
|
||||||
|
if Delay == InitialDelay {
|
||||||
|
Delay = LoopIterationDelay
|
||||||
|
ticker.Reset(Delay)
|
||||||
|
}
|
||||||
|
|
||||||
|
batteries, _ := battery.GetAll()
|
||||||
|
// In theory, this module should give for each entry its separate err, but in practice it gives
|
||||||
|
// one single err for all entries, so we cannot detemine whist exatly entry errored.
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
Batts = fmt.Sprintf(
|
|
||||||
"<span font='%s' size='%s'>%s</span><span font='%s' size='%s'> no batt</span>",
|
|
||||||
c.Battery.SymbolFont,
|
|
||||||
c.Battery.SymbolFontSize,
|
|
||||||
c.Battery.Symbol,
|
|
||||||
c.Battery.Font,
|
|
||||||
c.Battery.FontSize,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
var (
|
var (
|
||||||
battsInfo string
|
battsInfo string
|
||||||
chStr string
|
chStr string
|
||||||
@@ -51,7 +53,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
ch = int(math.Round((b.Full - (b.Full - b.Current)) * (100 / b.Full)))
|
ch = int(math.Round((b.Full - (b.Full - b.Current)) * (100 / b.Full)))
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case ch > 85:
|
case ch <= 500 && ch >= 84:
|
||||||
if c.Battery.ChargeColor.Full == "" {
|
if c.Battery.ChargeColor.Full == "" {
|
||||||
chStr = fmt.Sprintf(
|
chStr = fmt.Sprintf(
|
||||||
"<span color='%s' background='%s' font='%s' size='%s'>% 3d%%</span>",
|
"<span color='%s' background='%s' font='%s' size='%s'>% 3d%%</span>",
|
||||||
@@ -114,7 +116,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
case ch < 10:
|
case ch < 10 && ch >= 0:
|
||||||
if c.Battery.ChargeColor.Empty == "" {
|
if c.Battery.ChargeColor.Empty == "" {
|
||||||
chStr = fmt.Sprintf(
|
chStr = fmt.Sprintf(
|
||||||
"<span color='%s' background='%s' font='%s' size='%s'>% 3d%%</span>",
|
"<span color='%s' background='%s' font='%s' size='%s'>% 3d%%</span>",
|
||||||
@@ -134,6 +136,9 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
ch,
|
ch,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
battsInfo += fmt.Sprintf(
|
battsInfo += fmt.Sprintf(
|
||||||
@@ -160,7 +165,6 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
|||||||
if battsInfo != "" {
|
if battsInfo != "" {
|
||||||
Batts = battsInfo
|
Batts = battsInfo
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if c.Values.BatteryString != Batts {
|
if c.Values.BatteryString != Batts {
|
||||||
c.Values.BatteryString = Batts
|
c.Values.BatteryString = Batts
|
||||||
|
|||||||
Reference in New Issue
Block a user