Class: Rubycam::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/rubycam/controls.rb

Overview

A single camera control (brightness, zoom_absolute, ...) discovered via VIDIOC_QUERYCTRL. Reading and writing goes through the owning device.

Constant Summary collapse

TYPES =
{ 1 => :integer, 2 => :boolean, 3 => :menu, 4 => :button,
5 => :integer64, 6 => :ctrl_class, 7 => :string, 8 => :bitmask,
9 => :integer_menu }.freeze
FLAG_DISABLED =
0x0001
FLAG_GRABBED =
0x0002
FLAG_READ_ONLY =
0x0004
FLAG_INACTIVE =
0x0010

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device, id:, type:, name:, min:, max:, step:, default:, flags:) ⇒ Control

Returns a new instance of Control.



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/rubycam/controls.rb', line 16

def initialize(device, id:, type:, name:, min:, max:, step:, default:, flags:)
  @device = device
  @id = id
  @type = TYPES.fetch(type, type)
  @name = name
  @min = min
  @max = max
  @step = step
  @default = default
  @flags = flags
end

Instance Attribute Details

#defaultObject (readonly)

Returns the value of attribute default.



14
15
16
# File 'lib/rubycam/controls.rb', line 14

def default
  @default
end

#flagsObject (readonly)

Returns the value of attribute flags.



14
15
16
# File 'lib/rubycam/controls.rb', line 14

def flags
  @flags
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/rubycam/controls.rb', line 14

def id
  @id
end

#maxObject (readonly)

Returns the value of attribute max.



14
15
16
# File 'lib/rubycam/controls.rb', line 14

def max
  @max
end

#minObject (readonly)

Returns the value of attribute min.



14
15
16
# File 'lib/rubycam/controls.rb', line 14

def min
  @min
end

#nameObject (readonly)

Returns the value of attribute name.



14
15
16
# File 'lib/rubycam/controls.rb', line 14

def name
  @name
end

#stepObject (readonly)

Returns the value of attribute step.



14
15
16
# File 'lib/rubycam/controls.rb', line 14

def step
  @step
end

#typeObject (readonly)

Returns the value of attribute type.



14
15
16
# File 'lib/rubycam/controls.rb', line 14

def type
  @type
end

Instance Method Details

#inactive?Boolean

Returns:

  • (Boolean)


38
# File 'lib/rubycam/controls.rb', line 38

def inactive? = flags & FLAG_INACTIVE != 0

#keyObject

Symbol key derived from the control name, e.g. "Zoom, Absolute" => :zoom_absolute



29
# File 'lib/rubycam/controls.rb', line 29

def key = @key ||= name.downcase.gsub(/[^a-z0-9]+/, '_').gsub(/^_|_$/, '').to_sym

#read_only?Boolean

Returns:

  • (Boolean)


39
# File 'lib/rubycam/controls.rb', line 39

def read_only? = flags & FLAG_READ_ONLY != 0

#to_sObject



41
42
43
# File 'lib/rubycam/controls.rb', line 41

def to_s
  "#{key} (#{type}) min=#{min} max=#{max} step=#{step} default=#{default} value=#{value}"
end

#valueObject



31
# File 'lib/rubycam/controls.rb', line 31

def value = @device.get_control(id)

#value=(v) ⇒ Object



33
34
35
36
# File 'lib/rubycam/controls.rb', line 33

def value=(v)
  clamped = v.clamp(min, max)
  @device.set_control(id, clamped)
end