From e154d88e03e05b2dad34408b05ed944024036ba5 Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 18 Feb 2018 22:38:51 +0100 Subject: Batt: Try also "BAT" (fixes #338) --- readme.md | 6 ++++-- src/Plugins/Monitors/Batt.hs | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/readme.md b/readme.md index 45158cf..ae2edf1 100644 --- a/readme.md +++ b/readme.md @@ -816,15 +816,17 @@ something like: ### `Battery Args RefreshRate` -- Same as `BatteryP ["BAT0", "BAT1", "BAT2"] Args RefreshRate`. +- Same as `BatteryP ["BAT", "BAT0", "BAT1", "BAT2"] Args RefreshRate`. ### `BatteryP Dirs Args RefreshRate` - Aliases to `battery` + - Dirs: list of directories in `/sys/class/power_supply/` where to look for the ACPI files of each battery. Example: - `["BAT0","BAT1","BAT2"]`. Only the first 3 directories will be + `["BAT0","BAT1","BAT2"]`. Only up to 3 existing directories will be searched. + - Args: default monitor arguments, plus the following specific ones (these options, being specific to the monitor, are to be specified after a `--` in the argument list): diff --git a/src/Plugins/Monitors/Batt.hs b/src/Plugins/Monitors/Batt.hs index 0469ac2..eeeb049 100644 --- a/src/Plugins/Monitors/Batt.hs +++ b/src/Plugins/Monitors/Batt.hs @@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module : Plugins.Monitors.Batt --- Copyright : (c) 2010, 2011, 2012, 2013, 2015, 2016 Jose A Ortega +-- Copyright : (c) 2010, 2011, 2012, 2013, 2015, 2016, 2018 Jose A Ortega -- (c) 2010 Andrea Rossato, Petr Rockai -- License : BSD-style (see LICENSE) -- @@ -107,7 +107,7 @@ data Files = Files , fCurrent :: String , fStatus :: String , isCurrent :: Bool - } | NoFiles + } | NoFiles deriving Eq data Battery = Battery { full :: !Float @@ -174,7 +174,8 @@ mostCommonDef x xs = head $ last $ [x] : sortOn length (group xs) readBatteries :: BattOpts -> [Files] -> IO Result readBatteries opts bfs = - do bats <- mapM (readBattery (scale opts)) (take 3 bfs) + do let bfs' = filter (/= NoFiles) bfs + bats <- mapM (readBattery (scale opts)) (take 3 bfs') ac <- haveAc (onlineFile opts) let sign = if ac then 1 else -1 ft = sum (map full bats) @@ -194,7 +195,7 @@ readBatteries opts bfs = return $ if isNaN left then NA else Result left watts time racst runBatt :: [String] -> Monitor String -runBatt = runBatt' ["BAT0","BAT1","BAT2"] +runBatt = runBatt' ["BAT", "BAT0", "BAT1", "BAT2"] runBatt' :: [String] -> [String] -> Monitor String runBatt' bfs args = do -- cgit v1.2.3