hArduino 0.9 → 1.0
raw patch · 19 files changed
+84/−28 lines, 19 filessetup-changed
Files
- CHANGES.md +15/−1
- README.md +1/−1
- Setup.hs +16/−0
- System/Hardware/Arduino/Comm.hs +1/−1
- System/Hardware/Arduino/Data.hs +18/−8
- System/Hardware/Arduino/Protocol.hs +17/−1
- System/Hardware/Arduino/SamplePrograms/Analog.hs +1/−1
- System/Hardware/Arduino/SamplePrograms/Blink.hs +1/−1
- System/Hardware/Arduino/SamplePrograms/Button.hs +1/−1
- System/Hardware/Arduino/SamplePrograms/Counter.hs +1/−1
- System/Hardware/Arduino/SamplePrograms/Distance.hs +2/−2
- System/Hardware/Arduino/SamplePrograms/JingleBells.hs +1/−1
- System/Hardware/Arduino/SamplePrograms/LCD.hs +1/−1
- System/Hardware/Arduino/SamplePrograms/Morse.hs +1/−1
- System/Hardware/Arduino/SamplePrograms/NumGuess.hs +1/−1
- System/Hardware/Arduino/SamplePrograms/Pulse.hs +2/−2
- System/Hardware/Arduino/SamplePrograms/Servo.hs +2/−2
- System/Hardware/Arduino/SamplePrograms/SevenSegment.hs +1/−1
- hArduino.cabal +1/−1
CHANGES.md view
@@ -1,7 +1,21 @@ * Hackage: (http://hackage.haskell.org/package/hArduino) * GitHub: (http://leventerkok.github.com/hArduino) -* Latest Hackage released version: 0.9+* Latest Hackage released version: 1.0++### Version 1.0, 2016-03-27+ * Unfortunately the Firmata project moved on, and hArduino no longer+ works with the latest release of StandardFirmata. This release mainly+ makes a note of this fact, and points to an older version of StandardFirmata+ that hArduino has been tested against. Volunteers encouraged to+ contribute to bring hArduino up-to-date: Contact me if interested!++ * Make the pin-capabilities code robust, by explicitly catching+ (and ignoring) capabilities we do not know/care about. Previously+ we were simply using toEnum, which choked with new versions+ of Firmata as they added new options. Thanks to Can Akcura on+ Github for pointing out the issue.+ ### Version 0.9, 2014-02-09 * Added example program for Morse encoding.
README.md view
@@ -1,1 +1,1 @@-Please see http://leventerkok.github.com/hArduino.+Please see http://leventerkok.github.io/hArduino.
Setup.hs view
@@ -1,2 +1,18 @@+-----------------------------------------------------------------------------+-- |+-- Module : Main+-- Copyright : (c) Levent Erkok+-- License : BSD3+-- Maintainer : erkokl@gmail.com+-- Stability : experimental+--+-- Setup module for the hArduino library+-----------------------------------------------------------------------------++{-# OPTIONS_GHC -Wall #-}+module Main(main) where+ import Distribution.Simple++main :: IO () main = defaultMain
System/Hardware/Arduino/Comm.hs view
@@ -37,7 +37,7 @@ -- -- * The file path argument should point to the device file that is -- associated with the board. ('COM1' on Windows,--- '/dev/cu.usbmodemfd131' on Mac, etc.)+-- '/dev/cu.usbmodemFD131' on Mac, etc.) -- -- * The boolean argument controls verbosity. It should remain -- 'False' unless you have communication issues. The print-out
System/Hardware/Arduino/Data.hs view
@@ -14,7 +14,6 @@ {-# LANGUAGE RankNTypes #-} module System.Hardware.Arduino.Data where -import Control.Applicative (Applicative) import Control.Concurrent (Chan, MVar, modifyMVar, modifyMVar_, withMVar, ThreadId) import Control.Monad (when) import Control.Monad.State (StateT, MonadIO, MonadState, gets, liftIO)@@ -34,6 +33,7 @@ } deriving (Eq, Ord) +-- | Show instance for Port instance Show Port where show p = "Port" ++ show (portNo p) @@ -42,6 +42,7 @@ | AnalogPin {userPinNo :: Word8} | MixedPin {userPinNo :: Word8} +-- | Show instance for Pin instance Show Pin where show (DigitalPin w) = "DPin" ++ show w show (AnalogPin w) = "APin" ++ show w@@ -51,6 +52,7 @@ data IPin = InternalPin { pinNo :: Word8 } deriving (Eq, Ord) +-- | Show instance for IPin instance Show IPin where show (InternalPin w) = "IPin" ++ show w @@ -92,13 +94,19 @@ pinPortIndex p = pinNo p `rem` 8 -- | The mode for a pin.-data PinMode = INPUT -- ^ Digital input- | OUTPUT -- ^ Digital output- | ANALOG -- ^ Analog input- | PWM -- ^ PWM (Pulse-Width-Modulation) output - | SERVO -- ^ Servo Motor controller- | SHIFT -- ^ Shift controller- | I2C -- ^ I2C (Inter-Integrated-Circuit) connection+data PinMode = INPUT -- ^ Digital input+ | OUTPUT -- ^ Digital output+ | ANALOG -- ^ Analog input+ | PWM -- ^ PWM (Pulse-Width-Modulation) output + | SERVO -- ^ Servo Motor controller+ | SHIFT -- ^ Shift controller+ | I2C -- ^ I2C (Inter-Integrated-Circuit) connection+ | ONEWIRE -- ^ NB. No explicit support+ | STEPPER -- ^ NB. No explicit support+ | ENCODER -- ^ NB. No explicit support+ | SERIAL -- ^ NB. No explicit support+ | PULLUP -- ^ NB. No explicit support+ | UNSUPPORTED -- ^ A mode we do not understand or support deriving (Eq, Show, Enum) -- | A request, as sent to Arduino@@ -124,6 +132,7 @@ | PulseResponse IPin Word32 -- ^ Repsonse to a PulseInCommand | Unimplemented (Maybe String) [Word8] -- ^ Represents messages currently unsupported +-- | Show instance for Response instance Show Response where show (Firmware majV minV n) = "Firmware v" ++ show majV ++ "." ++ show minV ++ " (" ++ n ++ ")" show (Capabilities b) = "Capabilities:\n" ++ show b@@ -146,6 +155,7 @@ -- | What the board is capable of and current settings newtype BoardCapabilities = BoardCapabilities (M.Map IPin PinCapabilities) +-- | Show instance for BoardCapabilities instance Show BoardCapabilities where show (BoardCapabilities m) = intercalate "\n" (map sh (M.toAscList m)) where sh (p, PinCapabilities{analogPinNumber, allowedModes}) = show p ++ sep ++ unwords [show md | (md, _) <- allowedModes]
System/Hardware/Arduino/Protocol.hs view
@@ -66,8 +66,24 @@ ([], []) -> [] (cur, 0x7f:rest) -> cur : chunk rest _ -> [xs]- pinCaps (x:y:rest) = (toEnum (fromIntegral x), y) : pinCaps rest+ pinCaps (x:y:rest) = (findMode (fromIntegral x), y) : pinCaps rest pinCaps _ = []++ -- Code defensively against capabilities we do not know+ findMode :: Int -> PinMode+ findMode 0 = INPUT+ findMode 1 = OUTPUT+ findMode 2 = ANALOG+ findMode 3 = PWM+ findMode 4 = SERVO+ findMode 5 = SHIFT+ findMode 6 = I2C+ findMode 7 = ONEWIRE+ findMode 8 = STEPPER+ findMode 9 = ENCODER+ findMode 10 = SERIAL+ findMode 11 = PULLUP+ findMode _ = UNSUPPORTED -- | Unpackage a Non-SysEx response unpackageNonSysEx :: (Int -> IO [Word8]) -> FirmataCmd -> IO Response
System/Hardware/Arduino/SamplePrograms/Analog.hs view
@@ -26,7 +26,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Analog.png>> analogVal :: IO ()-analogVal = withArduino False "/dev/cu.usbmodemfd131" $ do+analogVal = withArduino False "/dev/cu.usbmodemFD131" $ do setPinMode led OUTPUT setPinMode pot ANALOG cur <- analogRead pot
System/Hardware/Arduino/SamplePrograms/Blink.hs view
@@ -24,7 +24,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Blink.png>> blink :: IO ()-blink = withArduino False "/dev/cu.usbmodemfd131" $ do+blink = withArduino False "/dev/cu.usbmodemFD131" $ do let led = digital 13 setPinMode led OUTPUT forever $ do digitalWrite led True
System/Hardware/Arduino/SamplePrograms/Button.hs view
@@ -27,7 +27,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Button.png>> button :: IO ()-button = withArduino False "/dev/cu.usbmodemfd131" $ do+button = withArduino False "/dev/cu.usbmodemFD131" $ do setPinMode led OUTPUT setPinMode pb INPUT go =<< digitalRead pb
System/Hardware/Arduino/SamplePrograms/Counter.hs view
@@ -26,7 +26,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Counter.png>> counter :: IO ()-counter = withArduino False "/dev/cu.usbmodemfd131" $ do+counter = withArduino False "/dev/cu.usbmodemFD131" $ do setPinMode led OUTPUT setPinMode bUp INPUT setPinMode bDown INPUT
System/Hardware/Arduino/SamplePrograms/Distance.hs view
@@ -28,7 +28,7 @@ import System.Hardware.Arduino --- | Sound travels 343.2 meters per seconds (<http://en.wikipedia.org/wiki/Speed_of_sound>).+-- | Sound travels 343.2 meters per second (<http://en.wikipedia.org/wiki/Speed_of_sound>). -- The echo time is round-trip, from the sensor to the object and back. Thus, if echo is high -- for @d@ microseconds, then the distance in centimeters is: --@@ -48,7 +48,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Distance.png>> distance :: IO ()-distance = withArduino False "/dev/cu.usbmodemfd131" $ do+distance = withArduino False "/dev/cu.usbmodemFD131" $ do setPinMode sensor INPUT setPinMode led OUTPUT update
System/Hardware/Arduino/SamplePrograms/JingleBells.hs view
@@ -38,6 +38,6 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Piezo.png>> main :: IO ()-main = withArduino False "/dev/cu.usbmodemfd131" $ do+main = withArduino False "/dev/cu.usbmodemFD131" $ do pz <- speaker 75 (pin 3) playNotes pz jingleBells
System/Hardware/Arduino/SamplePrograms/LCD.hs view
@@ -91,7 +91,7 @@ -- we read from the user and demonstrate other LCD control features offered -- by hArduino. lcdDemo :: IO ()-lcdDemo = withArduino False "/dev/cu.usbmodemfd131" $ do+lcdDemo = withArduino False "/dev/cu.usbmodemFD131" $ do lcd <- lcdRegister hitachi happySymbol <- lcdCreateSymbol lcd happy sadSymbol <- lcdCreateSymbol lcd sad
System/Hardware/Arduino/SamplePrograms/Morse.hs view
@@ -69,7 +69,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Blink.png>> morseDemo :: IO ()-morseDemo = withArduino False "/dev/cu.usbmodemfd131" $ do+morseDemo = withArduino False "/dev/cu.usbmodemFD131" $ do setPinMode led OUTPUT forever send where led = digital 13
System/Hardware/Arduino/SamplePrograms/NumGuess.hs view
@@ -117,6 +117,6 @@ -- | Entry to the classing number guessing game. Simply initialize the -- shield and call our game function. guessGame :: IO ()-guessGame = withArduino False "/dev/cu.usbmodemfd131" $ do+guessGame = withArduino False "/dev/cu.usbmodemFD131" $ do (lcd, light, readButton) <- initOSepp numGuess lcd light readButton
System/Hardware/Arduino/SamplePrograms/Pulse.hs view
@@ -32,7 +32,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/PulseIn.png>> pulseInDemo :: IO ()-pulseInDemo = withArduino False "/dev/cu.usbmodemfd131" $ do+pulseInDemo = withArduino False "/dev/cu.usbmodemFD131" $ do setPinMode pb INPUT go where pb = digital 2@@ -55,7 +55,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Blink.png>> pulseOutDemo :: IO ()-pulseOutDemo = withArduino False "/dev/cu.usbmodemfd131" $ do+pulseOutDemo = withArduino False "/dev/cu.usbmodemFD131" $ do setPinMode led OUTPUT digitalWrite led False forever trigger
System/Hardware/Arduino/SamplePrograms/Servo.hs view
@@ -35,7 +35,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/Servo.png>> servo :: IO ()-servo = withArduino False "/dev/cu.usbmodemfd131" $ do+servo = withArduino False "/dev/cu.usbmodemFD131" $ do s <- attach (digital 9) (Just 600) (Just 2400) forever (demo s) where demo s = do liftIO $ putStr "Enter l, r or the desired servo angle: "@@ -54,7 +54,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/ServoAnalog.png>> servoAnalog :: IO ()-servoAnalog = withArduino False "/dev/cu.usbmodemfd131" $ do+servoAnalog = withArduino False "/dev/cu.usbmodemFD131" $ do s <- attach (digital 9) (Just 600) (Just 2400) setPinMode pot ANALOG liftIO $ putStrLn "Adjust the potentiometer to control the servo!"
System/Hardware/Arduino/SamplePrograms/SevenSegment.hs view
@@ -54,7 +54,7 @@ -- -- <<http://github.com/LeventErkok/hArduino/raw/master/System/Hardware/Arduino/SamplePrograms/Schematics/SevenSegment.png>> sevenSegment :: IO ()-sevenSegment = withArduino False "/dev/cu.usbmodemfd131" $ do+sevenSegment = withArduino False "/dev/cu.usbmodemFD131" $ do initialize sr liftIO $ do hSetBuffering stdin NoBuffering putStrLn "Seven-Segment-Display demo."
hArduino.cabal view
@@ -1,5 +1,5 @@ Name: hArduino-Version: 0.9+Version: 1.0 Category: Hardware Synopsis: Control your Arduino board from Haskell. Description: hArduino allows Haskell programs to control Arduino boards (<http://www.arduino.cc>)