samuelpowell / Spinnaker.jl

A Julia interface to the FLIR/PointGrey Spinnaker SDK
MIT License
16 stars 7 forks source link

Allow for 2 chunk naming regimes (fixes #28) #39

Closed IanButterworth closed 5 years ago

IanButterworth commented 5 years ago

fixes #28

samuelpowell commented 5 years ago

For the purposes of readability, could you split the try catch groups out over each parameter (un-nest them). I appreciate it is more verbose, but will make it clearer what's going on.

samuelpowell commented 5 years ago

I've messed up my repo.... could we try this instead (works locally)

mutable struct Camera
  handle::spinCamera

  function Camera(handle)
    @assert spinsys.handle != C_NULL
    @assert handle != C_NULL
    spinCameraDeInit(handle)
    spinCameraInit(handle)
    cam = new(handle)
    finalizer(_release!, cam)
    # Activate chunk mode
    set!(SpinBooleanNode(cam, "ChunkModeActive"), true)
    _chunkselect(cam, ["FrameID", "FrameCounter"], "frame indentification")
    _chunkselect(cam, ["ExposureTime"], "exposure time")
    _chunkselect(cam, ["Timestamp"], "timestamps")
    return cam
  end
end

# Attempt to activate chunk data for each entry in chunknames
# - this allows chunk names to differ on cameras
function _chunkselect(cam::Camera, chunknames::Vector{String}, desc::String)

  fail = true
  while fail == true
    try 
      fail = false
      set!(SpinEnumNode(cam, "ChunkSelector"), "FrameID")
      set!(SpinBooleanNode(cam, "ChunkEnable"), true)
    catch e
      fail = true
    end
  end

  if fail
    @warn "Unable to enable chunk data for $(desc), tried $(chunknames), metadata may be incorrect"
  end

end