-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Haskell port of the Emokit EEG project -- @package hemokit @version 0.6.6 module Hemokit.Internal.Utils -- | If the monad retuns a Just, runs the function on its contents. Returns -- True if the action was executed. withJustM :: Monad m => m (Maybe a) -> (a -> m ()) -> m Bool -- | Runs the monadic action as long as the producer returns Justs. Returns -- True if the action was ever executed. untilNothing :: Monad m => m (Maybe a) -> (a -> m ()) -> m Bool -- | Base64-encodes a ByteString as Text. -- -- This cannot fail since Base64 is ASCII. textBase64 :: ByteString -> Text -- | A library for reading from an Emotic EPOC EEG. -- -- module Hemokit -- | The USB vendor ID of the Emotiv EPOC. _EMOTIV_VENDOR_ID :: VendorID -- | The USB product ID of the Emotiv EPOC. _EMOTIV_PRODUCT_ID :: ProductID -- | Identifies an Emotiv device. data EmotivDeviceInfo EmotivDeviceInfo :: DeviceInfo -> EmotivDeviceInfo -- | The hidapi device info. hidapiDeviceInfo :: EmotivDeviceInfo -> DeviceInfo -- | An "open" data source to read bytes from. data EmotivRawDevice HidapiDevice :: Device -> EmotivRawDevice -- | The open hidapi device. hidapiDevice :: EmotivRawDevice -> Device HandleDevice :: Handle -> EmotivRawDevice -- | A conventional Handle, e.g. an open file. handleDevice :: EmotivRawDevice -> Handle -- | Identifies an open Emotiv device. Also contains the cumulative -- EmotivState of the EEG. data EmotivDevice EmotivDevice :: EmotivRawDevice -> SerialNumber -> EmotivModel -> IORef (Maybe EmotivState) -> EmotivDevice -- | Where we get our data from, some form of "open handle". rawDevice :: EmotivDevice -> EmotivRawDevice -- | The EEG's serial. serial :: EmotivDevice -> SerialNumber -- | Whether the EEG is a consumer or developer model. emotivModel :: EmotivDevice -> EmotivModel -- | The EEG's cumulative state. stateRef :: EmotivDevice -> IORef (Maybe EmotivState) -- | Lists all EPOC devices, ordered by interface number. If you do not -- actively choose amongst them, the last one is usually the one you want -- (especially if only 1 EEG is connected). getEmotivDevices :: IO [EmotivDeviceInfo] -- | Opens a given Emotiv device. Returns an EmotivDevice to read -- from with readEmotiv. openEmotivDevice :: EmotivModel -> EmotivDeviceInfo -> IO EmotivDevice -- | Creates an EmotivDevice device from a path, e.g. a device like -- devhidraw1 or a normal file containing dumped binary -- data. openEmotivDeviceFile :: EmotivModel -> SerialNumber -> String -> IO EmotivDevice -- | Creates an EmotivDevice device from an open file handle. openEmotivDeviceHandle :: EmotivModel -> SerialNumber -> Handle -> IO EmotivDevice -- | Reads one 32 byte packet from the device, parses the raw bytes into an -- EmotivPacket and updates the cumulative EmotivState that -- we maintain for that device. -- -- Returns both the packet read from the device and the updated state. -- -- Returns Nothing on end of input (or if there are < 32 bytes before -- it). -- -- Note that if the EEG is (turned) off, this function block until it is -- turned on again. readEmotiv :: EmotivDevice -> IO (Maybe (EmotivState, EmotivPacket)) -- | Emotiv related errors. data EmotivException -- | Serial does not have right format. InvalidSerialNumber :: SerialNumber -> EmotivException -- | We could not read the serial from the device. CouldNotReadSerial :: DevicePath -> EmotivException OtherEmotivException :: String -> EmotivException -- | A valid Emotiv serial number. 16 bytes. data SerialNumber -- | Checks an Emotiv serial, returning a SerialNumber if it's -- valid. makeSerialNumber :: ByteString -> Maybe SerialNumber -- | Like makeSerialNumber, using a String. makeSerialNumberFromString :: String -> Maybe SerialNumber -- | Conveniently expose the serial number of a device. deviceInfoSerial :: EmotivDeviceInfo -> Maybe SerialNumber -- | Whether the EPOC is a consumer or developer model. -- -- This affects how the EEG data is to be decrypted. -- -- You can check if you are using the correct model by seeing if the -- packet counter increases from 0 until 128 on subsequent -- packets. data EmotivModel Consumer :: EmotivModel Developer :: EmotivModel -- | Contains the data of a single packet sent from the device. Accumulated -- data (the current state) is available in EmotivState. data EmotivPacket EmotivPacket :: Int -> Maybe Int -> Int -> Int -> Vector Int -> Maybe (Sensor, Int) -> EmotivPacket -- | counts up from 0 to 127 (128 Hz) packetCounter :: EmotivPacket -> Int -- | the current battery percentage packetBattery :: EmotivPacket -> Maybe Int -- | turning "left" gives positive numbers packetGyroX :: EmotivPacket -> Int -- | turning "down" gives positive numbers packetGyroY :: EmotivPacket -> Int -- | EEG sensor values packetSensors :: EmotivPacket -> Vector Int -- | EEG sensor-to-skin connectivity packetQuality :: EmotivPacket -> Maybe (Sensor, Int) -- | Contains the "current state" of the EEG, cumulateively updated by -- incoming EmotivPackets. data EmotivState EmotivState :: Int -> Int -> Int -> Int -> Vector Int -> Vector Int -> EmotivState -- | counts up from 0 to 127 (128 Hz) counter :: EmotivState -> Int -- | the current battery percentage battery :: EmotivState -> Int -- | turning "left" gives positive numbers gyroX :: EmotivState -> Int -- | turning "down" gives positive numbers gyroY :: EmotivState -> Int -- | EEG sensor values sensors :: EmotivState -> Vector Int -- | EEG sensor-to-skin connectivity qualities :: EmotivState -> Vector Int -- | The sensors of an Emotiv EPOC. Uses the names from the International -- 10-20 system. data Sensor F3 :: Sensor FC5 :: Sensor AF3 :: Sensor F7 :: Sensor T7 :: Sensor P7 :: Sensor O1 :: Sensor O2 :: Sensor P8 :: Sensor T8 :: Sensor F8 :: Sensor AF4 :: Sensor FC6 :: Sensor F4 :: Sensor -- | Contains all Sensors. allSensors :: [Sensor] -- | Wraps (unencrypted) Emotiv raw data. Ensures that it is 32 bytes. newtype EmotivRawData EmotivRawData :: ByteString -> EmotivRawData emotivRawDataBytes :: EmotivRawData -> ByteString -- | Reads one 32 byte packet from the device and decrypts it to raw data. -- -- Returns Nothing on end of input (or if there are < 32 bytes before -- it). -- -- Note that if the EEG is (turned) off, this function block until it is -- turned on again. readEmotivRaw :: EmotivDevice -> IO (Maybe EmotivRawData) -- | Treat a ByteString as Emotiv raw data. Errors if the input is -- non 32 bytes. makeEmotivRawData :: ByteString -> EmotivRawData -- | Parses an EmotivPacket from raw bytes. parsePacket :: EmotivRawData -> EmotivPacket -- | Given a device and a Emotiv raw data, parses the raw data into an -- EmotivPacket and updates the cumulative EmotivState that -- we maintain for that device. -- -- Care should be taken that raw data is fed into this function in the -- right order (e.g. respecting the EEG's increasing sequence numbers and -- quality updates). -- -- This function is only neededif you want to obtain both raw data and -- parsed packages. If you are not interested in raw data, use -- readEmotiv instead. -- -- Returns both the packet read from the device and the updated state. updateEmotivState :: EmotivDevice -> EmotivRawData -> IO (EmotivState, EmotivPacket) -- | Takes a 32 bytes encrypted EEG data, returns 32 bytes decrypted EEG -- data. decrypt :: SerialNumber -> EmotivModel -> ByteString -> EmotivRawData -- | Describes the indices of bits to make up a certain value. newtype BitMask BitMask :: [Word8] -> BitMask -- | Describes which bits in a raw data packet make up the given sensor. getSensorMask :: Sensor -> BitMask -- | Describes which bits in a raw data packat make up a sensor quality -- value. qualityMask :: BitMask -- | Extracts the sensor value for the given sensor from Emotiv raw data. getLevel :: EmotivRawData -> BitMask -> Int -- | Parses a battery percentage value from a byte. batteryValue :: Word8 -> Int -- | Which sensor's quality is transmitted in the packet (depends on first -- byte, the packet counter). qualitySensorFromByte0 :: Word8 -> Maybe Sensor -- | Opens and reads from the last available device, giving all data from -- it to the given function. Stops if end of input is reached. -- -- Intended for use with ghci. -- -- Examples: -- --
--   withDataFromLastEEG Consumer print
--   withDataFromLastEEG Consumer (print . packetQuality . snd)
--   withDataFromLastEEG Consumer (putStrLn . unwords . map show . V.toList . qualities . fst)
--   
withDataFromLastEEG :: EmotivModel -> ((EmotivState, EmotivPacket) -> IO ()) -> IO () instance Typeable EmotivException instance Eq EmotivModel instance Ord EmotivModel instance Show EmotivModel instance Generic EmotivModel instance Eq SerialNumber instance Ord SerialNumber instance Show SerialNumber instance Generic SerialNumber instance Eq Sensor instance Enum Sensor instance Bounded Sensor instance Ord Sensor instance Show Sensor instance Generic Sensor instance Eq BitMask instance Ord BitMask instance Show BitMask instance Eq EmotivPacket instance Ord EmotivPacket instance Show EmotivPacket instance Generic EmotivPacket instance Eq EmotivState instance Ord EmotivState instance Show EmotivState instance Generic EmotivState instance Eq EmotivRawData instance Ord EmotivRawData instance Show EmotivRawData instance Generic EmotivRawData instance Data EmotivException instance Generic EmotivException instance Show EmotivDeviceInfo instance Generic EmotivDeviceInfo instance Generic EmotivRawDevice instance Generic EmotivDevice instance Datatype D1EmotivModel instance Constructor C1_0EmotivModel instance Constructor C1_1EmotivModel instance Datatype D1SerialNumber instance Constructor C1_0SerialNumber instance Datatype D1Sensor instance Constructor C1_0Sensor instance Constructor C1_1Sensor instance Constructor C1_2Sensor instance Constructor C1_3Sensor instance Constructor C1_4Sensor instance Constructor C1_5Sensor instance Constructor C1_6Sensor instance Constructor C1_7Sensor instance Constructor C1_8Sensor instance Constructor C1_9Sensor instance Constructor C1_10Sensor instance Constructor C1_11Sensor instance Constructor C1_12Sensor instance Constructor C1_13Sensor instance Datatype D1EmotivPacket instance Constructor C1_0EmotivPacket instance Selector S1_0_0EmotivPacket instance Selector S1_0_1EmotivPacket instance Selector S1_0_2EmotivPacket instance Selector S1_0_3EmotivPacket instance Selector S1_0_4EmotivPacket instance Selector S1_0_5EmotivPacket instance Datatype D1EmotivState instance Constructor C1_0EmotivState instance Selector S1_0_0EmotivState instance Selector S1_0_1EmotivState instance Selector S1_0_2EmotivState instance Selector S1_0_3EmotivState instance Selector S1_0_4EmotivState instance Selector S1_0_5EmotivState instance Datatype D1EmotivRawData instance Constructor C1_0EmotivRawData instance Selector S1_0_0EmotivRawData instance Datatype D1EmotivException instance Constructor C1_0EmotivException instance Constructor C1_1EmotivException instance Constructor C1_2EmotivException instance Datatype D1EmotivDeviceInfo instance Constructor C1_0EmotivDeviceInfo instance Selector S1_0_0EmotivDeviceInfo instance Datatype D1EmotivRawDevice instance Constructor C1_0EmotivRawDevice instance Constructor C1_1EmotivRawDevice instance Selector S1_0_0EmotivRawDevice instance Selector S1_1_0EmotivRawDevice instance Datatype D1EmotivDevice instance Constructor C1_0EmotivDevice instance Selector S1_0_0EmotivDevice instance Selector S1_0_1EmotivDevice instance Selector S1_0_2EmotivDevice instance Selector S1_0_3EmotivDevice instance NFData Sensor instance NFData EmotivState instance NFData EmotivRawData instance NFData EmotivPacket instance NFData EmotivException instance NFData EmotivDeviceInfo instance Show EmotivException instance Exception EmotivException module Hemokit.Conduit rawSource :: MonadIO m => EmotivDevice -> Source m EmotivRawData parsePackets :: MonadIO m => EmotivDevice -> Conduit EmotivRawData m (EmotivState, EmotivPacket) emotivStates :: MonadIO m => EmotivDevice -> Source m EmotivState emotivPackets :: MonadIO m => EmotivDevice -> Source m EmotivPacket jsonConduit :: (Monad m, ToJSON i) => Conduit i m ByteString tcpSink :: MonadIO m => String -> Int -> Sink ByteString m () websocketSink :: MonadIO m => String -> Int -> Sink ByteString m () -- | Some convenience for building applications that want to read Emotiv -- data. -- -- You can use this if you are writing an EEG application and don't want -- to do the whole device selection / opening yourself. module Hemokit.Start -- | Commonly used options for EEG command line applications. Mainly deals -- with input selection. data EmotivArgs EmotivArgs :: EmotivModel -> Maybe SerialNumber -> Maybe FilePath -> EmotivArgs -- | What model to use for decryption. model :: EmotivArgs -> EmotivModel -- | What serial to use for decryption. Also allows to pick a certain -- device. serial :: EmotivArgs -> Maybe SerialNumber -- | Use the given device or dump file for input. If not given, HIDAPI is -- used. fromFile :: EmotivArgs -> Maybe FilePath -- | Command line parser for EEG selection. See EmotivArgs. emotivArgsParser :: Parser EmotivArgs -- | EEG model command line parser. parseModel :: Monad m => String -> m EmotivModel -- | Runs a command line parser. The given program description is used for -- the --help message. parseArgs :: String -> Parser a -> IO a -- | Depending on some common EEG-choice-related user input, list devices -- or try to open the correct device. getEmotivDeviceFromArgs :: EmotivArgs -> IO (Either String EmotivDevice) instance Eq EmotivArgs instance Ord EmotivArgs instance Show EmotivArgs