-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.rb
executable file
·106 lines (83 loc) · 1.89 KB
/
demo.rb
1
2
3
4
5
6
7
8
9
10
11
12
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/env ruby
require 'bundler/setup'
require 'pp'
require 'eventmachine'
require_relative 'denon'
class DemoDenon < Denon
def on_network_button(id)
super
puts "Button #{id} pressed and the source is Network"
end
def on_cd_button(id)
super
puts "Button #{id} pressed and the source is CD"
end
def on_analog1_button(id)
super
puts "Button #{id} pressed and the source is Analog 1"
end
def on_analog2_button(id)
super
puts "Button #{id} pressed and the source is Analog 2"
end
def on_digital_button(id)
super
puts "Button #{id} pressed and the source is Digital"
end
def on_display_brightness(brightness)
super
puts "Display brightness set to #{brightness}"
end
def on_cd_function(function)
super
puts "Set CD function to #{function}"
end
def on_network_function(function)
super
puts "Set Network function to #{function}"
end
def on_volume(vol)
super
puts "Volume is #{vol}"
end
def on_mute(status)
super
puts "Mute status is #{status}"
end
def on_sleep_timer(time)
super
puts "Sleep timer set to #{time}"
end
def on_source(source)
super
puts "Source set to #{source}"
end
def on_amp_on
super
puts "Amp is on"
end
def on_amp_off
super
puts "Amp is off"
end
def on_radio(what)
puts "Radio operation #{what} happened, see @status"
end
end
class KeyboardHandler < EM::Connection # this is for demo only
include EM::Protocols::LineText2
def initialize(denon)
@denon = denon
@a = 0
end
def receive_line(data)
@denon.send_command "PWSTANDBY"
# pp @denon.status
end
end
EventMachine.run do
sp = SerialPort.open("/dev/ttyUSB0", 115200, 8, 1, SerialPort::NONE)
denon = EventMachine.attach sp, DemoDenon
EventMachine.open_keyboard KeyboardHandler, denon
puts "Press enter to see receiver status"
end