Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/distatus/battery
cross-platform, normalized battery information library
https://github.com/distatus/battery
battery cross-platform go
Last synced: 3 months ago
JSON representation
cross-platform, normalized battery information library
- Host: GitHub
- URL: https://github.com/distatus/battery
- Owner: distatus
- License: mit
- Created: 2016-03-12T23:03:40.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-09-27T07:39:30.000Z (over 1 year ago)
- Last Synced: 2024-07-31T20:52:23.190Z (6 months ago)
- Topics: battery, cross-platform, go
- Language: Go
- Homepage:
- Size: 78.1 KB
- Stars: 244
- Watchers: 5
- Forks: 36
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.md
Awesome Lists containing this project
- awesome-go - battery - Cross-platform, normalized battery information library. (Miscellaneous / Uncategorized)
- zero-alloc-awesome-go - battery - Cross-platform, normalized battery information library. (Miscellaneous / Uncategorized)
- awesome-go - battery - cross-platform, normalized battery information library - ★ 106 (Miscellaneous)
- awesome-go-extra - battery - platform, normalized battery information library|208|29|7|2016-03-12T23:03:40Z|2022-01-15T13:52:54Z| (Microsoft Office / Uncategorized)
- awesome-go-zh - battery
README
battery [![Build Status](https://github.com/distatus/battery/actions/workflows/tests.yml/badge.svg?branch=master)](https://github.com/distatus/battery/actions/workflows/tests.yml) [![Go Report Card](https://goreportcard.com/badge/github.com/distatus/battery)](https://goreportcard.com/report/github.com/distatus/battery) [![GoDoc](https://pkg.go.dev/badge/github.com/distatus/battery)](https://pkg.go.dev/github.com/distatus/battery)
=======Cross-platform, normalized battery information library.
Gives access to a system independent, typed battery state, capacity, charge and voltage values recalculated as necessary to be returned in mW, mWh or V units.
Currently supported systems:
* Linux 2.6.39+
* OS X 10.10+
* Windows XP+
* FreeBSD
* DragonFlyBSD
* NetBSD
* OpenBSD
* SolarisInstallation
------------```bash
$ go get -u github.com/distatus/battery
```Code Example
------------```go
package mainimport (
"fmt""github.com/distatus/battery"
)func main() {
batteries, err := battery.GetAll()
if err != nil {
fmt.Println("Could not get battery info!")
return
}
for i, battery := range batteries {
fmt.Printf("Bat%d: ", i)
fmt.Printf("state: %s, ", battery.State.String())
fmt.Printf("current capacity: %f mWh, ", battery.Current)
fmt.Printf("last full capacity: %f mWh, ", battery.Full)
fmt.Printf("design capacity: %f mWh, ", battery.Design)
fmt.Printf("charge rate: %f mW, ", battery.ChargeRate)
fmt.Printf("voltage: %f V, ", battery.Voltage)
fmt.Printf("design voltage: %f V\n", battery.DesignVoltage)
}
}
```CLI
---There is also a little utility which - more or less - mimicks the GNU/Linux `acpi -b` command.
*Installation*
```bash
$ go install github.com/distatus/battery/cmd/battery@latest
```*Usage*
```bash
$ battery
BAT0: Full, 95.61% [Voltage: 12.15V (design: 12.15V)]
```