Skip to content

Commit b674a8a

Browse files
algrszarvox
authored andcommitted
wappers/ruby: Updated to use new frame mode code.
Signed-off-by: Alex Weiss <[email protected]>
1 parent e79d08c commit b674a8a

File tree

2 files changed

+35
-38
lines changed

2 files changed

+35
-38
lines changed

wrappers/ruby/ffi-libfreenect/lib/freenect/device.rb

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -132,39 +132,35 @@ def stop_video
132132
end
133133
end
134134

135-
def set_depth_format(fmt)
136-
l_fmt = fmt.is_a?(Numeric)? fmt : Freenect::DEPTH_FORMATS[fmt]
137-
ret = ::FFI::Freenect.freenect_set_depth_format(self.device, l_fmt)
138-
if (ret== 0)
139-
@depth_format = fmt
140-
else
141-
raise DeviceError, "Error calling freenect_set_depth_format(self, #{fmt})"
142-
end
143-
end
144-
145-
alias depth_format= set_depth_format
146-
135+
def set_depth_mode(mode)
136+
mode = Freenect.depth_mode(:medium, mode) unless mode.is_a?(Freenect::FrameMode)
137+
raise ArgumentError, "Unkown depth mode #{mode}" if mode.nil?
138+
ret = ::FFI::Freenect.freenect_set_depth_mode(self.device, mode)
139+
raise DeviceError, "Error calling freenect_set_depth_mode(self, #{mode})" unless ret == 0
140+
end
141+
alias depth_mode= set_depth_mode
142+
147143
# returns the symbolic constant for the current depth format
148-
def depth_format
149-
(@depth_format.is_a?(Numeric))? Freenect::DEPTH_FORMATS[@depth_format] : @depth_format
144+
def depth_mode
145+
x = ::FFI::Freenect.freenect_get_current_depth_mode(self.device)
146+
x.frame_mode_type = :depth unless x.nil?
147+
x
150148
end
151149

152150
# Sets the video format to one of the following accepted values:
153151
#
154-
def set_video_format(fmt)
155-
l_fmt = fmt.is_a?(Numeric)? fmt : Freenect::VIDEO_FORMATS[fmt]
156-
ret = ::FFI::Freenect.freenect_set_video_format(self.device, l_fmt)
157-
if (ret== 0)
158-
@video_format = fmt
159-
else
160-
raise DeviceError, "Error calling freenect_set_video_format(self, #{fmt})"
161-
end
162-
end
163-
164-
alias video_format= set_video_format
165-
166-
def video_format
167-
(@video_format.is_a?(Numeric))? ::Freenect::VIDEO_FORMATS[@video_format] : @video_format
152+
def set_video_mode(mode)
153+
mode = Freenect.video_mode(:medium, mode) unless mode.is_a?(Freenect::FrameMode)
154+
raise ArgumentError, "Unkown video mode #{mode}" if mode.nil?
155+
ret = ::FFI::Freenect.freenect_set_video_mode(self.device, mode)
156+
raise DeviceError, "Error calling freenect_set_video_mode(self, #{mode})" unless ret == 0
157+
end
158+
alias video_mode= set_video_mode
159+
160+
def video_mode
161+
x = ::FFI::Freenect.freenect_get_current_video_mode(self.device)
162+
x.frame_mode_type = :video unless x.nil?
163+
x
168164
end
169165

170166
# Sets the led to one of the following accepted values:

wrappers/ruby/ffi-libfreenect/spec/device_spec.rb

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,21 @@
6969
end
7070

7171
it "should allow the video_format to be set and retrieved" do
72-
@dev.video_format.should be_nil # at first
73-
@dev.video_format = :bayer
74-
@dev.video_format.should == :bayer
75-
@dev.video_format = Freenect::VIDEO_RGB
76-
@dev.video_format.should == :rgb
72+
@dev.video_mode.should be_nil # at first
73+
@dev.video_mode = Freenect.video_mode(:medium, :bayer)
74+
@dev.video_mode.format.should == :bayer
75+
@dev.video_mode = Freenect.video_mode(:medium, :rgb)
76+
@dev.video_mode.format.should == :rgb
77+
@dev.video_mode.frame_mode_type.shoud == :video
7778
end
7879

7980

8081
it "should allow the depth_format to be set and retrieved" do
81-
@dev.depth_format.should be_nil # at first
82-
@dev.depth_format = :depth_10bit
83-
@dev.depth_format.should == :depth_10bit
84-
@dev.depth_format = Freenect::DEPTH_11BIT
85-
@dev.depth_format = :depth_11bit
82+
@dev.depth_mode.should be_nil # at first
83+
@dev.depth_mode = :depth_10bit
84+
@dev.depth_mode.should == :depth_10bit
85+
@dev.depth_mode = Freenect::DEPTH_11BIT
86+
@dev.depth_mode = :depth_11bit
8687
end
8788

8889
it "should allow itself to be looked up by it's object reference ID" do

0 commit comments

Comments
 (0)