packages feed

HPi 0.1.0.0 → 0.2.0

raw patch · 2 files changed

+5/−3 lines, 2 files

Files

HPi.cabal view
@@ -2,7 +2,7 @@ -- see http://haskell.org/cabal/users-guide/
 
 name:                HPi
-version:             0.1.0.0
+version:             0.2.0
 synopsis:            GPIO and I2C functions for the Raspberry Pi.
 description:         This package is a FFI wrapper around the bcm2835 library by Mike McCauley, it also includes a few utility functions for easier use of the imported functions.
 homepage:            https://github.com/WJWH/HPi
System/RaspberryPi/GPIO.hs view
@@ -29,12 +29,13 @@ --hook for the
 
 import Control.Applicative ((<$>))
-import Control.Exception (bracket, bracket_)
+import Control.Exception
 import Foreign
 import Foreign.C
 import Foreign.C.String
 import qualified Data.ByteString as BS
 import qualified Data.ByteString.Char8 as BSC
+import GHC.IO.Exception
 
 ------------------------------------------------------------------------------------------------------------------------------------
 --------------------------------------------- Data types ---------------------------------------------------------------------------
@@ -106,7 +107,8 @@ withGPIO :: IO a -> IO a
 withGPIO f = bracket    initBCM2835
                         (const stopBCM2835) --const because you don't care about the output of initBCM2835
-                        (\a -> if a==0 then error "Initialisation of GPIO failed" else f) -- init returning 0 is not good
+                        (\a -> if a==0 then throwIO ioe else f) -- init returning 0 is not good
+                            where ioe = IOError Nothing IllegalOperation "GPIO: " "Unable to start GPIO." Nothing Nothing
 
 -- |Any IO computation that uses the I2C bus using this library should be wrapped with this function; ie @withI2C $ do foo@.
 -- It prepares the relevant pins for use with the I2C protocol and makes sure everything is safely returned to normal if an exception