Module: GPhoto2::Camera::Configuration

Included in:
GPhoto2::Camera
Defined in:
lib/gphoto2/camera/configuration.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ GPhoto2::CameraWidget

Returns the widget identified by ‘key`.

Examples:

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

Parameters:

  • key (#to_s)

Returns:



55
56
57
# File 'lib/gphoto2/camera/configuration.rb', line 55

def [](key)
  config[key.to_s]
end

#[]=(key, value) ⇒ Object

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.

Examples:

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

Parameters:

  • key (#to_s)
  • value (Object)

Returns:

  • (Object)

Raises:

  • (ArgumentError)


72
73
74
75
76
77
# 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

#configHash<String,GPhoto2::CameraWidget>

Returns a flat map of camera configuration widgets.

Examples:

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

Returns:

See Also:



24
25
26
# File 'lib/gphoto2/camera/configuration.rb', line 24

def config
  @config ||= window.flatten
end

#dirty?Boolean

Returns whether attributes have been changed.

Examples:

camera.dirty?
# => false

camera['iso'] = 400

camera.dirty?
# => true

Returns:

  • (Boolean)

    whether attributes have been changed



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

def dirty?
  @dirty
end

#initialize(model, port) ⇒ Object

Parameters:

  • model (String)
  • port (String)


6
7
8
# File 'lib/gphoto2/camera/configuration.rb', line 6

def initialize(model, port)
  reset
end

#reloadvoid

This method returns an undefined value.

Reloads the camera configuration.

All unsaved changes will be lost.

Examples:

camera['iso']
# => 800

camera['iso'] = 200
camera.reload

camera['iso']
# => 800


43
44
45
46
47
# File 'lib/gphoto2/camera/configuration.rb', line 43

def reload
  @window.finalize if @window
  reset
  config
end

#saveBoolean

Updates the configuration on the camera.

Examples:

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

Returns:

  • (Boolean)

    whether setting the configuration was attempted



89
90
91
92
93
94
# File 'lib/gphoto2/camera/configuration.rb', line 89

def save
  return false unless dirty?
  set_config
  @dirty = false
  true
end

#update(attributes = {}) ⇒ Boolean

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

Examples:

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

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

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

Parameters:

  • attributes (Hash<String,Object>) (defaults to: {})

Returns:

  • (Boolean)

    whether the configuration saved



110
111
112
113
114
115
116
# File 'lib/gphoto2/camera/configuration.rb', line 110

def update(attributes = {})
  attributes.each do |key, value|
    self[key] = value
  end

  save
end

#windowWindowCameraWidget

Returns:



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

def window
  @window ||= get_config
end