ffi-gphoto2 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +90 -0
- data/Rakefile +6 -0
- data/examples/intervalometer.rb +12 -0
- data/examples/live_view.rb +21 -0
- data/ffi-gphoto2.gemspec +30 -0
- data/lib/ffi/gphoto2.rb +85 -0
- data/lib/ffi/gphoto2/camera.rb +12 -0
- data/lib/ffi/gphoto2/camera_abilities.rb +37 -0
- data/lib/ffi/gphoto2/camera_abilities_list.rb +15 -0
- data/lib/ffi/gphoto2/camera_capture_type.rb +8 -0
- data/lib/ffi/gphoto2/camera_driver_status.rb +9 -0
- data/lib/ffi/gphoto2/camera_event_type.rb +10 -0
- data/lib/ffi/gphoto2/camera_file.rb +28 -0
- data/lib/ffi/gphoto2/camera_file_access_type.rb +8 -0
- data/lib/ffi/gphoto2/camera_file_operation.rb +11 -0
- data/lib/ffi/gphoto2/camera_file_path.rb +9 -0
- data/lib/ffi/gphoto2/camera_file_type.rb +11 -0
- data/lib/ffi/gphoto2/camera_folder_operation.rb +10 -0
- data/lib/ffi/gphoto2/camera_list.rb +15 -0
- data/lib/ffi/gphoto2/camera_operation.rb +12 -0
- data/lib/ffi/gphoto2/camera_widget.rb +33 -0
- data/lib/ffi/gphoto2/camera_widget_type.rb +14 -0
- data/lib/ffi/gphoto2/entry.rb +9 -0
- data/lib/ffi/gphoto2/gp_context.rb +31 -0
- data/lib/ffi/gphoto2/gphoto_device_type.rb +7 -0
- data/lib/ffi/gphoto2_port.rb +31 -0
- data/lib/ffi/gphoto2_port/gp_port_info.rb +11 -0
- data/lib/ffi/gphoto2_port/gp_port_info_list.rb +14 -0
- data/lib/ffi/gphoto2_port/gp_port_result.rb +35 -0
- data/lib/ffi/gphoto2_port/gp_port_type.rb +12 -0
- data/lib/gphoto2.rb +41 -0
- data/lib/gphoto2/camera.rb +219 -0
- data/lib/gphoto2/camera_abilities.rb +44 -0
- data/lib/gphoto2/camera_abilities_list.rb +64 -0
- data/lib/gphoto2/camera_file.rb +69 -0
- data/lib/gphoto2/camera_file_path.rb +21 -0
- data/lib/gphoto2/camera_folder.rb +82 -0
- data/lib/gphoto2/camera_list.rb +43 -0
- data/lib/gphoto2/camera_widgets/camera_widget.rb +112 -0
- data/lib/gphoto2/camera_widgets/date_camera_widget.rb +19 -0
- data/lib/gphoto2/camera_widgets/menu_camera_widget.rb +4 -0
- data/lib/gphoto2/camera_widgets/radio_camera_widget.rb +41 -0
- data/lib/gphoto2/camera_widgets/range_camera_widget.rb +37 -0
- data/lib/gphoto2/camera_widgets/section_camera_widget.rb +4 -0
- data/lib/gphoto2/camera_widgets/text_camera_widget.rb +14 -0
- data/lib/gphoto2/camera_widgets/toggle_camera_widget.rb +18 -0
- data/lib/gphoto2/camera_widgets/window_camera_widget.rb +4 -0
- data/lib/gphoto2/context.rb +31 -0
- data/lib/gphoto2/entry.rb +38 -0
- data/lib/gphoto2/port_info.rb +70 -0
- data/lib/gphoto2/port_info_list.rb +46 -0
- data/lib/gphoto2/port_result.rb +7 -0
- data/lib/gphoto2/version.rb +3 -0
- data/spec/gphoto2/camera_abilities_list_spec.rb +45 -0
- data/spec/gphoto2/camera_abilities_spec.rb +38 -0
- data/spec/gphoto2/camera_file_path_spec.rb +27 -0
- data/spec/gphoto2/camera_file_spec.rb +71 -0
- data/spec/gphoto2/camera_folder_spec.rb +110 -0
- data/spec/gphoto2/camera_list_spec.rb +35 -0
- data/spec/gphoto2/camera_spec.rb +292 -0
- data/spec/gphoto2/camera_widgets/date_camera_widget_spec.rb +15 -0
- data/spec/gphoto2/camera_widgets/radio_camera_widget_spec.rb +31 -0
- data/spec/gphoto2/camera_widgets/range_camera_widget_spec.rb +27 -0
- data/spec/gphoto2/camera_widgets/text_camera_widget_spec.rb +15 -0
- data/spec/gphoto2/camera_widgets/toggle_camera_widget_spec.rb +21 -0
- data/spec/gphoto2/context_spec.rb +17 -0
- data/spec/gphoto2/entry_spec.rb +27 -0
- data/spec/gphoto2/port_info_list_spec.rb +33 -0
- data/spec/gphoto2/port_info_spec.rb +53 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/support/shared_examples/camera_widget_examples.rb +89 -0
- metadata +194 -0
@@ -0,0 +1,41 @@
|
|
1
|
+
module GPhoto2
|
2
|
+
class RadioCameraWidget < CameraWidget
|
3
|
+
def choices
|
4
|
+
count_choices.times.map { |i| get_choice(i) }
|
5
|
+
end
|
6
|
+
|
7
|
+
protected
|
8
|
+
|
9
|
+
def get_value
|
10
|
+
val = FFI::MemoryPointer.new(:string)
|
11
|
+
val_ptr = FFI::MemoryPointer.new(:pointer)
|
12
|
+
val_ptr.write_pointer(val)
|
13
|
+
rc = gp_widget_get_value(ptr, val_ptr)
|
14
|
+
GPhoto2.check!(rc)
|
15
|
+
val_ptr.read_pointer.read_string
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_value(value)
|
19
|
+
val = FFI::MemoryPointer.from_string(value.to_s)
|
20
|
+
rc = gp_widget_set_value(ptr, val)
|
21
|
+
GPhoto2.check!(rc)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def count_choices
|
27
|
+
rc = gp_widget_count_choices(ptr)
|
28
|
+
GPhoto2.check!(rc)
|
29
|
+
rc
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_choice(i)
|
33
|
+
val = FFI::MemoryPointer.new(:string)
|
34
|
+
val_ptr = FFI::MemoryPointer.new(:pointer)
|
35
|
+
val_ptr.write_pointer(val)
|
36
|
+
rc = gp_widget_get_choice(ptr, i, val_ptr)
|
37
|
+
GPhoto2.check!(rc)
|
38
|
+
val_ptr.read_pointer.read_string
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module GPhoto2
|
2
|
+
class RangeCameraWidget < CameraWidget
|
3
|
+
def range
|
4
|
+
min, max, inc = get_range
|
5
|
+
(min..max).step(inc).to_a
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
|
10
|
+
def get_value
|
11
|
+
val = FFI::MemoryPointer.new(:float)
|
12
|
+
rc = gp_widget_get_value(ptr, val)
|
13
|
+
GPhoto2.check!(rc)
|
14
|
+
val.read_float
|
15
|
+
end
|
16
|
+
|
17
|
+
def set_value(value)
|
18
|
+
val = FFI::MemoryPointer.new(:float)
|
19
|
+
val.write_float(value)
|
20
|
+
rc = gp_widget_set_value(ptr, val)
|
21
|
+
GPhoto2.check!(rc)
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def get_range
|
27
|
+
min = FFI::MemoryPointer.new(:float)
|
28
|
+
max = FFI::MemoryPointer.new(:float)
|
29
|
+
inc = FFI::MemoryPointer.new(:float)
|
30
|
+
|
31
|
+
rc = gp_widget_get_range(ptr, min, max, inc)
|
32
|
+
GPhoto2.check!(rc)
|
33
|
+
|
34
|
+
[min.read_float, max.read_float, inc.read_float]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module GPhoto2
|
2
|
+
class TextCameraWidget < CameraWidget
|
3
|
+
protected
|
4
|
+
|
5
|
+
def get_value
|
6
|
+
val = FFI::MemoryPointer.new(:string)
|
7
|
+
val_ptr = FFI::MemoryPointer.new(:pointer)
|
8
|
+
val_ptr.write_pointer(val)
|
9
|
+
rc = gp_widget_get_value(ptr, val_ptr)
|
10
|
+
GPhoto2.check!(rc)
|
11
|
+
val_ptr.read_pointer.read_string
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module GPhoto2
|
2
|
+
class ToggleCameraWidget < CameraWidget
|
3
|
+
protected
|
4
|
+
|
5
|
+
def get_value
|
6
|
+
val = FFI::MemoryPointer.new(:int)
|
7
|
+
rc = gp_widget_get_value(ptr, val)
|
8
|
+
(val.read_int == 1)
|
9
|
+
end
|
10
|
+
|
11
|
+
def set_value(toggle)
|
12
|
+
val = FFI::MemoryPointer.new(:int)
|
13
|
+
val.write_int(toggle ? 1 : 0)
|
14
|
+
rc = gp_widget_set_value(ptr, val)
|
15
|
+
GPhoto2.check!(rc)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module GPhoto2
|
2
|
+
class Context
|
3
|
+
include FFI::GPhoto2
|
4
|
+
|
5
|
+
attr_reader :ptr
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
new
|
9
|
+
end
|
10
|
+
|
11
|
+
def finalize
|
12
|
+
unref
|
13
|
+
end
|
14
|
+
alias_method :close, :finalize
|
15
|
+
|
16
|
+
def to_ptr
|
17
|
+
@ptr
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def new
|
23
|
+
ctx = gp_context_new()
|
24
|
+
@ptr = GPContext.new(ctx)
|
25
|
+
end
|
26
|
+
|
27
|
+
def unref
|
28
|
+
gp_context_unref(ptr)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module GPhoto2
|
2
|
+
class Entry
|
3
|
+
include FFI::GPhoto2
|
4
|
+
|
5
|
+
def initialize(camera_list, index)
|
6
|
+
@camera_list = camera_list
|
7
|
+
@index = index
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
get_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def value
|
15
|
+
get_value
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def get_name
|
21
|
+
name = FFI::MemoryPointer.new(:string)
|
22
|
+
ptr = FFI::MemoryPointer.new(:pointer)
|
23
|
+
ptr.write_pointer(name)
|
24
|
+
rc = gp_list_get_name(@camera_list.ptr, @index, ptr)
|
25
|
+
GPhoto2.check!(rc)
|
26
|
+
ptr.read_pointer.read_string
|
27
|
+
end
|
28
|
+
|
29
|
+
def get_value
|
30
|
+
value = FFI::MemoryPointer.new(:string)
|
31
|
+
ptr = FFI::MemoryPointer.new(:pointer)
|
32
|
+
ptr.write_pointer(value)
|
33
|
+
rc = gp_list_get_value(@camera_list.ptr, @index, ptr)
|
34
|
+
GPhoto2.check!(rc)
|
35
|
+
ptr.read_pointer.read_string
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module GPhoto2
|
2
|
+
class PortInfo
|
3
|
+
include FFI::GPhoto2Port
|
4
|
+
|
5
|
+
attr_reader :ptr
|
6
|
+
|
7
|
+
def self.find(port)
|
8
|
+
port_info_list = PortInfoList.new
|
9
|
+
index = port_info_list.lookup_path(port)
|
10
|
+
port_info_list[index]
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(port_info_list, index)
|
14
|
+
@port_info_list = port_info_list
|
15
|
+
@index = index
|
16
|
+
new
|
17
|
+
end
|
18
|
+
|
19
|
+
def name
|
20
|
+
get_name
|
21
|
+
end
|
22
|
+
|
23
|
+
def path
|
24
|
+
get_path
|
25
|
+
end
|
26
|
+
|
27
|
+
def type
|
28
|
+
get_type
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_ptr
|
32
|
+
@ptr
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def new
|
38
|
+
ptr = FFI::MemoryPointer.new(GPPortInfo)
|
39
|
+
rc = gp_port_info_list_get_info(@port_info_list.ptr, @index, ptr)
|
40
|
+
GPhoto2.check!(rc)
|
41
|
+
@ptr = GPPortInfo.new(ptr.read_pointer)
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_name
|
45
|
+
name = FFI::MemoryPointer.new(:string)
|
46
|
+
name_ptr = FFI::MemoryPointer.new(:pointer)
|
47
|
+
name_ptr.write_pointer(name)
|
48
|
+
rc = gp_port_info_get_name(ptr, name_ptr)
|
49
|
+
GPhoto2.check!(rc)
|
50
|
+
name_ptr.read_pointer.read_string
|
51
|
+
end
|
52
|
+
|
53
|
+
def get_path
|
54
|
+
path = FFI::MemoryPointer.new(:string)
|
55
|
+
path_ptr = FFI::MemoryPointer.new(:pointer)
|
56
|
+
path_ptr.write_pointer(path)
|
57
|
+
rc = gp_port_info_get_path(ptr, path_ptr)
|
58
|
+
GPhoto2.check!(rc)
|
59
|
+
path_ptr.read_pointer.read_string
|
60
|
+
end
|
61
|
+
|
62
|
+
def get_type
|
63
|
+
# assume GPPortType is an int
|
64
|
+
type = FFI::MemoryPointer.new(:int)
|
65
|
+
rc = gp_port_info_get_type(ptr, type)
|
66
|
+
GPhoto2.check!(rc)
|
67
|
+
GPPortType[type.read_int]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module GPhoto2
|
2
|
+
class PortInfoList
|
3
|
+
include FFI::GPhoto2Port
|
4
|
+
|
5
|
+
attr_reader :ptr
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
new
|
9
|
+
load
|
10
|
+
end
|
11
|
+
|
12
|
+
def lookup_path(port)
|
13
|
+
_lookup_path(port)
|
14
|
+
end
|
15
|
+
alias_method :index, :lookup_path
|
16
|
+
|
17
|
+
def at(index)
|
18
|
+
PortInfo.new(self, index)
|
19
|
+
end
|
20
|
+
alias_method :[], :at
|
21
|
+
|
22
|
+
def to_ptr
|
23
|
+
@ptr
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def new
|
29
|
+
ptr = FFI::MemoryPointer.new(GPPortInfoList)
|
30
|
+
rc = gp_port_info_list_new(ptr)
|
31
|
+
GPhoto2.check!(rc)
|
32
|
+
@ptr = GPPortInfoList.new(ptr.read_pointer)
|
33
|
+
end
|
34
|
+
|
35
|
+
def load
|
36
|
+
rc = gp_port_info_list_load(ptr)
|
37
|
+
GPhoto2.check!(rc)
|
38
|
+
end
|
39
|
+
|
40
|
+
def _lookup_path(port)
|
41
|
+
index = rc = gp_port_info_list_lookup_path(ptr, port)
|
42
|
+
GPhoto2.check!(rc)
|
43
|
+
index
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module GPhoto2
|
4
|
+
describe CameraAbilitiesList do
|
5
|
+
let(:context) { double('context') }
|
6
|
+
|
7
|
+
before do
|
8
|
+
CameraAbilitiesList.any_instance.stub(:new)
|
9
|
+
CameraAbilitiesList.any_instance.stub(:load)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#detect' do
|
13
|
+
it 'returns a list cameras' do
|
14
|
+
camera_list = double('camera_list')
|
15
|
+
|
16
|
+
abilities_list = CameraAbilitiesList.new(context)
|
17
|
+
abilities_list.stub(:_detect).and_return(camera_list)
|
18
|
+
|
19
|
+
expect(abilities_list.detect).to eq(camera_list)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '#lookup_model' do
|
24
|
+
it 'returns the index of the abilities in the list' do
|
25
|
+
index = 0
|
26
|
+
|
27
|
+
list = CameraAbilitiesList.new(context)
|
28
|
+
list.stub(:_lookup_model).and_return(index)
|
29
|
+
|
30
|
+
expect(list.lookup_model('model')).to eq(index)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#at' do
|
35
|
+
it 'returns a new CameraAbilities instance at the specified index' do
|
36
|
+
abilities = double('camera_abilities')
|
37
|
+
|
38
|
+
CameraAbilities.stub(:new).and_return(abilities)
|
39
|
+
list = CameraAbilitiesList.new(context)
|
40
|
+
|
41
|
+
expect(list.at(0)).to eq(abilities)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module GPhoto2
|
4
|
+
describe CameraAbilities do
|
5
|
+
let(:camera_abilities_list) { double('camera_abilities_list') }
|
6
|
+
let(:index) { 0 }
|
7
|
+
|
8
|
+
before do
|
9
|
+
CameraAbilities.any_instance.stub(:get_abilities)
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '.find' do
|
13
|
+
it 'returns a new CameraAbilities instance from a model name' do
|
14
|
+
abilities = double('camera_abilities')
|
15
|
+
|
16
|
+
context = double('context')
|
17
|
+
context.stub(:finalize)
|
18
|
+
Context.stub(:new).and_return(context)
|
19
|
+
|
20
|
+
camera_abilities_list = double('camera_abilities_list')
|
21
|
+
CameraAbilitiesList.stub(:new).and_return(camera_abilities_list)
|
22
|
+
camera_abilities_list.stub(:lookup_model).and_return(0)
|
23
|
+
camera_abilities_list.stub(:[]).and_return(abilities)
|
24
|
+
|
25
|
+
expect(CameraAbilities.find('model')).to eq(abilities)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#[]' do
|
30
|
+
it 'returns the value at the given field' do
|
31
|
+
key, value = :model, 'name'
|
32
|
+
abilities = CameraAbilities.new(camera_abilities_list, index)
|
33
|
+
abilities.stub(:ptr).and_return({ key => value })
|
34
|
+
expect(abilities[key]).to eq(value)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module GPhoto2
|
4
|
+
describe CameraFilePath do
|
5
|
+
let(:name) { 'capt0001.jpg' }
|
6
|
+
let(:folder) { '/' }
|
7
|
+
|
8
|
+
before do
|
9
|
+
CameraFilePath.any_instance.stub(:name).and_return(name)
|
10
|
+
CameraFilePath.any_instance.stub(:folder).and_return(folder)
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '#name' do
|
14
|
+
it 'returns the name of the file' do
|
15
|
+
path = CameraFilePath.new
|
16
|
+
expect(path.name).to eq(name)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#folder' do
|
21
|
+
it 'returns the folder that contains the file' do
|
22
|
+
path = CameraFilePath.new
|
23
|
+
expect(path.folder).to eq(folder)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|