packages feed

bindings-K8055 (empty) → 0.1

raw patch · 11 files changed

+452/−0 lines, 11 filesdep +basesetup-changedbinary-added

Dependencies added: base

Files

+ Bindings/K8055.hs view
@@ -0,0 +1,65 @@+{-+ * Create K8055D.def with exports+ * dlltool -d K8055D.def -l K8055D.a+ * Use --extra-lib-dirs=. with cabal configure/install+-}+module Bindings.K8055 (+  getVersion,+  -- * General Procedures+  CardAddress(..),+  withDevice,+  module Bindings.K8055.AnalogIn,+  module Bindings.K8055.AnalogOut,+  module Bindings.K8055.DigitalOut,+  module Bindings.K8055.DigitalIn,+  module Bindings.K8055.Counters+  ) where++import Foreign.C+import Control.Monad+import Bindings.K8055.AnalogIn+import Bindings.K8055.AnalogOut+import Bindings.K8055.DigitalOut+import Bindings.K8055.DigitalIn+import Bindings.K8055.Counters+++-- | Depends on jumpers SK5, SK6 +data CardAddress +  = Card1  -- ^ SK5:ON  SK6:ON+  | Card2  -- ^ SK5:OFF SK6:ON+  | Card3  -- ^ SK5:ON  SK6:OFF+  | Card4  -- ^ SK5:OFF SK6:OFF+    +addressId :: Num a => CardAddress -> a+addressId address = +  case address of+    Card1 -> 0+    Card2 -> 1+    Card3 -> 2+    Card4 -> 3++    +foreign import stdcall unsafe "Version"+  c_Version :: IO CInt+               +getVersion :: IO Int+getVersion = do+  vers <- c_Version+  return $ fromIntegral vers+++foreign import stdcall unsafe "OpenDevice"+  c_OpenDevice :: CInt -> IO CInt++foreign import stdcall unsafe "CloseDevice"+  c_CloseDevice :: IO ()+                   +-- | Device is opened, action is performed and device is closed+withDevice :: CardAddress -> IO a -> IO a +withDevice address action = do+  ret <- c_OpenDevice (addressId address)+  when (ret /= 0) (error "open device failed")+  result <- action+  c_CloseDevice+  return result
+ Bindings/K8055/AnalogIn.hs view
@@ -0,0 +1,47 @@+module Bindings.K8055.AnalogIn (+  AnalogInput(..),+  readAnalogChannel, +  readAllAnalog+  ) where++import Foreign.C+import Foreign.Ptr+import Foreign.Marshal+import Foreign.Storable+import Data.Word++data AnalogInput+  = AnalogIn1+  | AnalogIn2+    +analogInputId :: Num a => AnalogInput -> a+analogInputId input =+  case input of+    AnalogIn1 -> 1+    AnalogIn2 -> 2+   +    +foreign import stdcall unsafe "ReadAnalogChannel"+  c_ReadAnalogChannel :: CInt -> IO CInt++-- | Reads the status of one analogue input-channel+readAnalogChannel :: AnalogInput -> IO Word8+readAnalogChannel channel = do+  res <- c_ReadAnalogChannel (analogInputId channel)+  return $ fromIntegral res+  ++foreign import stdcall unsafe "ReadAllAnalog"+  c_ReadAllAnalog :: Ptr CInt -> Ptr CInt -> IO ()++-- | Reads the status of both analogue input-channels+readAllAnalog :: IO (Word8, Word8)+readAllAnalog = do+  alloca $ \ a1 -> +    alloca $ \ a2 -> do+      c_ReadAllAnalog a1 a2+      a1' <- peek a1+      a2' <- peek a2+      return (fromIntegral a1', fromIntegral a2')++
+ Bindings/K8055/AnalogOut.hs view
@@ -0,0 +1,74 @@+module Bindings.K8055.AnalogOut (+  AnalogOutput(..),+  outputAnalogChannel,+  outputAllAnalog,+  clearAnalogChannel,+  clearAllAnalog,+  setAnalogChannel,+  setAllAnalog+  ) where++import Foreign.C+import Data.Word++data AnalogOutput+  = AnalogOut1+  | AnalogOut2+    +analogOutputId :: Num a => AnalogOutput -> a+analogOutputId output =                                       +  case output of+    AnalogOut1 -> 0+    AnalogOut2 -> 1++foreign import stdcall unsafe "OutputAnalogChannel"+  c_OutputAnalogChannel :: CInt -> CInt -> IO ()++-- | Sets the analogue output channel according to the data+outputAnalogChannel :: AnalogOutput -> Word8 -> IO ()+outputAnalogChannel channel dat = do+  c_OutputAnalogChannel (analogOutputId channel) (fromIntegral dat)+++foreign import stdcall unsafe "OutputAllAnalog"+  c_OutputAllAnalog :: CInt -> CInt -> IO ()+                       +-- | Sets both analogue output channels according to the data+outputAllAnalog :: Word8 -> Word8 -> IO ()+outputAllAnalog val1 val2 = do+  c_OutputAllAnalog (fromIntegral val1) (fromIntegral val2)+++foreign import stdcall unsafe "ClearAnalogChannel"+  c_ClearAnalogChannel :: CInt -> IO ()++-- | Sets the analogue output channel to minimum+clearAnalogChannel :: AnalogOutput -> IO ()+clearAnalogChannel channel = do+  c_ClearAnalogChannel (analogOutputId channel)+++foreign import stdcall unsafe "ClearAllAnalog"+  c_ClearAllAnalog :: IO ()+                   +-- | Sets all analogue output channels to minimum+clearAllAnalog :: IO ()+clearAllAnalog = c_ClearAllAnalog+++foreign import stdcall unsafe "SetAnalogChannel"      +  c_SetAnalogChannel :: CInt -> IO ()++-- | Sets the analogue output channel to maximum+setAnalogChannel :: AnalogOutput -> IO ()+setAnalogChannel channel = do+  c_SetAnalogChannel (analogOutputId channel)+++foreign import stdcall unsafe "SetAllAnalog"+  c_SetAllAnalog :: IO ()+                    +-- | Sets all analogue output channels to maximum+setAllAnalog :: IO ()+setAllAnalog = c_SetAllAnalog+
+ Bindings/K8055/Counters.hs view
@@ -0,0 +1,49 @@+module Bindings.K8055.Counters (+  Counter(..),+  resetCounter,+  readCounter,+  setCounterDebounceTime) where+++import Foreign.C+++data Counter+  = Counter1+  | Counter2+    +counterId :: Num a => Counter -> a+counterId cnt =+  case cnt of+    Counter1 -> 1+    Counter2 -> 2+++foreign import stdcall unsafe "ResetCounter"+  c_ResetCounter :: CInt -> IO ()++-- | Resets the 16 bit pulse counter number 1 or counter number 2+resetCounter :: Counter -> IO ()+resetCounter cnt =+  c_ResetCounter (counterId cnt)+++foreign import stdcall unsafe "ReadCounter"+  c_ReadCounter :: CInt -> IO CInt        +                   +-- | Reads the content of the pulse counte rnumber 1 or counter number 2+readCounter :: Counter -> IO Int+readCounter cnt = do+  val <- c_ReadCounter (counterId cnt)+  return $ fromIntegral val+++foreign import stdcall unsafe "SetCounterDebounceTime"+  c_SetCounterDebounceTime :: CInt -> CInt -> IO ()++-- | Sets the debounce time to the pulse counter+setCounterDebounceTime :: Counter    +                          -> Int    -- ^ 0 - 5000+                          -> IO ()+setCounterDebounceTime cnt debounce =+  c_SetCounterDebounceTime (counterId cnt) (fromIntegral debounce)
+ Bindings/K8055/DigitalIn.hs view
@@ -0,0 +1,51 @@+module Bindings.K8055.DigitalIn (  +  DigitalInput(..),+  readDigitalChannel,+  readAllDigital+  ) where++import Data.Word+import Foreign.C++data DigitalInput+  = DigitalIn1+  | DigitalIn2+  | DigitalIn3+  | DigitalIn4+  | DigitalIn5+  | DigitalIn6+  | DigitalIn7+  | DigitalIn8+    +digitalInputId :: Num a => DigitalInput -> a+digitalInputId input =+  case input of+    DigitalIn1 -> 1+    DigitalIn2 -> 2+    DigitalIn3 -> 3+    DigitalIn4 -> 4+    DigitalIn5 -> 5+    DigitalIn6 -> 6+    DigitalIn7 -> 7+    DigitalIn8 -> 8+++foreign import stdcall unsafe "ReadDigitalChannel"+  c_ReadDigitalChannel :: CInt -> IO CInt++-- | Reads the status of the input channel+readDigitalChannel :: DigitalInput -> IO Word8+readDigitalChannel input = do+  res <- c_ReadDigitalChannel (digitalInputId input)+  return $ fromIntegral res+++foreign import stdcall unsafe "ReadAllDigital"+  c_ReadAllDigital :: IO CInt++-- | Reads the status of all the input channels+readAllDigital :: IO Word8+readAllDigital = do+  res <- c_ReadAllDigital+  return $ fromIntegral res+
+ Bindings/K8055/DigitalOut.hs view
@@ -0,0 +1,79 @@+module Bindings.K8055.DigitalOut (+  DigitalOutput(..),+  writeAllDigital,+  clearDigitalChannel,+  clearAllDigital,+  setDigitalChannel,+  setAllDigital+  ) where++import Foreign.C+import Data.Word++data DigitalOutput+  = DigitalOut1+  | DigitalOut2+  | DigitalOut3+  | DigitalOut4+  | DigitalOut5+  | DigitalOut6+  | DigitalOut7+  | DigitalOut8++digitalOutputId :: Num a => DigitalOutput -> a+digitalOutputId output =+  case output of+    DigitalOut1 -> 1+    DigitalOut2 -> 2+    DigitalOut3 -> 3+    DigitalOut4 -> 4+    DigitalOut5 -> 5+    DigitalOut6 -> 6+    DigitalOut7 -> 7+    DigitalOut8 -> 8+++foreign import stdcall unsafe "WriteAllDigital"+  c_WriteAllDigital :: CInt -> IO ()++-- | Sets the digital outputs according to the data+writeAllDigital :: Word8 -> IO ()+writeAllDigital val =+  c_WriteAllDigital (fromIntegral val)+++foreign import stdcall unsafe "ClearDigitalChannel"+  c_ClearDigitalChannel :: CInt -> IO ()++-- | Clears the output channel+clearDigitalChannel :: DigitalOutput -> IO ()+clearDigitalChannel dig =+  c_ClearDigitalChannel (digitalOutputId dig)+++foreign import stdcall unsafe "ClearAllDigital"+  c_ClearAllDigital :: IO ()++-- | Clears all output channels+clearAllDigital :: IO ()+clearAllDigital = c_ClearAllDigital+++foreign import stdcall unsafe "SetDigitalChannel"+  c_SetDigitalChannel :: CInt -> IO ()++-- | Sets the output channel+setDigitalChannel :: DigitalOutput -> IO ()+setDigitalChannel dig = +  c_SetDigitalChannel (digitalOutputId dig)+++foreign import stdcall unsafe "SetAllDigital"+  c_SetAllDigital :: IO ()++-- | Sets all output channels+setAllDigital :: IO ()+setAllDigital = c_SetAllDigital+++
+ K8055D.a view

