ffi-gphoto2 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 06a37e1529e44e76317ee65554d7c1ddacea1cec
4
- data.tar.gz: fd9cb5732c86302822891de0530a3b6dd822c078
3
+ metadata.gz: 83f9c14b8b7006440420e875c32d4a93b809ce28
4
+ data.tar.gz: 9e3ccef87bc4565c88c4750e64d09ccde23f3330
5
5
  SHA512:
6
- metadata.gz: 63f6a9cc345afbc0c9e90fd4396927d054e24825c6579de635e0a12ab97fce77606960c0c9a79771b005b08e91537a262decef0e7015c3aa60010fa51b1bed3b
7
- data.tar.gz: e1cd250dc551227e6425991e8aabe5e1dcb92452186caa6f33980081784f33c5733e96aadb99806abca94697c3090e2cd898dc6fa140d582655b0f2155ada2fc
6
+ metadata.gz: 9d90104862dfccd44685aefa3870d83cde93e23a0aab57df6a7eb5a7feb2d9e712ca8c3125260b36f18b090df6ea8fce60726e913b667617f551180058c12397
7
+ data.tar.gz: f8536cef9cf2d3d7c9cfedb71fa0e7079280a7a7a0e7f579e1b886c4cba8e37e9316504e2298f1aabc0358638a3cd7f0ef5d20e5c87eee95ea4e15d82acef454
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
1
  --color
2
- --warnings
3
2
  --require spec_helper
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  **ffi-gphoto2** provides an FFI for common functions in [libgphoto2][1].
4
4
  It also includes a facade to interact with the library in a more
5
- canonical Ruby way.
5
+ idiomatic Ruby way.
6
6
 
7
7
  ## Installation
8
8
 
@@ -17,82 +17,94 @@ canonical Ruby way.
17
17
 
18
18
  ## Usage
19
19
 
20
- require 'gphoto2'
20
+ ```ruby
21
+ require 'gphoto2'
21
22
 
22
- # list available cameras
23
- cameras = GPhoto2::Camera.all
24
- # => [#<GPhoto2::Camera>, ...]
23
+ # list available cameras
24
+ cameras = GPhoto2::Camera.all
25
+ # => [#<GPhoto2::Camera>, ...]
25
26
 
26
- # list found cameras by model and port path
27
- cameras.map { |c| [c.model, c.port] }
28
- # => [['Nikon DSC D5100 (PTP mode)', 'usb:250,006'], ...]
27
+ # list found cameras by model and port path
28
+ cameras.map { |c| [c.model, c.port] }
29
+ # => [['Nikon DSC D5100 (PTP mode)', 'usb:250,006'], ...]
29
30
 
30
- # use the first camera
31
- camera = cameras.first
31
+ # use the first camera
32
+ camera = cameras.first
32
33
 
33
- # ...or more conveniently
34
- camera = GPhoto2::Camera.first
34
+ # ...or more conveniently
35
+ camera = GPhoto2::Camera.first
35
36
 
36
- # ...or even search by model name
37
- camera = GPhoto2::Camera.where(model: /nikon/i).first
37
+ # ...or even search by model name
38
+ camera = GPhoto2::Camera.where(model: /nikon/i).first
38
39
 
39
- # check camera abilities
40
- camera.can? :capture_image
41
- # => true
40
+ # check camera abilities (see `FFI::GPhoto2::CameraOperation.symbols`)
41
+ camera.can? :capture_image
42
+ # => true
42
43
 
43
- # list camera configuration names
44
- camera.config.keys
45
- # => ['autofocusdrive', 'manualfocusdrive', 'controlmode', ...]
44
+ # list camera configuration names
45
+ camera.config.keys
46
+ # => ['autofocusdrive', 'manualfocusdrive', 'controlmode', ...]
46
47
 
47
- # read the current configuration value of an option
48
- camera['whitebalance']
49
- # => "Automatic"
48
+ # read the current configuration value of an option
49
+ camera['expprogram'].value
50
+ # => "M"
51
+ camera['whitebalance'].value
52
+ # => "Automatic"
50
53
 
51
- # list valid choices of a configuration option
52
- camera['whitebalance'].choices
53
- # => ['Automatic', 'Daylight', 'Fluorescent', 'Tungsten', ...]
54
+ # list valid choices of a configuration option
55
+ camera['whitebalance'].choices
56
+ # => ["Automatic", "Daylight", "Fluorescent", "Tungsten", ...]
54
57
 
55
- # check if the configuration has changed
56
- camera.dirty?
57
- # => false
58
+ # check if the configuration has changed
59
+ camera.dirty?
60
+ # => false
58
61
 
59
- # change camera configuration
60
- camera['iso'] = 800
61
- camera['f-number'] = 'f/4.5'
62
- camera['shutterspeed2'] = '1/30'
62
+ # change camera configuration
63
+ camera['iso'] = 800
64
+ camera['f-number'] = 'f/4.5'
65
+ camera['shutterspeed2'] = '1/30'
63
66
 
64
- # check if the configuration has changed
65
- camera.dirty?
66
- # => true
67
+ # check if the configuration has changed
68
+ camera.dirty?
69
+ # => true
67
70
 
68
- # apply the new configuration on the device
69
- camera.save
71
+ # apply the new configuration to the device
72
+ camera.save
70
73
 
71
- # take a photo
72
- file = camera.capture
74
+ # alternatively, update the camera configuration in one go
75
+ camera.update(iso: 200, shutterspeed2: '1/60', 'f-number' => 'f/1.8')
73
76
 
74
- # ...and save it to the current working directory
75
- file.save
77
+ # take a photo
78
+ file = camera.capture
76
79
 
77
- # traverse the camera filesystem
78
- folder = camera/'store_00010001/DCIM/100D5100'
80
+ # ...and save it to the current working directory
81
+ file.save
79
82
 
80
- # list files
81
- files = folder.files
82
- folder.files.map(&:name)
83
- => ["DSC_0001.JPG", "DSC_0002.JPG", ...]
83
+ # ...or to a specific pathname
84
+ file.save('/tmp/out.jpg')
84
85
 
85
- # save a file
86
- file = files.first
87
- file.save
86
+ # traverse the camera filesystem
87
+ folder = camera/'store_00010001/DCIM/100D5100'
88
88
 
89
- # and delete it
90
- file.delete
89
+ # list files
90
+ files = folder.files
91
+ folder.files.map(&:name)
92
+ # => ["DSC_0001.JPG", "DSC_0002.JPG", ...]
91
93
 
92
- # close the camera
93
- camera.finalize
94
+ # copy a file from the camera
95
+ file = files.first
96
+ file.save
94
97
 
95
- More examples can be found in [`examples/`][2].
98
+ # ...and then delete it from the camera
99
+ file.delete
100
+
101
+ # close the camera
102
+ camera.finalize
103
+ ```
104
+
105
+ More examples can be found in [`examples/`][2]. YARD documentation can be
106
+ generated using the `rake yard` task or [browsed online][3].
96
107
 
