glbat

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 2, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

README

glbat

glbat - Go Linux Battery library.

This library obtains and serializes battery data from /sys/class/power_supply.

Install

go get github.com/alexcoder04/glbat

Use

package ...

import (
    "fmt"
    ...

    "github.com/alexcoder04/glbat"
)

func ...() {
    bats, err := glbat.GetAll()
    if err != nil {
        return
    }

    for _, bat := range bats {
        fmt.Printf("Battery %d (%s/%s): %s, %d%%", bat.Id, bat.Manufacturer, bat.ModelName, bat.Status, bat.Capacity)
    }
}

Documentation

See pkg.go.dev.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDetected

func GetDetected() ([]int, error)

Returns a list of detected battery ids.

Types

type Battery

type Battery struct {
	// battery id
	Id int

	// current battery capacity in percent
	Capacity         int
	CapacityLevel    string
	CycleCount       int
	EnergyFull       int
	EnergyFullDesign int
	EnergyNow        int
	Manufacturer     string
	ModelName        string
	PowerNow         int
	// whether the battery is present
	Present      bool
	SerialNumber string
	// battery status, e. g. "Charging"
	Status           string
	Technology       string
	VoltageNow       int
	VoltageMinDesign int
}

func GetAll

func GetAll() ([]Battery, error)

Get data for all batteries.

func GetBat

func GetBat(id int) (Battery, error)

Get data for battery with a certain id.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL