Module: Freenect::Sync

Defined in:
lib/freenect/sync.rb

Defined Under Namespace

Classes: FormatError

Class Method Summary collapse

Class Method Details

.get_depth(idx = 0, fmt = :depth_11bit) ⇒ Numeric, String

Synchronous depth function (starts the runloop if it isn’t running)

Raises:

  • FormatError An exception is raised if an invalid format is specified.

  • RuntimeError An exception is raised if an unknown error occurs in the freenect_sync_get_video function



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/freenect/sync.rb', line 67

def self.get_depth(idx=0, fmt=:depth_11bit)
  idx ||= 0
  fmt ||= :depth_11bit

  if (buf_size = Freenect.lookup_depth_size(fmt)).nil?
    raise(FormatError, "Invalid depth format: #{fmt.inspect}")
  end

  depth_p = FFI::MemoryPointer.new(buf_size)
  timestamp_p = FFI::MemoryPointer.new(:uint32)

  ret = ::FFI::Freenect.freenect_sync_get_depth(depth_p, timestamp_p, idx, Freenect.lookup_depth_format(fmt))
  if ret != 0
    raise("Unknown error in freenect_sync_get_depth()") # TODO is errno set or something here?
  else
    return [timestamp_p.read_int, video_p.read_string_length(buf_size)]
  end
end

.get_video(idx = nil, fmt = nil) ⇒ Numeric, String

Synchronous video function (starts the runloop if it isn’t running)

Raises:

  • FormatError An exception is raised if an invalid format is specified.

  • RuntimeError An exception is raised if an unknown error occurs in the freenect_sync_get_video function



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/freenect/sync.rb', line 28

def self.get_video(idx=nil, fmt=nil)
  idx ||= 0
  fmt ||= :rgb

  if (buf_size = Freenect.lookup_video_size(fmt)).nil?
    raise(FormatError, "Invalid video format: #{fmt.inspect}")
  end

  video_p = FFI::MemoryPointer.new(buf_size)
  timestamp_p = FFI::MemoryPointer.new(:uint32)

  ret = ::FFI::Freenect.freenect_sync_get_video(video_p, timestamp_p, idx, Freenect.lookup_video_format(fmt))

  if ret != 0
    raise("Unknown error in freenect_sync_get_video()") # TODO is errno set or something here?
  else
    return [timestamp_p.read_int, video_p.read_string_length(buf_size)]
  end
end

.stopObject

Stops the sync runloop



87
88
89
# File 'lib/freenect/sync.rb', line 87

def self.stop
  FFI::Freenect.freenect_sync_stop()
end