97
108
  [1]: http://www.gphoto.org/
98
109
  [2]: https://github.com/zaeleus/ffi-gphoto2/tree/master/examples
110
+ [3]: http://www.rubydoc.info/gems/ffi-gphoto2/frames
@@ -15,9 +15,6 @@ def visit(widget, level = 0)
15
15
  indent << ' '
16
16
 
17
17
  puts "#{indent}type: #{widget.type}"
18
-
19
- return if widget.type == :menu
20
-
21
18
  puts "#{indent}value: #{widget.value}"
22
19
 
23
20
  case widget.type
@@ -25,7 +22,7 @@ def visit(widget, level = 0)
25
22
  range = widget.range
26
23
  step = (range.size > 1) ? range[1] - range[0] : 1.0
27
24
  puts "#{indent}options: #{range.first}..#{range.last}:step(#{step})"
28
- when :radio
25
+ when :radio, :menu
29
26
  puts "#{indent}options: #{widget.choices.inspect}"
30
27
  end
31
28
  end
data/ffi-gphoto2.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.3'
26
26
  spec.add_development_dependency 'rake'
27
- spec.add_development_dependency 'rspec', '~> 3.0.0'
27
+ spec.add_development_dependency 'rspec', '~> 3.2.0'
28
28
  spec.add_development_dependency 'yard', '~> 0.8.7'
29
29
 
30
30
  spec.add_dependency 'ffi', '~> 1.9.0'
@@ -29,6 +29,16 @@ module GPhoto2
29
29
  #
30
30
  # All unsaved changes will be lost.
31
31
  #
32
+ # @example
33
+ # camera['iso']
34
+ # # => 800
35
+ #
36
+ # camera['iso'] = 200
37
+ # camera.reload
38
+ #
39
+ # camera['iso']
40
+ # # => 800
41
+ #
32
42
  # @return [void]
33
43
  def reload
34
44
  @window.finalize if @window
@@ -67,6 +77,13 @@ module GPhoto2
67
77
 
68
78
  # Updates the configuration on the camera.
69
79
  #
80
+ # @example
81
+ # camera['iso'] = 800
82
+ # camera.save
83
+ # # => true
84
+ # camera.save
85
+ # # => false (nothing to update)
86
+ #
70
87
  # @return [Boolean] whether setting the configuration was attempted
71
88
  def save
72
89
  return false unless dirty?
@@ -30,7 +30,7 @@ module GPhoto2
30
30
  rc = gp_camera_wait_for_event(ptr, timeout, type, data_ptr, context.ptr)
31
31
  GPhoto2.check!(rc)
32
32
 
33
- type = CameraEventType[type.read_int]
33
+ type = FFI::GPhoto2::CameraEventType[type.read_int]
34
34
  data = data_ptr.read_pointer
