topherfangio-lcdproc-ruby 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ *.sw?
2
+ .project
3
+ .DS_Store
4
+ coverage
5
+ rdoc
6
+ pkg
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 topherfangio
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,9 @@
1
+ =Introduction
2
+ LCDProc-Ruby is an object-oriented API to the LCDProc server LCDd.
3
+
4
+ To get started, take a look at LCDProc::Client since it is the main
5
+ interface to LCDd. If you are interested in the status of development,
6
+ head over to the TODO to see what outstanding bugs are listed as well
7
+ as an overview of the features that are yet to be implemented.
8
+
9
+ LCDProc-Ruby is released under the open source MIT license.
data/Rakefile ADDED
@@ -0,0 +1,70 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "lcdproc-ruby"
8
+ gem.summary = %Q{A Ruby library to interface with LCDProc.}
9
+ gem.email = "fangiotophia@gmail.com"
10
+ gem.homepage = "http://github.com/topherfangio/lcdproc-ruby"
11
+ gem.authors = ["topherfangio"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
18
+
19
+ require 'rake/testtask'
20
+ Rake::TestTask.new(:test) do |test|
21
+ test.libs << 'lib/tasks/test' << 'test'
22
+ test.pattern = 'test/**/*_test.rb'
23
+ test.verbose = true
24
+ end
25
+
26
+ begin
27
+ require 'rcov/rcovtask'
28
+ Rcov::RcovTask.new do |test|
29
+ test.libs << 'test'
30
+ test.pattern = 'test/**/*_test.rb'
31
+ test.verbose = true
32
+ end
33
+ rescue LoadError
34
+ task :rcov do
35
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
36
+ end
37
+ end
38
+
39
+
40
+ task :default => :test
41
+
42
+ require 'rake/rdoctask'
43
+ Rake::RDocTask.new do |rdoc|
44
+ if File.exist?('VERSION.yml')
45
+ config = YAML.load(File.read('VERSION.yml'))
46
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
47
+ else
48
+ version = ""
49
+ end
50
+
51
+ rdoc.rdoc_dir = 'rdoc'
52
+ rdoc.title = "lcdproc-ruby #{version}"
53
+ rdoc.rdoc_files.include('README*')
54
+ rdoc.rdoc_files.include('TODO*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ rdoc.rdoc_files.include('devices/**/*.rb')
57
+
58
+ # Show all methods including private ones
59
+ rdoc.options << '--all'
60
+ # Show line numbers and source code
61
+ rdoc.options << '--line-numbers' << '--inline-source'
62
+ end
63
+
64
+ # Load lcdproc-ruby specific tasks
65
+ require 'find'
66
+ Find.find( "tasks/test" ) do |file|
67
+ if File.basename( file ) =~ /\.rake$/
68
+ load File.expand_path( file )
69
+ end
70
+ end
data/TODO ADDED
@@ -0,0 +1,18 @@
1
+ =Introduction
2
+
3
+ Currently, I am still in the process of stating all of the features that I would like to implement for the 1.0
4
+ release. Many aspects of the program are in a working condition and can be used to create a basic program that
5
+ talks to the LCDd server. I hope to add much functionality over the next few months and to ensure that the code
6
+ structure enables easy extension by other developers (and myself).
7
+
8
+ =Bug Fixes
9
+
10
+ Bug fixes are any code/design changes that need to be implemented in order for the API to function properly or
11
+ conform to standards.
12
+
13
+ * Horizontal bar graphs should be able to handle a percentage or a regular integer
14
+ * The <tt>menu_add_item</tt> command currently returns two responses and I have inserted a hack to get it to work, a cleaner solution is desired
15
+
16
+ =Future Enhancements
17
+
18
+ Any feature requests will be documented here until they can be fully implemented and added into the existing API.
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.1
@@ -0,0 +1,108 @@
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
+ module LCDProc
28
+ module Devices
29
+ module Crystalfontz
30
+
31
+ module Packet
32
+ VALID_KEYS = [ "Escape", "Enter", "Up", "Down", "Left", "Right" ]
33
+
34
+ @drives_devices = [ "CrystalFontz Driver: CFA-635" ]
35
+
36
+ LCDProc::Devices.send( :include, self )
37
+
38
+
39
+ def Packet.drives?( search )
40
+ @drives_devices.include? search
41
+ end
42
+
43
+
44
+ # Called before initialization takes place.
45
+ def before_initialize( options = {} )
46
+ # Do nothing
47
+ end
48
+
49
+
50
+ # Called after initialization takes place.
51
+ def after_initialize( options = {} )
52
+ @leds = { 0 => 0, 1 => 0, 2 => 0, 3 => 0 }
53
+ end
54
+
55
+
56
+ # Make the specified leds light up.
57
+ #
58
+ # * <tt>leds</tt> - The leds that you wish to light. They may be specified as a single number, a range (1..3), an array [0,2] or the special parameter :all.
59
+ # * <tt>color</tt> - The color that you wish to light the leds. Valid options are :off, :green, :orange, or :red.
60
+ def light_leds( leds, color )
61
+
62
+ if leds == :all
63
+ leds_to_light = @leds.keys
64
+ elsif leds.kind_of? Range
65
+ leds_to_light = leds.to_a
66
+ else
67
+ leds_to_light = ( leds.kind_of?( Array ) ? leds : [ leds ] )
68
+ end
69
+
70
+ if leds_to_light.max > @leds.keys.max
71
+ add_message( "Error: Led '#{leds_to_light.max}' does not correspond to an actual led." )
72
+ return false
73
+ end
74
+
75
+ case color
76
+ when :off
77
+ leds_to_light.each{ |l| @leds[l] = 0 }
78
+ when :green
79
+ leds_to_light.each{ |l| @leds[l] = 2 ** l }
80
+ when :orange
81
+ leds_to_light.each{ |l| @leds[l] = 2 ** l * 16 + 2 ** l }
82
+ when :red
83
+ leds_to_light.each{ |l| @leds[l] = 2 ** l * 16 }
84
+ else
85
+ add_message( "Error: Unknown color '#{color}'" )
86
+ return false
87
+ end
88
+
89
+ command = Command.new( "output #{ @leds.values.sum }" )
90
+ response = send_command( command )
91
+
92
+ if response.successful?
93
+ add_message( "Leds #{leds_to_light} were correctly lit" )
94
+ return true
95
+ else
96
+ add_message( "Leds #{leds_to_light} were NOT correctly lit (#{response.message})" )
97
+ return false
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+
104
+ end
105
+
106
+ end
107
+
108
+ end
@@ -0,0 +1,41 @@
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
+ module LCDProc
28
+
29
+ module Devices
30
+
31
+ def Devices.included_in
32
+ ancestors - [ self ]
33
+ end
34
+
35
+ def Devices.find_all_that_drive( search )
36
+ Devices.included_in.select { |mod| mod.drives?(search.strip) }
37
+ end
38
+
39
+ end
40
+
41
+ end
data/examples/basic.rb ADDED
@@ -0,0 +1,39 @@
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
+
29
+ include LCDProc
30
+
31
+ c = Client.new( :name => "My Client", :host => "localhost" )
32
+ s = Screen.new( "Test" )
33
+
34
+ c.attach( s )
35
+ graph = Widget.new( :graph )
36
+
37
+ s.add_widget(graph)
38
+
39
+ 10.times { graph.bars.each { |bar| bar.height = rand(22) + 5 }; s.update; sleep 1 }
data/examples/clock.rb ADDED
@@ -0,0 +1,78 @@
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
+ # Example: clock.rb
29
+ # Author: Topher Fangio
30
+ # Date: 9.17.2008
31
+ #
32
+ # Purpose: This program displays a simple clock on the LCD that updates every 5 seconds.
33
+ # This will most likely be extracted into it's own Widget at a later date, but
34
+ # it makes a very good beginners example for now.
35
+
36
+ require "lcdproc"
37
+
38
+ include LCDProc
39
+
40
+ c = Client.new( :host => "localhost" )
41
+ s = Screen.new("clock")
42
+
43
+ hour1 = Widgets::Num.new("hour1", 0, 3)
44
+ hour2 = Widgets::Num.new("hour2", 1, 7)
45
+ colon = Widgets::Num.new("colon", 10, 10)
46
+ minute1 = Widgets::Num.new("minute1", 0, 12)
47
+ minute2 = Widgets::Num.new("minute2", 0, 16)
48
+
49
+ s.add_widget(hour1)
50
+ s.add_widget(hour2)
51
+ s.add_widget(colon)
52
+ s.add_widget(minute1)
53
+ s.add_widget(minute2)
54
+
55
+ c.attach( s )
56
+
57
+ while true do
58
+ t = Time.new
59
+
60
+ if (t.hour > 10)
61
+ hour1.number = t.hour / 10
62
+ hour2.number = t.hour % 10
63
+ else
64
+ hour1.number = 0
65
+ hour2.number = t.hour
66
+ end
67
+
68
+ if (t.min > 10)
69
+ minute1.number = t.min / 10
70
+ minute2.number = t.min % 10
71
+ else
72
+ minute1.number = 0
73
+ minute2.number = t.min
74
+ end
75
+
76
+ s.update
77
+ sleep 5
78
+ end
@@ -0,0 +1,67 @@
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
+ # Example: lights.rb
29
+ # Author: Topher Fangio
30
+ # Date: 9.17.2008
31
+ #
32
+ # Purpose: This program iterates through the available lights and turns them red.
33
+ # Note that at the moment, only one device has been defined that supports
34
+ # leds, the CrystalFontz display defined in devices/crystalfontz/packet.rb.
35
+
36
+ require "lcdproc"
37
+ include LCDProc
38
+
39
+ # Setup our client
40
+ c = Client.new( :host => "192.168.1.142" )
41
+
42
+ @current_led = 0
43
+ @color = :red
44
+
45
+ # Define a method to modify the current led
46
+ def move_current_led(direction)
47
+ @current_led += direction
48
+
49
+ if (@current_led > 3)
50
+ @current_led = 0
51
+ end
52
+
53
+ if (@current_led < 0)
54
+ @current_led = 3
55
+ end
56
+
57
+ return @current_led
58
+ end
59
+
60
+ while true
61
+ c.light_leds(:all, :off)
62
+ c.light_leds(@current_led, :red)
63
+
64
+ move_current_led(1)
65
+
66
+ sleep 1
67
+ end