binary file changed (absent → 7150 bytes)

+ K8055D.def view
@@ -0,0 +1,24 @@+LIBRARY K8055D+EXPORTS+    Version+    OpenDevice+    CloseDevice+    ReadAnalogChannel+    SetAllAnalog+    ClearAllAnalog+    SetAllDigital+    ClearAllDigital+    ClearDigitalChannel+    SetDigitalChannel+    ReadDigitalChannel+    ReadAllDigital+    OutputAnalogChannel+    ClearAnalogChannel+    SetAnalogChannel+    WriteAllDigital+    OutputAllAnalog+    ReadCounter+    ResetCounter+    SetCurrentDevice+    SearchDevices+    ReadAllAnalog
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c)2011, Joris Putcuyps++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Joris Putcuyps nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ bindings-K8055.cabal view
@@ -0,0 +1,31 @@+Name:                bindings-K8055+Version:             0.1+Synopsis:            Bindings to Velleman K8055 dll+description:         Bindings to Velleman K8055 dll for interfacing USB I/O board.+License:             BSD3+License-file:        LICENSE+Author:              Joris Putcuyps+Maintainer:          Joris.Putcuyps@gmail.com+Homepage:            https://github.com/jputcu/bindings-K8055+bug-reports:         https://github.com/jputcu/bindings-K8055/issues+Category:            FFI+Build-type:          Simple+Cabal-version:       >=1.2+extra-source-files:  K8055D.def K8055D.a++Library+  Exposed-modules:+    Bindings.K8055,+    Bindings.K8055.AnalogIn,+    Bindings.K8055.AnalogOut,+    Bindings.K8055.DigitalOut,+    Bindings.K8055.DigitalIn,+    Bindings.K8055.Counters+  +  Build-depends: +    base >= 3 && < 5++  extra-libraries: K8055D+  extra-lib-dirs: .+  extensions: ForeignFunctionInterface+  ghc-options: -Wall