diff options
author | Jose A Ortega Ruiz <jao@gnu.org> | 2010-02-22 17:47:29 +0100 |
---|---|---|
committer | Jose A Ortega Ruiz <jao@gnu.org> | 2010-02-22 17:47:29 +0100 |
commit | 7350d55936ffcc4a0b1b0eb08a60a3433e74fc5a (patch) | |
tree | 4ef42333a4d0c6183159bfa2194f9078a26f1612 | |
parent | 32dc866c396c262d3781e03bdfd1acd2b4a151ee (diff) | |
download | xmobar-7350d55936ffcc4a0b1b0eb08a60a3433e74fc5a.tar.gz xmobar-7350d55936ffcc4a0b1b0eb08a60a3433e74fc5a.tar.bz2 |
Wireless monitor: correctly computing link qualities
Ignore-this: d03b31a12d52cf482841aae0fcf6829b
darcs-hash:20100222164729-748be-ba76d94a4870bab3b9d8e7957af4d3097677dc0a.gz
-rw-r--r-- | IWlib.hsc | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -56,7 +56,7 @@ getWirelessInfo iface = str <- c_iw_stats i istr stats rng 1 rgr <- c_iw_range i istr rng c_iw_close i - if (bcr < 0) then return $WirelessInfo {wiEssid = "", wiQuality = -1} else + if (bcr < 0) then return nullInfo else do hase <- (#peek struct wireless_config, has_essid) wc :: IO CInt eon <- (#peek struct wireless_config, essid_on) wc :: IO CInt essid <- if hase > 0 && eon > 0 then @@ -65,12 +65,13 @@ getWirelessInfo iface = peekCStringLen (e, fromIntegral (l :: CInt)) else return "" q <- if str >= 0 && rgr >=0 then - do let qual = (#ptr struct iw_statistics, qual) stats - qualv <- (#peek struct iw_param, value) qual :: IO CInt - let qualm = (#ptr struct iw_range, max_qual) rng - mv <- (#peek struct iw_param, value) qualm :: IO CInt + do qualv <- xqual $ (#ptr struct iw_statistics, qual) stats + mv <- xqual $ (#ptr struct iw_range, max_qual) rng let mxv = if mv > 0 then fromIntegral mv else 1 return $ fromIntegral qualv / mxv else return (-1) let qv = round (100 * (q :: Double)) return $ WirelessInfo { wiEssid = essid, wiQuality = min 100 qv } + where nullInfo = WirelessInfo { wiEssid = "", wiQuality = -1 } + xqual p = let qp = (#ptr struct iw_param, value) p in + (#peek struct iw_quality, qual) qp :: IO CChar |