diff options
Diffstat (limited to 'packages/code')
| -rw-r--r-- | packages/code/dfetch/app/Dfetch/Battery.hs | 24 | ||||
| -rw-r--r-- | packages/code/dfetch/app/Dfetch/Brightness.hs | 29 | ||||
| -rw-r--r-- | packages/code/dfetch/app/Main.hs | 7 | ||||
| -rw-r--r-- | packages/code/dfetch/dfetch.cabal | 6 |
4 files changed, 49 insertions, 17 deletions
diff --git a/packages/code/dfetch/app/Dfetch/Battery.hs b/packages/code/dfetch/app/Dfetch/Battery.hs index 6e6a0a8..0315882 100644 --- a/packages/code/dfetch/app/Dfetch/Battery.hs +++ b/packages/code/dfetch/app/Dfetch/Battery.hs @@ -3,24 +3,32 @@ module Dfetch.Battery , allBatteries ) where -import System.FilePath ((</>)) -import System.Directory (listDirectory) -import Data.List (isPrefixOf) +import Data.List (isPrefixOf) +import System.Directory (listDirectory) +import System.FilePath ((</>)) basePath :: FilePath basePath = "/sys/class/power_supply/" data Battery = Battery - {name :: String, capacity :: Int} deriving (Show) + { name :: String + , capacity :: Int + , energy :: Double + , energyFull :: Double + } deriving (Show, Eq) getCapacity :: String -> IO Battery -getCapacity name = Battery <$> pure name <*> capacity +getCapacity bName = Battery + <$> pure bName + <*> (read <$> readFile (path </> "capacity")) + <*> (read <$> readFile (path </> "energy_now")) + <*> (read <$> readFile (path </> "energy_full")) where - path = basePath </> name </> "capacity" - capacity = read <$> readFile path + path = basePath </> bName findBatteries :: IO [String] findBatteries = filter ("BAT" `isPrefixOf`) <$> listDirectory basePath +-- | Fetch all batteries from the running system allBatteries :: IO [Battery] -allBatteries = findBatteries >>= traverse getCapacity +allBatteries = findBatteries >>= mapM getCapacity diff --git a/packages/code/dfetch/app/Dfetch/Brightness.hs b/packages/code/dfetch/app/Dfetch/Brightness.hs index 912905a..9d7b7b9 100644 --- a/packages/code/dfetch/app/Dfetch/Brightness.hs +++ b/packages/code/dfetch/app/Dfetch/Brightness.hs @@ -1,8 +1,29 @@ -module Dfetch.Brightness where +module Dfetch.Brightness + ( Brightness(..) + , fetchBrightness + , allBs + ) where -import System.FilePath ((</>)) -import System.Directory (listDirectory) -import Data.List (isPrefixOf) +import System.Directory (listDirectory) +import System.FilePath ((</>)) basePath :: FilePath basePath = "/sys/class/backlight/" + +data Brightness = Brightness + { bright :: Int + , maxbright :: Int + } deriving Show + +backlights :: IO [String] +backlights = listDirectory basePath + +fetchBrightness :: String -> IO Brightness +fetchBrightness device = Brightness + <$> (read <$> readFile (path </> "brightness")) + <*> (read <$> readFile (path </> "max_brightness")) + where + path = basePath </> device + +allBs :: IO [Brightness] +allBs = backlights >>= mapM fetchBrightness diff --git a/packages/code/dfetch/app/Main.hs b/packages/code/dfetch/app/Main.hs index d9a15ac..e04ff42 100644 --- a/packages/code/dfetch/app/Main.hs +++ b/packages/code/dfetch/app/Main.hs @@ -1,8 +1,11 @@ module Main (main) where import Dfetch.Battery (allBatteries) +import Dfetch.Brightness (allBs) main :: IO () main = do - bs <- allBatteries - print bs + bats <- allBatteries + backlights <- allBs + print bats + print backlights diff --git a/packages/code/dfetch/dfetch.cabal b/packages/code/dfetch/dfetch.cabal index 4b23eb3..ff2255e 100644 --- a/packages/code/dfetch/dfetch.cabal +++ b/packages/code/dfetch/dfetch.cabal @@ -3,13 +3,13 @@ name: dfetch version: 0.1.0.0 -- synopsis: -- description: -license: BSD-3-Clause -license-file: LICENSE +-- license: BSD-3-Clause +-- license-file: LICENSE author: Kleidi Bujari maintainer: mail@4kb.net -- copyright: build-type: Simple -extra-doc-files: CHANGELOG.md +-- extra-doc-files: CHANGELOG.md -- extra-source-files: common warnings |
