Ejemplo n.º 1
0
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
}
Ejemplo n.º 2
0
/*
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
}
Ejemplo n.º 3
0
// 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
}
Ejemplo n.º 4
0
// 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],
	}
}
Ejemplo n.º 5
0
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
}
Ejemplo n.º 6
0
func (b *Battery) Status() string {
	str, _ := helper.StringFromFile(psp(b.Key, "status"))
	return str
}