summaryrefslogtreecommitdiff
path: root/modules/batteryModule.go
diff options
context:
space:
mode:
authorJackson Taylor <jtaylormuffins@gmail.com>2020-10-02 23:10:52 -0400
committerJackson Taylor <jtaylormuffins@gmail.com>2020-10-02 23:10:52 -0400
commit3b25b5bc0254c7462555c9911c67266627428795 (patch)
treecb01d1fe194999925f452651230d46b1be663d2b /modules/batteryModule.go
parentcdeb1de96fbd01865497b481aa00c4032c446d66 (diff)
Create modules packageHEADmaster
Diffstat (limited to 'modules/batteryModule.go')
-rw-r--r--modules/batteryModule.go29
1 files changed, 29 insertions, 0 deletions
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
+}