Class: GPhoto2::Camera

Inherits:
Object
  • Object
show all
Includes:
FFI::GPhoto2, Capture, Configuration, Event, Filesystem, Struct
Defined in:
lib/gphoto2/camera.rb,
lib/gphoto2/camera/event.rb,
lib/gphoto2/camera/capture.rb,
lib/gphoto2/camera/filesystem.rb,
lib/gphoto2/camera/configuration.rb

Defined Under Namespace

Modules: Capture, Configuration, Event, Filesystem

Constant Summary

Constants included from FFI::GPhoto2

FFI::GPhoto2::CameraCaptureType, FFI::GPhoto2::CameraDriverStatus, FFI::GPhoto2::CameraEventType, FFI::GPhoto2::CameraFileAccessType, FFI::GPhoto2::CameraFileInfoFields, FFI::GPhoto2::CameraFileOperation, FFI::GPhoto2::CameraFilePermissions, FFI::GPhoto2::CameraFileStatus, FFI::GPhoto2::CameraFileType, FFI::GPhoto2::CameraFolderOperation, FFI::GPhoto2::CameraOperation, FFI::GPhoto2::CameraWidgetType, FFI::GPhoto2::GphotoDeviceType

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Filesystem

#delete, #file, #filesystem

Methods included from Event

#wait, #wait_for

Methods included from Configuration

#[], #[]=, #config, #dirty?, #reload, #save, #update, #window

Methods included from Capture

#capture, #preview, #trigger

Methods included from Struct

#to_ptr

Constructor Details

#initialize(model, port) ⇒ Camera

Returns a new instance of Camera.

Parameters:

  • model (String)
  • port (String)


108
109
110
111
# File 'lib/gphoto2/camera.rb', line 108

def initialize(model, port)
  super
  @model, @port = model, port
end

Instance Attribute Details

#modelString (readonly)

Returns:

  • (String)


12
13
14
# File 'lib/gphoto2/camera.rb', line 12

def model
  @model
end

#portString (readonly)

Returns:

  • (String)


15
16
17
# File 'lib/gphoto2/camera.rb', line 15

def port
  @port
end

Class Method Details

.allArray<GPhoto2::Camera>

Returns a list of all available devices.

Examples:

cameras = GPhoto2::Camera.all
# => [#<GPhoto2::Camera>, #<GPhoto2::Camera>, ...]

Returns:



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gphoto2/camera.rb', line 22

def self.all
  context = Context.new

  abilities = CameraAbilitiesList.new(context)
  cameras = abilities.detect

  entries = cameras.to_a.map do |entry|
    model, port = entry.name, entry.value
    Camera.new(model, port)
  end

  context.finalize

  entries
end

.first(&blk) ⇒ GPhoto2::Camera

Returns the first detected camera.

Examples:

camera = GPhoto2::Camera.first

begin
  # ...
ensure
  camera.finalize
end

# Alternatively, pass a block, which will automatically close the camera.
GPhoto2::Camera.first do |camera|
  # ...
end

Returns:

Raises:

  • (RuntimeError)

    when no devices are detected



54
55
56
57
58
59
# File 'lib/gphoto2/camera.rb', line 54

def self.first(&blk)
  entries = all
  raise RuntimeError, 'no devices detected' if entries.empty?
  camera = entries.first
  autorelease(camera, &blk)
end

.open(model, port, &blk) ⇒ GPhoto2::Camera

Examples:

model = 'Nikon DSC D5100 (PTP mode)'
port = 'usb:250,006'

camera = GPhoto2::Camera.open(model, port)

begin
  # ...
ensure
  camera.finalize
end

# Alternatively, pass a block, which will automatically close the camera.
GPhoto2::Camera.open(model, port) do |camera|
  # ...
end

Parameters:

  • model (String)
  • port (String)

Returns:



81
82
83
84
# File 'lib/gphoto2/camera.rb', line 81

def self.open(model, port, &blk)
  camera = new(model, port)
  autorelease(camera, &blk)
end

.where(condition) ⇒ Array<GPhoto2::Camera>

Filters devices by a given condition.

Filter keys can be either ‘model` or `port`. Only the first filter is used.

Examples:

# Find the cameras whose model names contain Nikon.
cameras = GPhoto2::Camera.where(model: /nikon/i)

# Select a camera by its port.
camera = GPhoto2::Camera.where(port: 'usb:250,004').first

Parameters:

  • condition (Hash)

Returns:



100
101
102
103
104
# File 'lib/gphoto2/camera.rb', line 100

def self.where(condition)
  name = condition.keys.first
  pattern = condition.values.first
  all.select { |c| c.send(name).match(pattern) }
end

Instance Method Details

#abilitiesGPhoto2::CameraAbilities



132
133
134
# File 'lib/gphoto2/camera.rb', line 132

def abilities
  @abilities || (init && @abilities)
end

#can?(operation) ⇒ Boolean

Examples:

camera.can? :capture_image
# => true

Parameters:

Returns:

  • (Boolean)

See Also:



153
154
155
# File 'lib/gphoto2/camera.rb', line 153

def can?(operation)
  (abilities.operations & (CameraOperation[operation] || 0)) != 0
end

#contextGPhoto2::Context

Returns:



142
143
144
# File 'lib/gphoto2/camera.rb', line 142

def context
  @context ||= Context.new
end

#exitvoid

This method returns an undefined value.



122
123
124
# File 'lib/gphoto2/camera.rb', line 122

def exit
  _exit
end

#finalizevoid Also known as: close

This method returns an undefined value.



114
115
116
117
118
# File 'lib/gphoto2/camera.rb', line 114

def finalize
  @context.finalize if @context
  @window.finalize if @window
  unref if @ptr
end

#port_infoGPhoto2::PortInfo

Returns:



137
138
139
# File 'lib/gphoto2/camera.rb', line 137

def port_info
  @port_info || (init && @port_info)
end

#ptrFFI::GPhoto::Camera

Returns:

  • (FFI::GPhoto::Camera)


127
128
129
# File 'lib/gphoto2/camera.rb', line 127

def ptr
  @ptr || (init && @ptr)
end