From 3b25b5bc0254c7462555c9911c67266627428795 Mon Sep 17 00:00:00 2001 From: Jackson Taylor Date: Fri, 2 Oct 2020 23:10:52 -0400 Subject: Create modules package --- modules/batteryModule.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 modules/batteryModule.go (limited to 'modules/batteryModule.go') diff --git a/modules/batteryModule.go b/modules/batteryModule.go new file mode 100644 index 0000000..d4593ff --- /dev/null +++ b/modules/batteryModule.go @@ -0,0 +1,29 @@ +package modules + +import ( + "io/ioutil" +) + +// TODO: Move this to a central spot, like a config.h +const ( + batteryPath = "/sys/class/power_supply/BAT0/capacity" +) + +// BatteryModule is the module that controls finding out the battery +// percentage, mainly useful in laptops +type BatteryModule struct { +} + +func (_ BatteryModule) GetInfo() (string, error) { + return readBatteryLevel(batteryPath) +} + +func readBatteryLevel(path string) (string, error) { + dat, err := ioutil.ReadFile(path) + + if err != nil { + return "NULL", err + } + + return (string(dat[:len(dat)-1]) + "%"), nil +} -- cgit v1.2.3