topherfangio-lcdproc-ruby 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. data/.document +5 -0
  2. data/.gitignore +6 -0
  3. data/LICENSE +20 -0
  4. data/README.rdoc +9 -0
  5. data/Rakefile +70 -0
  6. data/TODO +18 -0
  7. data/VERSION +1 -0
  8. data/devices/crystalfontz/packet.rb +108 -0
  9. data/devices/devices.rb +41 -0
  10. data/examples/basic.rb +39 -0
  11. data/examples/clock.rb +78 -0
  12. data/examples/lights.rb +67 -0
  13. data/lcdproc.rb +43 -0
  14. data/lib/console.rb +39 -0
  15. data/lib/core_extensions/array.rb +37 -0
  16. data/lib/core_extensions/string.rb +37 -0
  17. data/lib/includes/lcdproc.rb +27 -0
  18. data/lib/lcdproc-ruby.rb +0 -0
  19. data/lib/lcdproc/client.rb +458 -0
  20. data/lib/lcdproc/command.rb +54 -0
  21. data/lib/lcdproc/errors.rb +41 -0
  22. data/lib/lcdproc/key_event.rb +59 -0
  23. data/lib/lcdproc/menu.rb +188 -0
  24. data/lib/lcdproc/menu_event.rb +49 -0
  25. data/lib/lcdproc/menu_item.rb +108 -0
  26. data/lib/lcdproc/menu_items/action.rb +72 -0
  27. data/lib/lcdproc/menu_items/alpha.rb +85 -0
  28. data/lib/lcdproc/menu_items/checkbox.rb +76 -0
  29. data/lib/lcdproc/menu_items/ip.rb +75 -0
  30. data/lib/lcdproc/menu_items/numeric.rb +75 -0
  31. data/lib/lcdproc/menu_items/ring.rb +75 -0
  32. data/lib/lcdproc/menu_items/slider.rb +83 -0
  33. data/lib/lcdproc/menu_items/submenu.rb +77 -0
  34. data/lib/lcdproc/response.rb +65 -0
  35. data/lib/lcdproc/screen.rb +283 -0
  36. data/lib/lcdproc/widget.rb +142 -0
  37. data/lib/lcdproc/widgets/graph.rb +185 -0
  38. data/lib/lcdproc/widgets/hbar.rb +101 -0
  39. data/lib/lcdproc/widgets/icon.rb +94 -0
  40. data/lib/lcdproc/widgets/num.rb +92 -0
  41. data/lib/lcdproc/widgets/scroller.rb +110 -0
  42. data/lib/lcdproc/widgets/string.rb +94 -0
  43. data/lib/lcdproc/widgets/title.rb +90 -0
  44. data/lib/lcdproc/widgets/vbar.rb +111 -0
  45. data/script/console.rb +28 -0
  46. data/script/telnet.rb +90 -0
  47. data/tasks/test/basic.rake +82 -0
  48. data/tasks/test/keys.rake +66 -0
  49. data/tasks/test/menus.rake +74 -0
  50. metadata +104 -0
