Skip to content
This repository has been archived by the owner on Nov 28, 2018. It is now read-only.

Commit

Permalink
Merge pull request #7 from ruuns/master
Browse files Browse the repository at this point in the history
Add support for setting AutoExposure/AutoWhiteBalance/RawColor and Mirro...
  • Loading branch information
chrisdone committed Sep 25, 2014
2 parents ac0b92b + 9191543 commit 966bef2
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/Freenect.hs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ module Freenect
,setLed
,setVideoMode
,setDepthMode
,setFlag
,Context
,Device
,FreenectException(..)
,Subdevice(..)
,LogLevel(..)
,Led(..)
,Flag(..)
,Resolution(..)
,VideoFormat(..)
,DepthFormat(..))
Expand Down Expand Up @@ -92,6 +94,7 @@ data FreenectException
| StartDepthProblem -- ^ Problem starting the depth stream.
| UnableToSetTilt -- ^ Unable to set the tilt.
| UnableToSetLed -- ^ Unable to set active led
| UnableToSetFlag -- ^ Failed to enable a specific device flag
| SetVideoMode -- ^ Unable to set the video mode.
| VideoModeNotSet -- ^ TODO, not used: You didn't set the video mode.
| SetDepthMode -- ^ Unable to set the depth mode.
Expand Down Expand Up @@ -344,6 +347,32 @@ setLed d led = flip withD d $ \ptr -> do



data Flag
= AutoExposure
| AutoWhiteBalance
| RawColor
| MirrorDepth
| MirrorVideo
deriving(Show,Eq)

-- | Sets a specific device flag for depth and video cameras. The
-- bool value defines to enable or disable the given flag. The specific camera
-- has to be started with startVideo/startDepth before Freenect accepts
-- these flags (seems to be a small bug for me, an issue is written at libfreenect)
setFlag :: Device -> Flag -> Bool -> IO ()
setFlag d flag enabled = flip withD d $ \ptr -> do
ptr <- peek ptr
succeed UnableToSetFlag (return ()) $
freenect_set_flag ptr key value
where
key = toEnumInteger flag
value = fromIntegral (if enabled then 1 else 0)

toEnumInteger AutoExposure = 1 `shift` 14
toEnumInteger AutoWhiteBalance = 1 `shift` 1
toEnumInteger RawColor = 1 `shift` 4
toEnumInteger MirrorDepth = 1 `shift` 16
toEnumInteger MirrorVideo = 1 `shift` 17
-- $contexts
--
-- First you need to initalize a context. Example:
Expand Down
6 changes: 6 additions & 0 deletions src/Freenect/FFI.hs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ foreign import ccall
foreign import ccall
"freenect.h freenect_set_led"
freenect_set_led :: Ptr DeviceStruct -> CInt -> IO CInt


foreign import ccall
"freenect.h freenect_set_flag"
freenect_set_flag :: Ptr DeviceStruct -> CInt -> CInt -> IO CInt

--------------------------------------------------------------------------------
-- Helpers.

Expand Down

0 comments on commit 966bef2

Please sign in to comment.