Compare commits
1 Commits
v1.4
...
64da06663c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
64da06663c |
@@ -16,10 +16,14 @@ import (
|
||||
// UpdateBatteryInfo updates info about battery charge.
|
||||
func (c *MyConfig) UpdateBatteryInfo() {
|
||||
var (
|
||||
ch int
|
||||
status string
|
||||
Batts string
|
||||
InitialDelay = 100 * time.Millisecond
|
||||
LoopIterationDelay = 5 * time.Second
|
||||
Delay = InitialDelay
|
||||
ticker = time.NewTicker(Delay)
|
||||
batteries []*battery.Battery
|
||||
)
|
||||
|
||||
for range ticker.C {
|
||||
@@ -28,17 +32,8 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
||||
ticker.Reset(Delay)
|
||||
}
|
||||
|
||||
var (
|
||||
batteries []*battery.Battery = []*battery.Battery{}
|
||||
Batts string
|
||||
ch int
|
||||
status string
|
||||
)
|
||||
|
||||
if c.Battery.UseSysfs {
|
||||
for _, file := range c.Battery.SysfsFiles {
|
||||
var batt battery.Battery
|
||||
|
||||
for battNum, file := range c.Battery.SysfsFiles {
|
||||
_, err := os.Stat(file)
|
||||
|
||||
// If file exists.
|
||||
@@ -57,7 +52,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
||||
|
||||
myCharge = strings.Trim(string(b), "\n")
|
||||
|
||||
statusFile := filepath.Dir(file) + "/status"
|
||||
statusFile := filepath.Dir(file) + "status"
|
||||
|
||||
// If file exists.
|
||||
if !os.IsNotExist(err) {
|
||||
@@ -76,15 +71,15 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
||||
// Make stub battery class :) .
|
||||
switch myStatus {
|
||||
case "Charging":
|
||||
batt.State.Raw = battery.Charging
|
||||
batteries[battNum].State.Raw = battery.Charging
|
||||
case "Discharging":
|
||||
batt.State.Raw = battery.Discharging
|
||||
batteries[battNum].State.Raw = battery.Discharging
|
||||
case "Empty":
|
||||
batt.State.Raw = battery.Empty
|
||||
batteries[battNum].State.Raw = battery.Empty
|
||||
case "Full":
|
||||
batt.State.Raw = battery.Full
|
||||
batteries[battNum].State.Raw = battery.Full
|
||||
default:
|
||||
batt.State.Raw = battery.Unknown
|
||||
batteries[battNum].State.Raw = battery.Unknown
|
||||
}
|
||||
|
||||
ch, err := strconv.Atoi(myCharge)
|
||||
@@ -94,9 +89,7 @@ func (c *MyConfig) UpdateBatteryInfo() {
|
||||
continue
|
||||
}
|
||||
|
||||
batt.Current = float64(ch)
|
||||
|
||||
batteries = append(batteries, &batt)
|
||||
batteries[battNum].Current = float64(ch)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -783,10 +783,7 @@ func ReadConf(defaultConfig []byte) (*MyConfig, error) {
|
||||
// sampleConfig.Battery.UseSysfs will be false if not set in config
|
||||
|
||||
if len(sampleConfig.Battery.SysfsFiles) == 0 {
|
||||
sampleConfig.Battery.SysfsFiles = append(
|
||||
sampleConfig.Battery.SysfsFiles,
|
||||
"/sys/class/power_supply/BAT0/capacity",
|
||||
)
|
||||
sampleConfig.Battery.SysfsFiles[0] = "/sys/class/power_supply/BAT0/capacity"
|
||||
}
|
||||
|
||||
if sampleConfig.Battery.Color == "" {
|
||||
|
||||
Reference in New Issue
Block a user