data/script/console.rb ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #-------------------------------------------------------------------------------
4
+ # Copyright (c) 2008 Topher Fangio
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person
7
+ # obtaining a copy of this software and associated documentation
8
+ # files (the "Software"), to deal in the Software without
9
+ # restriction, including without limitation the rights to use,
10
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the
12
+ # Software is furnished to do so, subject to the following
13
+ # conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be
16
+ # included in all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ # OTHER DEALINGS IN THE SOFTWARE.
26
+ #-------------------------------------------------------------------------------
27
+
28
+ require 'lib/console'
data/script/telnet.rb ADDED
@@ -0,0 +1,90 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ #-------------------------------------------------------------------------------
4
+ # Copyright (c) 2008 Topher Fangio
5
+ #
6
+ # Permission is hereby granted, free of charge, to any person
7
+ # obtaining a copy of this software and associated documentation
8
+ # files (the "Software"), to deal in the Software without
9
+ # restriction, including without limitation the rights to use,
10
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the
12
+ # Software is furnished to do so, subject to the following
13
+ # conditions:
14
+ #
15
+ # The above copyright notice and this permission notice shall be
16
+ # included in all copies or substantial portions of the Software.
17
+ #
18
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25
+ # OTHER DEALINGS IN THE SOFTWARE.
26
+ #-------------------------------------------------------------------------------
27
+
28
+
29
+ # Set our options based on the command line
30
+ require 'optparse'
31
+
32
+ options = { :host => 'localhost', :port => 13666 }
33
+
34
+ OptionParser.new do |opt|
35
+ opt.banner = "Usage: telnet [options]"
36
+ opt.on('-h', "--host[#{options[:host]}]", 'Connect to a specific host.') { |v| options[:host] = v }
37
+ opt.on('-p', "--port[#{options[:port]}]", 'Connect using a different port.') { |v| options[:port] = v }
38
+ opt.parse!(ARGV)
39
+ end
40
+
41
+
42
+ def process_responses
43
+ response = @daemon_socket.gets
44
+
45
+ ( puts " - #{response}"; @response_count += 1 ) unless response =~ /^ignore|listen/
46
+
47
+ Thread.pass
48
+ end
49
+
50
+ # Start the main program by openning a telnet session and parsing stdin
51
+ require 'socket'
52
+
53
+ @response_count = 0
54
+
55
+ puts " Opening connection to LCDd..."
56
+
57
+ begin
58
+ @daemon_socket = TCPSocket.new( options[:host], options[:port] )
59
+ puts " Connection established, Ready to send commands\n\n"
60
+
61
+ @listen = Thread.new { while true do process_responses end }
62
+
63
+ puts " Listening for responses..."
64
+
65
+ while true
66
+ rc = @response_count
67
+
68
+ print "lcdproc > "
69
+ $stdout.flush
70
+
71
+ input = $stdin.readline
72
+
73
+ if input.strip == "exit"
74
+ @daemon_socket.close
75
+ puts " *waves goodbye*\n"
76
+
77
+ break
78
+ end
79
+
80
+ @daemon_socket.write( input )
81
+
82
+ while not @response_count > rc
83
+ # Wait until we get a response
84
+ end
85
+
86
+ end
87
+
88
+ rescue Errno::ECONNREFUSED
89
+ puts " Error: Connection to '#{options[:host]}':#{options[:port]} was refused."
90
+ end
@@ -0,0 +1,82 @@
1
+ #-------------------------------------------------------------------------------
2
+ # Copyright (c) 2008 Topher Fangio
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation
6
+ # files (the "Software"), to deal in the Software without
7
+ # restriction, including without limitation the rights to use,
8
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the
10
+ # Software is furnished to do so, subject to the following
11
+ # conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ # OTHER DEALINGS IN THE SOFTWARE.
24
+ #-------------------------------------------------------------------------------
25
+
26
+
27
+ require 'lcdproc.rb'
28
+ include LCDProc
29
+
30
+ namespace :test do
31
+
32
+ desc "Runs a basic test that creates a client, attaches a screen and adds some widgets."
33
+ task :basic do
34
+ puts "=== Running Basic Test ===\n"
35
+ puts "Creating client..."
36
+ c = Client.new
37
+
38
+ puts "Creating screens..."
39
+ s1 = Screen.new
40
+ s2 = Screen.new
41
+ s3 = Screen.new
42
+ s4 = Screen.new
43
+
44
+ puts "Attaching screens..."
45
+ c.attach( s1 )
46
+ c.attach( s2 )
47
+ c.attach( s3 )
48
+ c.attach( s4 )
49
+
50
+ puts "Creating widgets..."
51
+ w1 = Widget.new( :string )
52
+ w2 = Widget.new( :hbar )
53
+ w3 = Widget.new( :vbar )
54
+ w4 = Widget.new( :graph )
55
+ w5 = Widget.new( :num )
56
+
57
+ puts "Setting up widgets..."
58
+ w2.y = rand( 2 ) + 2
59
+
60
+ w3.x = rand( 20 )
61
+ w3.height = rand( 22 ) + 10
62
+
63
+ w4.bars.each{ |bar| bar.height = rand( 22 ) + 10 }
64
+
65
+ puts "Adding widgets to screens..."
66
+ s1.add_widget( w1 )
67
+ s1.add_widget( w2 )
68
+
69
+ s2.add_widget( w3 )
70
+
71
+ s3.add_widget( w4 )
72
+
73
+ s4.add_widget( w5 )
74
+
75
+ #puts c.commands.collect{ |cmd| cmd.message }
76
+ #puts c.messages
77
+
78
+ puts "Sleeping for 10 seconds..."
79
+ sleep 10
80
+ end
81
+
82
+ end
@@ -0,0 +1,66 @@
1
+ #-------------------------------------------------------------------------------
2
+ # Copyright (c) 2008 Topher Fangio
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation
6
+ # files (the "Software"), to deal in the Software without
7
+ # restriction, including without limitation the rights to use,
8
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the
10
+ # Software is furnished to do so, subject to the following
11
+ # conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ # OTHER DEALINGS IN THE SOFTWARE.
24
+ #-------------------------------------------------------------------------------
25
+
26
+
27
+ require 'lcdproc.rb'
28
+ include LCDProc
29
+
30
+ namespace :test do
31
+
32
+ desc "Tests the registering and unregistering of keys."
33
+ task :keys do
34
+ puts "=== Running Keys Test ===\n"
35
+
36
+ puts "Creating Client and Screen"
37
+ c = Client.new
38
+ s = Screen.new
39
+
40
+ puts "Attaching Screen"
41
+ c.attach( s )
42
+
43
+ kel = KeyEvent.new( 'Left' ) { puts "Left Key Pressed" }
44
+ ker = KeyEvent.new( 'Right' ) { puts "Right Key Pressed" }
45
+ keu = KeyEvent.new( 'Up' ) { puts "Up Key Pressed" }
46
+ ked = KeyEvent.new( 'Down' ) { puts "Down Key Pressed" }
47
+ keen = KeyEvent.new( 'Enter' ) { puts "Enter Key Pressed" }
48
+ kees = KeyEvent.new( 'Escape' ) { puts "Escape Key Pressed" }
49
+
50
+ puts "Registering new Key Event (Left Key) for 10 seconds..."
51
+ s.register_key_event( kel )
52
+
53
+ sleep( 10 )
54
+
55
+ puts "Unregistering Key Event (Left Key)"
56
+ s.unregister_key_event( kel )
57
+
58
+ puts "Registering all events..."
59
+ [ kel, ker, keu, ked, keen, kees ].each do |event|
60
+ s.register_key_event( event )
61
+ end
62
+
63
+ sleep( 30 )
64
+ end
65
+
66
+ end
@@ -0,0 +1,74 @@
1
+ #-------------------------------------------------------------------------------
2
+ # Copyright (c) 2008 Topher Fangio
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person
5
+ # obtaining a copy of this software and associated documentation
6
+ # files (the "Software"), to deal in the Software without
7
+ # restriction, including without limitation the rights to use,
8
+ # copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the
10
+ # Software is furnished to do so, subject to the following
11
+ # conditions:
12
+ #
13
+ # The above copyright notice and this permission notice shall be
14
+ # included in all copies or substantial portions of the Software.
15
+ #
16
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
+ # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
+ # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
+ # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
+ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
+ # OTHER DEALINGS IN THE SOFTWARE.
24
+ #-------------------------------------------------------------------------------
25
+
26
+
27
+ require 'lcdproc.rb'
28
+ include LCDProc
29
+
30
+ def my_cool_slider_callback( value )
31
+ puts "Current Slider Value: #{value}"
32
+ end
33
+
34
+ namespace :test do
35
+
36
+ desc "Runs a test that creates a variety menus attached to a client."
37
+ task :menus do
38
+ puts "=== Running Menus Test ===\n"
39
+
40
+ c = Client.new( :name => 'MenuTest' )
41
+
42
+ action_nothing = c.menu.add_item( MenuItem.new( :action, { :id => 'nothing' }, { :text => 'I Do Nothing' } ) )
43
+
44
+ ring_manual = MenuItem.new( :ring, { :id => 'Ring' }, { :text => 'ManualRing', :strings => [ 'Yes', 'No', 'Whatever' ].join('\t') } )
45
+ c.menu.add_item( ring_manual )
46
+ c.register_menu_event( MenuEvent.new( ring_manual ) { |response| puts "Ring: " + response.split(' ')[-1].to_s } )
47
+
48
+ checkbox_boom = c.menu.add_item( MenuItem.new( :checkbox, { :id => 'Boom'}, { :text => 'Boom', :allow_gray => true } ) ) { |response| puts response.split(' ')[-1] }
49
+
50
+ slider = c.menu.add_item( MenuItem.new( :slider, { :id => 'Fluidity' } ) ) { |r| my_cool_slider_callback( r.split(' ')[-1] ) }
51
+
52
+ alpha = c.menu.add_item( MenuItem.new( :alpha, { :id => 'AlphaText' }, { :value => "Abstract" } ) ) { |r| puts "Alpha value updated to #{r.split(' ')[-1] }" }
53
+
54
+ ip = c.menu.add_item( MenuItem.new( :ip, { :id => 'LocalIP' } ) ) { |r| puts "IP: #{r.split(' ')[-1]}" }
55
+
56
+ submenu = c.menu.add_item( MenuItem.new( :submenu, { :id => "SubMenu", :text => "Sub Menu" } ) )
57
+ submenu_action_noperrs = submenu.add_item( MenuItem.new( :action, :id => 'Noperrs' ) ) { |r| puts r.split(' ')[-1] }
58
+ submenu_submenu = submenu.add_item( MenuItem.new( :submenu, { :id => 'Subber' }, :text => 'Subber' ) ) { |r| puts r.split(' ')[-1] }
59
+ submenu_submenu_checkbox = submenu_submenu.add_item( MenuItem.new( :checkbox, { :id => 'Checkers' }, :text => 'Check Me' ) ) { |r| puts r.split(' ')[-1] }
60
+
61
+
62
+ #puts "\nCommands: " + c.commands.collect{ |cmd| cmd.message }.inspect
63
+ #puts "\nMessages: " + c.messages.inspect
64
+ #puts "\nMenu Items: " + c.menu.items.inspect
65
+ #puts "\nMenu Events: " + c.menu_events.inspect
66
+
67
+
68
+ sleep_time = 500
69
+
70
+ puts "Sleeping for #{sleep_time} seconds..."
71
+ sleep sleep_time
72
+ end
73
+
74
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: topherfangio-lcdproc-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - topherfangio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-19 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: fangiotophia@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - LICENSE
24
+ - README.rdoc
25
+ files:
26
+ - .document
27
+ - .gitignore
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - TODO
32
+ - VERSION
33
+ - devices/crystalfontz/packet.rb
34
+ - devices/devices.rb
35
+ - examples/basic.rb
36
+ - examples/clock.rb
37
+ - examples/lights.rb
38
+ - lcdproc.rb
39
+ - lib/console.rb
40
+ - lib/core_extensions/array.rb
41
+ - lib/core_extensions/string.rb
42
+ - lib/includes/lcdproc.rb
43
+ - lib/lcdproc-ruby.rb
44
+ - lib/lcdproc/client.rb
45
+ - lib/lcdproc/command.rb
46
+ - lib/lcdproc/errors.rb
47
+ - lib/lcdproc/key_event.rb
48
+ - lib/lcdproc/menu.rb
49
+ - lib/lcdproc/menu_event.rb
50
+ - lib/lcdproc/menu_item.rb
51
+ - lib/lcdproc/menu_items/action.rb
52
+ - lib/lcdproc/menu_items/alpha.rb
53
+ - lib/lcdproc/menu_items/checkbox.rb
54
+ - lib/lcdproc/menu_items/ip.rb
55
+ - lib/lcdproc/menu_items/numeric.rb
56
+ - lib/lcdproc/menu_items/ring.rb
57
+ - lib/lcdproc/menu_items/slider.rb
58
+ - lib/lcdproc/menu_items/submenu.rb
59
+ - lib/lcdproc/response.rb
60
+ - lib/lcdproc/screen.rb
61
+ - lib/lcdproc/widget.rb
62
+ - lib/lcdproc/widgets/graph.rb
63
+ - lib/lcdproc/widgets/hbar.rb
64
+ - lib/lcdproc/widgets/icon.rb
65
+ - lib/lcdproc/widgets/num.rb
66
+ - lib/lcdproc/widgets/scroller.rb
67
+ - lib/lcdproc/widgets/string.rb
68
+ - lib/lcdproc/widgets/title.rb
69
+ - lib/lcdproc/widgets/vbar.rb
70
+ - script/console.rb
71
+ - script/telnet.rb
72
+ - tasks/test/basic.rake
73
+ - tasks/test/keys.rake
74
+ - tasks/test/menus.rake
75
+ has_rdoc: true
76
+ homepage: http://github.com/topherfangio/lcdproc-ruby
77
+ post_install_message:
78
+ rdoc_options:
79
+ - --charset=UTF-8
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: "0"
87
+ version:
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - ">="
91
+ - !ruby/object:Gem::Version
92
+ version: "0"
93
+ version:
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.2.0
98
+ signing_key:
99
+ specification_version: 2
100
+ summary: A Ruby library to interface with LCDProc.
101
+ test_files:
102
+ - examples/basic.rb
103
+ - examples/clock.rb
104
+ - examples/lights.rb