packages feed

huckleberry 0.10.0.0 → 0.10.0.1

raw patch · 12 files changed

+402/−1 lines, 12 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

Files

+ README.md view
@@ -0,0 +1,28 @@+# huckleberry: Haskell IOT on Intel Edison and other Linux computers.++This package provides the library, for performing physical I/O on Linux computers. It provides features such as the following:++* GPIO for input++* GPIO for output++* PWM signal output++* SPI++* I2C+++# Prerequisites++Currentry this library was tested only for Intel Edison++* [Intel Edison](https://en.wikipedia.org/wiki/Intel_Edison)++* [stack](https://docs.haskellstack.org) installed on Intel Edison++++# Authors++This library was written by Takamasa Mitsuji.
+ demo/GpioIn.hs view
@@ -0,0 +1,22 @@+import Control.Monad(forM_)+import Control.Concurrent(threadDelay)+import System.PIO.Linux.GPIO(getValue)++{--+Connection for Intel Edison++$ sh/setup_in.sh 78++[J20-11]+[J19- 2]++--}+++test = do++  forM_ [0..999] $ \_ -> do+    +    print =<< getValue 78+    threadDelay $ 100 * 1000+
+ demo/GpioOut.hs view
@@ -0,0 +1,27 @@+import Control.Monad(forM_)+import Control.Concurrent(threadDelay)+import System.PIO.Linux.GPIO(setValue)++{--+Connection for Intel Edison++$ sh/setup_out.sh 78++[J20-11] == ++[J19- 3] == -++--}+++test = do++  forM_ [0..9] $ \_ -> do+    +    setValue 78 True+    threadDelay $ 500 * 1000+    +    setValue 78 False+    threadDelay $ 500 * 1000++  +
+ demo/I2C.hs view
@@ -0,0 +1,78 @@+import Data.Int(Int16)+import Data.Word(Word8)+import Data.Bits((.|.),(.&.),shiftL,shiftR)+import Foreign.Ptr(Ptr)+import Foreign.Marshal.Array(allocaArray,withArrayLen,peekArray)+import Control.Monad(forM_)+import Control.Concurrent(threadDelay)++import System.PIO(hexToNum)+import System.PIO.Linux(fdOpen,IOMode(ReadWriteMode),fdClose,fdGetBuf,fdPutBuf)+import System.PIO.Linux.I2C.Raw(setSlave)+++{--++Connection for Intel Edison++$ sh/setup_i2c.sh 6 27 28++[J17-7] == SCL+[J17-9] == SDA+[J19-2] == VDD+[J19-3] == GND++--}+++hex :: String -> Word8+hex = hexToNum+++demo1 :: IO ()+demo1 = do+  +  fd <- fdOpen "/dev/i2c-6" ReadWriteMode+  setSlave fd $ hex "1E"++  withArrayLen [hex "00", hex "70"] $ \len p -> fdPutBuf fd p len+  withArrayLen [hex "01", hex "A0"] $ \len p -> fdPutBuf fd p len+  withArrayLen [hex "02", hex "01"] $ \len p -> fdPutBuf fd p len+  threadDelay $ 10 * 1000++  xh:xl:zh:zl:yh:yl:_ <- allocaArray 6 $+    \p -> fdGetBuf fd (p :: Ptr Word8) 6 >> peekArray 6 p+  let x = ((fromIntegral xh :: Int16) `shiftL` 8) .|. (fromIntegral xl :: Int16)+  let z = ((fromIntegral zh :: Int16) `shiftL` 8) .|. (fromIntegral zl :: Int16)+  let y = ((fromIntegral yh :: Int16) `shiftL` 8) .|. (fromIntegral yl :: Int16)+  print $ (show x) ++ ":" ++ (show y) ++ ":" ++ (show z)++  fdClose fd+++demo2 :: IO ()+demo2 = do+  +  fd <- fdOpen "/dev/i2c-6" ReadWriteMode+  setSlave fd $ hex "1E"++  withArrayLen [hex "00", hex "70"] $ \len p -> fdPutBuf fd p len+  withArrayLen [hex "01", hex "A0"] $ \len p -> fdPutBuf fd p len+  withArrayLen [hex "02", hex "00"] $ \len p -> fdPutBuf fd p len+  threadDelay $ 10 * 1000++  forM_ [0..99] $ \_ -> do+    +    withArrayLen [hex "03"] $ \len p -> fdPutBuf fd p len+    +    xh:xl:zh:zl:yh:yl:_ <- allocaArray 6 $+      \p -> fdGetBuf fd (p :: Ptr Word8) 6 >> peekArray 6 p+    let x = ((fromIntegral xh :: Int16) `shiftL` 8) .|. (fromIntegral xl :: Int16)+    let z = ((fromIntegral zh :: Int16) `shiftL` 8) .|. (fromIntegral zl :: Int16)+    let y = ((fromIntegral yh :: Int16) `shiftL` 8) .|. (fromIntegral yl :: Int16)+    print $ (show x) ++ ":" ++ (show y) ++ ":" ++ (show z)+      +    threadDelay $ 500 * 1000+    +  fdClose fd+
+ demo/PWM.hs view
@@ -0,0 +1,30 @@+import Control.Monad(forM_)+import Control.Concurrent(threadDelay)+import System.PIO.Linux.PWM(setValue)++{--+Connection for Intel Edison++$ sh/setup_pwm.sh 0 1 13++[J18- 1] == ++[J19- 3] == -++--}+++test = do++  forM_ [0..9] $ \_ -> do+    +    setValue 1 200000 200000+    threadDelay $ 500 * 1000+    +    setValue 1 200000 50000+    threadDelay $ 500 * 1000++  ++-- setValue 1 20000000 320000+-- setValue 1 20000000 1300000+-- setValue 1 20000000 2352000
+ demo/SPI.hs view
@@ -0,0 +1,128 @@+import Data.Word(Word8,Word16)+import Data.Bits((.|.),(.&.),shiftL,shiftR)+import Foreign.Marshal.Array(withArrayLen,peekArray)+import Control.Monad(forM_)+import Control.Concurrent(threadDelay)++import System.PIO(binToNum)+import System.PIO.Linux(fdOpen,IOMode(ReadWriteMode),fdClose)+import System.PIO.Linux.SPI.Raw+++{--++Connection for Intel Edison++$ sh/setup_spi.sh 5 1 109 114 115 111++[J17-10] == SS+[J17-11] == SCLK+[J17-12] == MOSI+[J18-11] == MISO+[J19- 2] == VDD+[J19- 3] == GND++--}+++bin :: String -> Word8+bin = binToNum+++demoSetting :: IO ()+demoSetting = do++  fd <- fdOpen "/dev/spidev5.1" ReadWriteMode+  +  print . fromEnum =<< getMode fd+  +  setMode fd Mode1+  print . fromEnum =<< getMode fd+  +  setMode fd Mode2+  print . fromEnum =<< getMode fd+  +  setMode fd Mode3+  print . fromEnum =<< getMode fd+  +  setMode fd Mode0+  print . fromEnum =<< getMode fd+  +  +  print =<< getLsbFirst fd+  +--  setLsbFirst fd True+--  print =<< getLsbFirst fd+  +  setLsbFirst fd False+  print =<< getLsbFirst fd++  +  print =<< getBitsPerWord fd+  +  setBitsPerWord fd 7+  print =<< getBitsPerWord fd+  +  setBitsPerWord fd 8+  print =<< getBitsPerWord fd+  +  setBitsPerWord fd 10+  print =<< getBitsPerWord fd++  setBitsPerWord fd 20+  print =<< getBitsPerWord fd+++  print =<< getMaxSpeedHz fd+  +  setMaxSpeedHz fd 7000+  print =<< getMaxSpeedHz fd+  +  setMaxSpeedHz fd 8000+  print =<< getMaxSpeedHz fd+  +  setMaxSpeedHz fd 9100+  print =<< getMaxSpeedHz fd+  +  setMaxSpeedHz fd 1000000+  print =<< getMaxSpeedHz fd+  ++  fdClose fd++++demoTransferTxRx1 :: IO ()+demoTransferTxRx1 = do+  +  let bits = 8+  let speed = 1000000+  let ch = 0+  +  fd <- fdOpen "/dev/spidev5.1" ReadWriteMode+  +  setMode fd Mode0+  setBitsPerWord fd bits+  setMaxSpeedHz fd speed++  forM_ [0..99] $ \_ -> do+    +    let dt0 = bin "1100000" .|. (ch `shiftL` 4)+    let dt1 = 0+    dt0':dt1':_ <- withArrayLen [dt0,dt1] $+      \len p -> transferTxRx1 fd p len bits speed 0 False >> peekArray len p+      +    let v = ((fromIntegral (dt0' .&. bin "11") :: Word16) `shiftL` 8) .|. (fromIntegral dt1' :: Word16)+    print v+      +    threadDelay $ 500 * 1000++  fdClose fd++++dt0'' ch = bin "00000110" .|. ( (bin "0100" .&. ch) `shiftR` 2)+dt1'' ch = bin "00000000" .|. ( (bin "0011" .&. ch) `shiftL` 6)++    +
huckleberry.cabal view
@@ -1,5 +1,5 @@ name:                huckleberry-version:             0.10.0.0+version:             0.10.0.1 synopsis:            Haskell IOT on Intel Edison and other Linux computers. description:         Please see README.md homepage:            https://github.com/mitsuji/huckleberry#readme@@ -12,9 +12,21 @@ build-type:          Simple cabal-version:       >=1.10 extra-source-files:+  README.md   include/hs_fcntl.h   include/hs_i2c.h   include/hs_spi.h+  include/hs_spi.h+  sh/setup_in.sh+  sh/setup_out.sh+  sh/setup_pwm.sh+  sh/setup_i2c.sh+  sh/setup_spi.sh+  demo/GpioIn.hs+  demo/GpioOut.hs+  demo/PWM.hs+  demo/I2C.hs+  demo/SPI.hs  library   hs-source-dirs:      src
+ sh/setup_i2c.sh view
@@ -0,0 +1,14 @@+#!/bin/sh++if [ "$#" -ne 3 ]+then+    echo "Usage: setup_i2c.sh [Adapter Number] [SCL] [SDA]"+    echo "ex) setup_i2c.sh 6 27 28"+    exit 1+fi++sh -c "echo mode1 > /sys/kernel/debug/gpio_debug/gpio$2/current_pinmux"+sh -c "echo mode1 > /sys/kernel/debug/gpio_debug/gpio$3/current_pinmux"+sh -c "chmod 666 /dev/i2c-$1"++
+ sh/setup_in.sh view
@@ -0,0 +1,14 @@+#!/bin/sh++if [ "$#" -ne 1 ]+then+    echo "Usage: setup_in.sh [GPIO]"+    echo "ex) setup_in.sh 78"+    exit 1+fi++sh -c "echo mode0 > /sys/kernel/debug/gpio_debug/gpio$1/current_pinmux"+sh -c "echo $1    > /sys/class/gpio/export"+sh -c "echo in    > /sys/class/gpio/gpio$1/direction"+sh -c "chmod 666 /sys/class/gpio/gpio$1/value"+
+ sh/setup_out.sh view
@@ -0,0 +1,14 @@+#!/bin/sh++if [ "$#" -ne 1 ]+then+    echo "Usage: setup_out.sh [GPIO]"+    echo "ex) setup_out.sh 78"+    exit 1+fi++sh -c "echo mode0 > /sys/kernel/debug/gpio_debug/gpio$1/current_pinmux"+sh -c "echo $1    > /sys/class/gpio/export"+sh -c "echo out   > /sys/class/gpio/gpio$1/direction"+sh -c "chmod 666 /sys/class/gpio/gpio$1/value"+
+ sh/setup_pwm.sh view
@@ -0,0 +1,19 @@+#!/bin/sh++if [ "$#" -ne 3 ]+then+    echo "Usage: setup_pwm.sh [Chip Number] [Channel Number] [GPIO]"+    echo "ex) setup_pwm.sh 0 0 182"+    exit 1+fi+++sh -c "echo mode1 > /sys/kernel/debug/gpio_debug/gpio$3/current_pinmux"+sh -c "echo $2    > /sys/class/pwm/pwmchip$1/export"+sh -c "chmod 666 /sys/class/pwm/pwmchip$1/pwm$2/enable"+sh -c "chmod 666 /sys/class/pwm/pwmchip$1/pwm$2/period"+sh -c "chmod 666 /sys/class/pwm/pwmchip$1/pwm$2/duty_cycle"+sh -c "echo 1 > /sys/class/pwm/pwmchip$1/pwm$2/enable"+++
+ sh/setup_spi.sh view
@@ -0,0 +1,15 @@+#!/bin/sh++if [ "$#" -ne 6 ]+then+    echo "Usage: setup_spi.sh [Bus Number] [ChipSelect Number] [CLK] [MOSI] [MISO] [SS]"+    echo "ex) setup_spi.sh 5 1 109 114 115 111"+    exit 1+fi++sh -c "echo mode1 > /sys/kernel/debug/gpio_debug/gpio$3/current_pinmux"+sh -c "echo mode1 > /sys/kernel/debug/gpio_debug/gpio$4/current_pinmux"+sh -c "echo mode1 > /sys/kernel/debug/gpio_debug/gpio$5/current_pinmux"+sh -c "echo mode1 > /sys/kernel/debug/gpio_debug/gpio$6/current_pinmux"+sh -c "chmod 666 /dev/spidev$1.$2"+