35
35
 
36
36
  data =
@@ -56,7 +56,7 @@ module GPhoto2
56
56
  raise RuntimeError, 'no devices detected' if entries.empty?
57
57
  camera = entries.first
58
58
  autorelease(camera, &blk)
59
- end
59
+ end
60
60
 
61
61
  # @example
62
62
  # model = 'Nikon DSC D5100 (PTP mode)'
@@ -139,6 +139,7 @@ module GPhoto2
139
139
  # camera.can? :capture_image
140
140
  # # => true
141
141
  #
142
+ # @see FFI::GPhoto2::CameraOperation
142
143
  # @param [CameraOperation] operation
143
144
  # @return [Boolean]
144
145
  def can?(operation)
@@ -63,8 +63,6 @@ module GPhoto2
63
63
  case type
64
64
  when :window, :section
65
65
  children.each { |child| child.flatten(map) }
66
- when :menu
67
- # noop
68
66
  else
69
67
  map[name] = self
70
68
  end
@@ -1,4 +1,4 @@
1
1
  module GPhoto2
2
- class MenuCameraWidget < CameraWidget
2
+ class MenuCameraWidget < RadioCameraWidget
3
3
  end
4
4
  end
@@ -1,3 +1,3 @@
1
1
  module GPhoto2
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
data/lib/gphoto2.rb CHANGED
@@ -8,9 +8,9 @@ require 'ffi/gphoto2_port'
8
8
  require 'gphoto2/struct'
9
9
 
10
10
  require 'gphoto2/camera_widgets/camera_widget'
11
+ require 'gphoto2/camera_widgets/radio_camera_widget'
11
12
  require 'gphoto2/camera_widgets/date_camera_widget'
12
13
  require 'gphoto2/camera_widgets/menu_camera_widget'
13
- require 'gphoto2/camera_widgets/radio_camera_widget'
14
14
  require 'gphoto2/camera_widgets/range_camera_widget'
15
15
  require 'gphoto2/camera_widgets/section_camera_widget'
16
16
  require 'gphoto2/camera_widgets/text_camera_widget'
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module GPhoto2
4
4
  describe DateCameraWidget do
5
- it_behaves_like CameraWidget, DateCameraWidget
5
+ it_behaves_like CameraWidget
6
6
 
7
7
  describe '#value' do
8
8
  it 'has a Time return value' do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module GPhoto2
4
4
  describe RadioCameraWidget do
5
- it_behaves_like CameraWidget, RadioCameraWidget
5
+ it_behaves_like CameraWidget
6
6
 
7
7
  describe '#value' do
8
8
  it 'has a String return value' do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module GPhoto2
4
4
  describe RangeCameraWidget do
5
- it_behaves_like CameraWidget, RangeCameraWidget
5
+ it_behaves_like CameraWidget
6
6
 
7
7
  describe '#value' do
8
8
  it 'has a Float return value' do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module GPhoto2
4
4
  describe TextCameraWidget do
5
- it_behaves_like CameraWidget, TextCameraWidget
5
+ it_behaves_like CameraWidget
6
6
 
7
7
  describe '#value' do
8
8
  it 'has a String return value' do
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  module GPhoto2
4
4
  describe ToggleCameraWidget do
5
- it_behaves_like CameraWidget, ToggleCameraWidget
5
+ it_behaves_like CameraWidget
6
6
 
7
7
  describe '#value' do
8
8
  it 'can have a TrueClass return value' do
data/spec/spec_helper.rb CHANGED
@@ -3,3 +3,13 @@ require 'gphoto2'
3
3
 
4
4
  __dir__ ||= File.dirname(__FILE__)
5
5
  Dir[File.join(__dir__, 'support/**/*.rb')].each { |f| require f }
6
+
7
+ RSpec.configure do |config|
8
+ config.expect_with :rspec do |expectations|
9
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
10
+ end
11
+
12
+ config.mock_with :rspec do |mocks|
13
+ mocks.verify_partial_doubles = true
14
+ end
15
+ end
@@ -1,4 +1,6 @@
1
- shared_examples_for GPhoto2::CameraWidget do |klass|
1
+ shared_examples_for GPhoto2::CameraWidget do
2
+ let(:klass) { described_class }
3
+
2
4
  describe '#name' do
3
5
  it 'returns the name of the widget' do
4
6
  name = 'name'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-gphoto2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Macias
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-16 00:00:00.000000000 Z
11
+ date: 2015-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 3.0.0
47
+ version: 3.2.0
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 3.0.0
54
+ version: 3.2.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: yard
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -195,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
195
195
  requirements:
196
196
  - libgphoto2 >= 2.5.0
197
197
  rubyforge_project:
198
- rubygems_version: 2.2.2
198
+ rubygems_version: 2.4.6
199
199
  signing_key:
200
200
  specification_version: 4
201
201
  summary: A Ruby FFI for common functions in libgphoto2