module GPhoto2::Camera::Configuration

Public Class Methods

new(model, port) click to toggle source

@param [String] model @param [String] port

# File lib/gphoto2/camera/configuration.rb, line 6
def initialize(model, port)
  reset
end

Public Instance Methods

[](key) click to toggle source

@example

camera['whitebalance'].to_s
# => "Automatic"

@param [#to_s] key @return [GPhoto2::CameraWidget] the widget identified by ‘key`

# File lib/gphoto2/camera/configuration.rb, line 55
def [](key)
  config[key.to_s]
end
[]=(key, value) click to toggle source

Updates the attribute identified by ‘key` with the specified `value`.

This marks the configuration as “dirty”, meaning a call to {#save} is needed to actually update the configuration on the camera.

@example

camera['iso'] = 800
camera['f-number'] = 'f/2.8'
camera['shutterspeed2'] = '1/60'

@param [#to_s] key @param [Object] value @return [Object]

# File lib/gphoto2/camera/configuration.rb, line 72
def []=(key, value)
  raise ArgumentError, "invalid key: #{key}" unless self[key]
  self[key].value = value
  @dirty = true
  value
end
config() click to toggle source

@example

# List camera configuration keys.
camera.config.keys
# => ['autofocusdrive', 'manualfocusdrive', 'controlmode', ...]

@return [Hash<String,GPhoto2::CameraWidget>] a flat map of camera

configuration widgets

@see [] @see []=

# File lib/gphoto2/camera/configuration.rb, line 24
def config
  @config ||= window.flatten
end
dirty?() click to toggle source

@example

camera.dirty?
# => false

camera['iso'] = 400

camera.dirty?
# => true

@return [Boolean] whether attributes have been changed

# File lib/gphoto2/camera/configuration.rb, line 128
def dirty?
  @dirty
end
reload() click to toggle source

Reloads the camera configuration.

All unsaved changes will be lost.

@example

camera['iso']
# => 800

camera['iso'] = 200
camera.reload

camera['iso']
# => 800

@return [void]

# File lib/gphoto2/camera/configuration.rb, line 43
def reload
  @window.finalize if @window
  reset
  config
end
save() click to toggle source

Updates the configuration on the camera.

@example

camera['iso'] = 800
camera.save
# => true
camera.save
# => false (nothing to update)

@return [Boolean] whether setting the configuration was attempted

# File lib/gphoto2/camera/configuration.rb, line 89
def save
  return false unless dirty?
  set_config
  @dirty = false
  true
end
update(attributes = {}) click to toggle source

Updates the attributes of the camera from the given Hash and saves the configuration.

@example

camera['iso'] # => 800
camera['shutterspeed2'] # => "1/30"

camera.update(iso: 400, shutterspeed2: '1/60')

camera['iso'] # => 400
camera['shutterspeed2'] # => "1/60"

@param [Hash<String,Object>] attributes @return [Boolean] whether the configuration saved

# File lib/gphoto2/camera/configuration.rb, line 110
def update(attributes = {})
  attributes.each do |key, value|
    self[key] = value
  end

  save
end
window() click to toggle source

@return [WindowCameraWidget]

# File lib/gphoto2/camera/configuration.rb, line 11
def window
  @window ||= get_config
end

Private Instance Methods

get_config() click to toggle source
# File lib/gphoto2/camera/configuration.rb, line 140
def get_config
  widget_ptr = FFI::MemoryPointer.new(:pointer)
  rc = gp_camera_get_config(ptr, widget_ptr, context.ptr)
  GPhoto2.check!(rc)
  widget = FFI::GPhoto2::CameraWidget.new(widget_ptr.read_pointer)
  CameraWidget.factory(widget)
end
reset() click to toggle source
# File lib/gphoto2/camera/configuration.rb, line 134
def reset
  @window = nil
  @config = nil
  @dirty = false
end
set_config() click to toggle source
# File lib/gphoto2/camera/configuration.rb, line 148
def set_config
  rc = gp_camera_set_config(ptr, window.ptr, context.ptr)
  GPhoto2.check!(rc)
end