Class: Seriamp::Sonamp::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/seriamp/sonamp/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(device: nil, glob: nil, logger: nil, retries: true, timeout: nil, thread_safe: false) ⇒ Client

Returns a new instance of Client.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/seriamp/sonamp/client.rb', line 13

def initialize(device: nil, glob: nil, logger: nil, retries: true,
  timeout: nil, thread_safe: false
)
  @logger = logger

  @device = device
  @detect_device = device.nil?
  @glob = glob
  @retries = case retries
    when nil, false
      0
    when true
      1
    when Integer
      retries
    else
      raise ArgumentError, "retries must be an integer, true, false or nil: #{retries}"
    end
  @timeout = timeout || DEFAULT_RS232_TIMEOUT
  @thread_safe = !!thread_safe

  if thread_safe?
    @lock = Mutex.new
  end
end

Instance Attribute Details

#deviceObject (readonly)

Returns the value of attribute device.



39
40
41
# File 'lib/seriamp/sonamp/client.rb', line 39

def device
  @device
end

#globObject (readonly)

Returns the value of attribute glob.



40
41
42
# File 'lib/seriamp/sonamp/client.rb', line 40

def glob
  @glob
end

#loggerObject (readonly)

Returns the value of attribute logger.



41
42
43
# File 'lib/seriamp/sonamp/client.rb', line 41

def logger
  @logger
end

#retriesObject (readonly)

Returns the value of attribute retries.



42
43
44
# File 'lib/seriamp/sonamp/client.rb', line 42

def retries
  @retries
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



43
44
45
# File 'lib/seriamp/sonamp/client.rb', line 43

def timeout
  @timeout
end

Instance Method Details

#detect_device?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/seriamp/sonamp/client.rb', line 49

def detect_device?
  @detect_device
end

#get_auto_trigger_input(zone = nil) ⇒ Object



156
157
158
# File 'lib/seriamp/sonamp/client.rb', line 156

def get_auto_trigger_input(zone = nil)
  get_zone_state('ATI', zone)
end

#get_bbe(zone = nil) ⇒ Object



132
133
134
# File 'lib/seriamp/sonamp/client.rb', line 132

def get_bbe(zone = nil)
  get_zone_state('BP', zone)
end

#get_bbe_high_boost(zone = nil) ⇒ Object



144
145
146
# File 'lib/seriamp/sonamp/client.rb', line 144

def get_bbe_high_boost(zone = nil)
  get_zone_state('BH', zone)
end

#get_bbe_low_boost(zone = nil) ⇒ Object



152
153
154
# File 'lib/seriamp/sonamp/client.rb', line 152

def get_bbe_low_boost(zone = nil)
  get_zone_state('BL', zone)
end

#get_channel_front_panel_level(channel = nil) ⇒ Object



120
121
122
# File 'lib/seriamp/sonamp/client.rb', line 120

def get_channel_front_panel_level(channel = nil)
  get_channel_value('TVL', channel)
end

#get_channel_mute(channel = nil) ⇒ Object



116
117
118
# File 'lib/seriamp/sonamp/client.rb', line 116

def get_channel_mute(channel = nil)
  get_channel_state('MC', channel)
end

#get_channel_volume(channel = nil) ⇒ Object



92
93
94
# File 'lib/seriamp/sonamp/client.rb', line 92

def get_channel_volume(channel = nil)
  get_channel_value('VC', channel)
end

#get_firmware_versionObject



164
165
166
# File 'lib/seriamp/sonamp/client.rb', line 164

def get_firmware_version
  global_query('VER')
end

#get_temperatureObject



168
169
170
# File 'lib/seriamp/sonamp/client.rb', line 168

def get_temperature
  Integer(global_query('TP'))
end

#get_voltage_trigger_input(zone = nil) ⇒ Object



160
161
162
# File 'lib/seriamp/sonamp/client.rb', line 160

def get_voltage_trigger_input(zone = nil)
  get_zone_state('VTI', zone, include_all: true)
end

#get_zone_fault(zone = nil) ⇒ Object



124
125
126
# File 'lib/seriamp/sonamp/client.rb', line 124

def get_zone_fault(zone = nil)
  get_zone_state('FP', zone)
end

#get_zone_mute(zone = nil) ⇒ Object



112
113
114
# File 'lib/seriamp/sonamp/client.rb', line 112

def get_zone_mute(zone = nil)
  get_zone_state('M', zone)
end

#get_zone_power(zone = nil) ⇒ Object



58
59
60
# File 'lib/seriamp/sonamp/client.rb', line 58

