Class: Net::PNS
- Inherits:
-
Object
show all
- Defined in:
- lib/net/pns.rb,
lib/net/pns/version.rb
Defined Under Namespace
Classes: LightError, PlayError
Constant Summary
collapse
- KEYS =
command keys: :red, :yellow, :green, :blue, :white, :buzzer command values (colors): :off, :on, :blink1, :blink2, :keep (default) command values (buzzer): :off, :buzz1, :buzz2, :buzz3, :buzz4, :keep (default)
[:red, :yellow, :green, :blue, :write, :buzzer]
- VALUES =
{
0 => 0, 1 => 1, 2 => 2, 3 => 3, 4 => 4, 9 => 9,
off: 0, on: 1, blink1: 2, blink2: 3, keep: 9,
buzz1: 1, buzz2: 2, buzz3: 3, buzz4: 4,
}
- PATTERN =
{0 => 0, 1 => 1, stop: 0, play: 1}
- VERSION =
"0.0.1"
Instance Method Summary
collapse
Constructor Details
#initialize(host, port = 10000, type = 'XX') ⇒ PNS
Returns a new instance of PNS.
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/net/pns.rb', line 9
def initialize(host, port = 10000, type = 'XX')
@socket = TCPSocket.new(host, port)
@type = type.unpack('CC')
if block_given?
begin
yield self
ensure
close
end
end
end
|
Instance Method Details
#clear ⇒ Object
49
50
51
|
# File 'lib/net/pns.rb', line 49
def clear
send('C', [], 1)
end
|
#close ⇒ Object
53
54
55
56
|
# File 'lib/net/pns.rb', line 53
def close
@socket.close
@socket = nil
end
|
#light(command) ⇒ Object
33
34
35
36
37
|
# File 'lib/net/pns.rb', line 33
def light(command)
cmd = KEYS.map{|c| [c, VALUES[command[c]] || 9]}.to_h.values
ret = send('S', cmd, 1).unpack('C')[0]
raise LightError.new unless ret == 0x06
end
|
#play_sound(ch, pattern = :play, repeat = 0) ⇒ Object
44
45
46
47
|
# File 'lib/net/pns.rb', line 44
def play_sound(ch, pattern = :play, repeat = 0)
ret = send('V', [PATTERN[pattern] || 1, repeat, 0, ch], 1)
raise PlayError.new unless ret == 0x06
end
|
#stat ⇒ Object
39
40
41
|
# File 'lib/net/pns.rb', line 39
def stat
return send('G', [], 6).unpack('C*')
end
|