func (b *Battery) ChargeFull() int64 { var str string if helper.IsFile(psp(b.Key, "energy_full")) { str, _ = helper.StringFromFile(psp(b.Key, "energy_full")) } else { str, _ = helper.StringFromFile(psp(b.Key, "charge_full")) } i, _ := strconv.ParseInt(str, 10, 64) return i }
/* Given a key like "AC" or "BAT0", determine whether it is a battery type */ func IsBattery(key string) bool { type_file := filepath.Join(PowerSupplyPath, key, "type") if str, err := helper.StringFromFile(type_file); err == nil && strings.Contains(str, "Battery") { return true } return false }
// Version of the current running kernel, /proc/version func GetVersion() string { str, err := helper.StringFromFile(VersionPath) if err != nil { if !quiet { fmt.Fprintf(os.Stderr, "WARN: %s\n", err) } return "" } return str }
// get the current LoadAvg func GetLoadAvg() LoadAvg { str, err := helper.StringFromFile(LoadAvgPath) if err != nil { if !quiet { fmt.Fprintf(os.Stderr, "WARN: %s\n", err) } return LoadAvg{} } values := strings.Split(str, " ") sAndE := strings.Split(values[3], "/") return LoadAvg{ values[0], values[1], values[2], sAndE[0], sAndE[1], } }
func (g *GenericPowerSupply) GetInfo() (*Info, error) { info := Info{ Key: g.Key, Time: time.Now().UnixNano(), Values: map[string]string{}, Load: GetLoadAvg(), Version: GetVersion(), } files, err := filepath.Glob(filepath.Join(PowerSupplyPath, g.Key, "*")) if err != nil { return nil, err } for _, file := range files { if helper.IsFile(file) { if str, err := helper.StringFromFile(file); err == nil { info.Values[filepath.Base(file)] = str } } } return &info, nil }
func (b *Battery) Status() string { str, _ := helper.StringFromFile(psp(b.Key, "status")) return str }