def get_zone_power(zone = nil)
  get_zone_state('P', zone)
end

#get_zone_volume(zone = nil) ⇒ Object



77
78
79
# File 'lib/seriamp/sonamp/client.rb', line 77

def get_zone_volume(zone = nil)
  get_zone_value('V', zone)
end

#power_offObject



71
72
73
74
75
# File 'lib/seriamp/sonamp/client.rb', line 71

def power_off
  1.upto(4).each do |zone|
    set_zone_power(zone, false)
  end
end

#present?Boolean

Returns:

  • (Boolean)


53
54
55
56
# File 'lib/seriamp/sonamp/client.rb', line 53

def present?
  get_zone_power(1)
  true
end

#set_bbe(zone, state) ⇒ Object



128
129
130
# File 'lib/seriamp/sonamp/client.rb', line 128

def set_bbe(zone, state)
  set_zone_value('BP', zone, state ? 1 : 0)
end

#set_bbe_boost(zone, state) ⇒ Object



136
137
138
# File 'lib/seriamp/sonamp/client.rb', line 136

def set_bbe_boost(zone, state)
  set_zone_value('BB', zone, convert_boolean_out(state))
end

#set_bbe_high_boost(zone, state) ⇒ Object



140
141
142
# File 'lib/seriamp/sonamp/client.rb', line 140

def set_bbe_high_boost(zone, state)
  set_zone_value('BH', zone, convert_boolean_out(state))
end

#set_bbe_low_boost(zone, state) ⇒ Object



148
149
150
# File 'lib/seriamp/sonamp/client.rb', line 148

def set_bbe_low_boost(zone, state)
  set_zone_value('BL', zone, convert_boolean_out(state))
end

#set_channel_mute(channel, state) ⇒ Object



108
109
110
# File 'lib/seriamp/sonamp/client.rb', line 108

def set_channel_mute(channel, state)
  set_channel_value('MC', channel, state ? 1 : 0)
end

#set_channel_volume(channel, volume) ⇒ Object



96
97
98
99
100
101
102
103
104
105
106
# File 'lib/seriamp/sonamp/client.rb', line 96

def set_channel_volume(channel, volume)
  if channel < 1 || channel > 8
    raise ArgumentError, "Channel must be between 1 and 4: #{channel}"
  end
  if volume < 0 || volume > 100
    raise ArgumentError, "Volume must be between 0 and 100: #{volume}"
  end
  cmd = ":VC#{channel}#{volume}"
  expected = cmd[1...cmd.length]
  dispatch_assert(cmd, expected)
end

#set_zone_mute(zone, state) ⇒ Object



88
89
90
# File 'lib/seriamp/sonamp/client.rb', line 88

def set_zone_mute(zone, state)
  set_zone_value('M', zone, state ? 1 : 0)
end

#set_zone_power(zone, state) ⇒ Object



62
63
64
65
66
67
68
69
# File 'lib/seriamp/sonamp/client.rb', line 62

def set_zone_power(zone, state)
  if zone < 1 || zone > 4
    raise ArgumentError, "Zone must be between 1 and 4: #{zone}"
  end
  cmd = ":P#{zone}#{state ? 1 : 0}"
  expected = cmd[1...cmd.length]
  dispatch_assert(cmd, expected)
end

#set_zone_volume(zone, volume) ⇒ Object



81
82
83
84
85
86
# File 'lib/seriamp/sonamp/client.rb', line 81

def set_zone_volume(zone, volume)
  if volume < 0 || volume > 100
    raise ArgumentError, "Volume must be between 0 and 100: #{volume}"
  end
  set_zone_value('V', zone, volume)
end

#statusObject



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
# File 'lib/seriamp/sonamp/client.rb', line 172

def status
  # Reusing the opened device file makes :VTIG? fail even with a delay
  # in front.
  with_device do
    {
      firmware_version: get_firmware_version,
      temperature: get_temperature,
      zone_power: get_zone_power,
      zone_fault: get_zone_fault,
      zone_volume: get_zone_volume,
      channel_volume: get_channel_volume,
      zone_mute: get_zone_mute,
      channel_mute: get_channel_mute,
      bbe: get_bbe,
      bbe_high_boost: get_bbe_high_boost,
      bbe_low_boost: get_bbe_low_boost,
      auto_trigger_input: get_auto_trigger_input,
      voltage_trigger_input: get_voltage_trigger_input,
      channel_front_panel_level: get_channel_front_panel_level,
    }
  end
end

#thread_safe?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/seriamp/sonamp/client.rb', line 45

def thread_safe?
  @thread_safe
end