topherfangio-lcdproc-ruby 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +6 -0
- data/LICENSE +20 -0
- data/README.rdoc +9 -0
- data/Rakefile +70 -0
- data/TODO +18 -0
- data/VERSION +1 -0
- data/devices/crystalfontz/packet.rb +108 -0
- data/devices/devices.rb +41 -0
- data/examples/basic.rb +39 -0
- data/examples/clock.rb +78 -0
- data/examples/lights.rb +67 -0
- data/lcdproc.rb +43 -0
- data/lib/console.rb +39 -0
- data/lib/core_extensions/array.rb +37 -0
- data/lib/core_extensions/string.rb +37 -0
- data/lib/includes/lcdproc.rb +27 -0
- data/lib/lcdproc-ruby.rb +0 -0
- data/lib/lcdproc/client.rb +458 -0
- data/lib/lcdproc/command.rb +54 -0
- data/lib/lcdproc/errors.rb +41 -0
- data/lib/lcdproc/key_event.rb +59 -0
- data/lib/lcdproc/menu.rb +188 -0
- data/lib/lcdproc/menu_event.rb +49 -0
- data/lib/lcdproc/menu_item.rb +108 -0
- data/lib/lcdproc/menu_items/action.rb +72 -0
- data/lib/lcdproc/menu_items/alpha.rb +85 -0
- data/lib/lcdproc/menu_items/checkbox.rb +76 -0
- data/lib/lcdproc/menu_items/ip.rb +75 -0
- data/lib/lcdproc/menu_items/numeric.rb +75 -0
- data/lib/lcdproc/menu_items/ring.rb +75 -0
- data/lib/lcdproc/menu_items/slider.rb +83 -0
- data/lib/lcdproc/menu_items/submenu.rb +77 -0
- data/lib/lcdproc/response.rb +65 -0
- data/lib/lcdproc/screen.rb +283 -0
- data/lib/lcdproc/widget.rb +142 -0
- data/lib/lcdproc/widgets/graph.rb +185 -0
- data/lib/lcdproc/widgets/hbar.rb +101 -0
- data/lib/lcdproc/widgets/icon.rb +94 -0
- data/lib/lcdproc/widgets/num.rb +92 -0
- data/lib/lcdproc/widgets/scroller.rb +110 -0
- data/lib/lcdproc/widgets/string.rb +94 -0
- data/lib/lcdproc/widgets/title.rb +90 -0
- data/lib/lcdproc/widgets/vbar.rb +111 -0
- data/script/console.rb +28 -0
- data/script/telnet.rb +90 -0
- data/tasks/test/basic.rake +82 -0
- data/tasks/test/keys.rake +66 -0
- data/tasks/test/menus.rake +74 -0
- metadata +104 -0
@@ -0,0 +1,92 @@
|
|
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 Widgets
|
30
|
+
|
31
|
+
class Num
|
32
|
+
include LCDProc::Widget
|
33
|
+
LCDProc::Widget.add_support( :num, self )
|
34
|
+
|
35
|
+
attr_accessor :x, :number
|
36
|
+
|
37
|
+
@@widget_count = 0
|
38
|
+
|
39
|
+
|
40
|
+
# Creates a new Num widget which can then be displayed anywhere on the screen.
|
41
|
+
#
|
42
|
+
# * <tt>:id</tt> - A unique string which identifies this widget. Defaults to "NumWidget_" + a sequence number.
|
43
|
+
# * <tt>:num</tt> - The number that you wish to display on the screen. Default to 1.
|
44
|
+
# * <tt>:col</tt> - The column in which you wish to display the num on screen. Defaults to 1.
|
45
|
+
#
|
46
|
+
# Example:
|
47
|
+
#
|
48
|
+
# w = Num.new
|
49
|
+
#
|
50
|
+
# or
|
51
|
+
#
|
52
|
+
# w = Num.new( 'Clock-Hour', 8, 1 )
|
53
|
+
def initialize( id = "NumWidget_#{@@widget_count}", num = 1, col = 1 )
|
54
|
+
if id.nil?
|
55
|
+
id = "NumWidget_#{@@widget_count}"
|
56
|
+
end
|
57
|
+
|
58
|
+
@id = id
|
59
|
+
@type = :num
|
60
|
+
@screen = nil
|
61
|
+
@visible = false
|
62
|
+
|
63
|
+
@number = num
|
64
|
+
@x = col
|
65
|
+
|
66
|
+
@@widget_count += 1
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
# Sends to command to the LCDd server to update the widget on screen
|
71
|
+
def update
|
72
|
+
if @screen
|
73
|
+
response = @screen.client.send_command( Command.new( "widget_set #{@screen.id} #{self.id} #{@x} #{@number}" ) )
|
74
|
+
|
75
|
+
if response.successful?
|
76
|
+
@screen.client.add_message( "Widget '#{@id}' was successfully updated" )
|
77
|
+
return true
|
78
|
+
else
|
79
|
+
@screen.client.add_message( "Error: Widget '#{@id}' was NOT successfully updated (#{response.message})" )
|
80
|
+
return true
|
81
|
+
end
|
82
|
+
else
|
83
|
+
@screen.client.add_message( "Error: Cannot update Widget '#{@id}' until it is attached to a screen" )
|
84
|
+
return false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
@@ -0,0 +1,110 @@
|
|
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 Widgets
|
30
|
+
|
31
|
+
class Scroller
|
32
|
+
include LCDProc::Widget
|
33
|
+
LCDProc::Widget.add_support( :scroller, self )
|
34
|
+
|
35
|
+
attr_accessor :left, :top, :right, :bottom, :direction, :speed, :text
|
36
|
+
|
37
|
+
@@widget_count = 0
|
38
|
+
|
39
|
+
|
40
|
+
# Creates a new Scroller widget which can then be displayed anywhere on the screen.
|
41
|
+
#
|
42
|
+
# * <tt>:id</tt> - A unique string which identifies this widget. Defaults to "ScrollerWidget_" + a sequence number.
|
43
|
+
# * <tt>:left</tt> - The column in which to begin the scrolling text. Defaults to 1.
|
44
|
+
# * <tt>:top</tt> - The row in which to begin the scrolling text. Defaults to 1.
|
45
|
+
# * <tt>:right</tt> - The column in which to end the scrolling text. Defaults to 10 until attached to a screen, then defaults to the width of the screen.
|
46
|
+
# * <tt>:bottom</tt> - The row in which to end the scrolling text. Defaults to 2 until attached to a screen, then defaults to the height of the screen.
|
47
|
+
# * <tt>:direction</tt> - The direction that the text should scroll. One of "h" for horizontal, "v" for vertical, or "m" for marquee.
|
48
|
+
# * <tt>:speed</tt> - The number of movements per rendering stroke (8 times per second).
|
49
|
+
# * <tt>:text</tt> - The text that you wish to display on the screen. Default to "Hello, here is some really long text.". Note that if this string is shorter than the allotted width or height, no scrolling occurs.
|
50
|
+
#
|
51
|
+
# Example:
|
52
|
+
#
|
53
|
+
# w = Scroller.new
|
54
|
+
#
|
55
|
+
# or
|
56
|
+
#
|
57
|
+
# w = Scroller.new( 'TestScroller', 1, 1, 20, 4, "h", 1, "Some Scrolling Text")
|
58
|
+
def initialize( id = "ScrollerWidget_#{@@widget_count}", left = 1, top = 1, right = 10, bottom = 2, direction = "h", speed = 1, text = "Hello, here is some really long text." )
|
59
|
+
if id.nil?
|
60
|
+
id = "ScrollerWidget_#{@@widget_count}"
|
61
|
+
end
|
62
|
+
|
63
|
+
@id = id
|
64
|
+
@type = :scroller
|
65
|
+
@screen = nil
|
66
|
+
@visible = false
|
67
|
+
|
68
|
+
@left = left
|
69
|
+
@top = top
|
70
|
+
@right = right
|
71
|
+
@bottom = bottom
|
72
|
+
@direction = direction
|
73
|
+
@speed = speed
|
74
|
+
@text = text
|
75
|
+
|
76
|
+
@@widget_count += 1
|
77
|
+
end
|
78
|
+
|
79
|
+
|
80
|
+
# Allows a widget to be attached to a screen.
|
81
|
+
def attach_to( screen )
|
82
|
+
@right = screen.client.width
|
83
|
+
@bottom = screen.client.height
|
84
|
+
|
85
|
+
return super(screen )
|
86
|
+
end
|
87
|
+
|
88
|
+
# Sends to command to the LCDd server to update the widget on screen
|
89
|
+
def update
|
90
|
+
if @screen
|
91
|
+
response = @screen.client.send_command( Command.new( "widget_set #{@screen.id} #{self.id} #{@left} #{@top} #{@right} #{@bottom} #{@direction} #{@speed} \"#{@text}\"" ) )
|
92
|
+
|
93
|
+
if response.successful?
|
94
|
+
@screen.client.add_message( "Widget '#{@id}' was successfully updated" )
|
95
|
+
return true
|
96
|
+
else
|
97
|
+
@screen.client.add_message( "Error: Widget '#{@id}' was NOT successfully updated (#{response.message})" )
|
98
|
+
return true
|
99
|
+
end
|
100
|
+
else
|
101
|
+
@screen.client.add_message( "Error: Cannot update Widget '#{@id}' until it is attached to a screen" )
|
102
|
+
return false
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
end
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
@@ -0,0 +1,94 @@
|
|
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 Widgets
|
30
|
+
|
31
|
+
class String
|
32
|
+
include LCDProc::Widget
|
33
|
+
LCDProc::Widget.add_support( :string, self )
|
34
|
+
|
35
|
+
attr_accessor :x, :y, :widget_text
|
36
|
+
|
37
|
+
@@widget_count = 0
|
38
|
+
|
39
|
+
|
40
|
+
# Creates a new String widget which can then be displayed anywhere on the screen.
|
41
|
+
#
|
42
|
+
# * <tt>:id</tt> - A unique string which identifies this widget. Defaults to "StringWidget_" + a sequence number.
|
43
|
+
# * <tt>:text</tt> - The text that you wish to display on the screen. Default to "Hello".
|
44
|
+
# * <tt>:col</tt> - The column in which you wish to display the text on screen. Defaults to 1.
|
45
|
+
# * <tt>:row</tt> - The row in which you wish to display the text on screen. Defaults to 1.
|
46
|
+
#
|
47
|
+
# Example:
|
48
|
+
#
|
49
|
+
# w = String.new
|
50
|
+
#
|
51
|
+
# or
|
52
|
+
#
|
53
|
+
# w = String.new( 'Test', 'This is a string', 1, 5 )
|
54
|
+
def initialize( id = "StringWidget_#{@@widget_count}", text = "Hello", col = 1, row = 1 )
|
55
|
+
if id.nil?
|
56
|
+
id = "StringWidget_#{@@widget_count}"
|
57
|
+
end
|
58
|
+
|
59
|
+
@id = id
|
60
|
+
@type = :string
|
61
|
+
@screen = nil
|
62
|
+
@visible = false
|
63
|
+
|
64
|
+
@widget_text = text
|
65
|
+
@x = col
|
66
|
+
@y = row
|
67
|
+
|
68
|
+
@@widget_count += 1
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
# Sends to command to the LCDd server to update the widget on screen
|
73
|
+
def update
|
74
|
+
if @screen
|
75
|
+
response = @screen.client.send_command( Command.new( "widget_set #{@screen.id} #{self.id} #{@x} #{@y} \"#{@widget_text}\"" ) )
|
76
|
+
|
77
|
+
if response.successful?
|
78
|
+
@screen.client.add_message( "Widget '#{@id}' was successfully updated" )
|
79
|
+
return true
|
80
|
+
else
|
81
|
+
@screen.client.add_message( "Error: Widget '#{@id}' was NOT successfully updated (#{response.message})" )
|
82
|
+
return true
|
83
|
+
end
|
84
|
+
else
|
85
|
+
@screen.client.add_message( "Error: Cannot update Widget '#{@id}' until it is attached to a screen" )
|
86
|
+
return false
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
@@ -0,0 +1,90 @@
|
|
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 Widgets
|
30
|
+
|
31
|
+
class Title
|
32
|
+
include LCDProc::Widget
|
33
|
+
LCDProc::Widget.add_support( :title, self )
|
34
|
+
|
35
|
+
attr_accessor :title_text
|
36
|
+
|
37
|
+
@@widget_count = 0
|
38
|
+
|
39
|
+
|
40
|
+
# Creates a new Title widget which gets displayed at the top of the screen
|
41
|
+
#
|
42
|
+
# * <tt>:id</tt> - A unique string which identifies this widget. Defaults to "TitleWidget_" + a sequence number.
|
43
|
+
# * <tt>:text</tt> - The text that you wish to display as the title. Default to "Title".
|
44
|
+
#
|
45
|
+
# Example:
|
46
|
+
#
|
47
|
+
# w = Title.new
|
48
|
+
#
|
49
|
+
# or
|
50
|
+
#
|
51
|
+
# w = Title.new( 'Test', 'My Wonderful Title' )
|
52
|
+
def initialize( id = "TitleWidget_#{@@widget_count}", text = "Title" )
|
53
|
+
if id.nil?
|
54
|
+
id = "TitleWidget_#{@@widget_count}"
|
55
|
+
end
|
56
|
+
|
57
|
+
@id = id
|
58
|
+
@type = :title
|
59
|
+
@screen = nil
|
60
|
+
@visible = false
|
61
|
+
|
62
|
+
@title_text = text
|
63
|
+
|
64
|
+
@@widget_count += 1
|
65
|
+
end
|
66
|
+
|
67
|
+
|
68
|
+
# Sends to command to the LCDd server to update the widget on screen
|
69
|
+
def update
|
70
|
+
if @screen
|
71
|
+
response = @screen.client.send_command( Command.new( "widget_set #{@screen.id} #{self.id} \"#{@title_text}\"" ) )
|
72
|
+
|
73
|
+
if response.successful?
|
74
|
+
@screen.client.add_message( "Widget '#{@id}' was successfully updated" )
|
75
|
+
return true
|
76
|
+
else
|
77
|
+
@screen.client.add_message( "Error: Widget '#{@id}' was NOT successfully updated (#{response.message})" )
|
78
|
+
return true
|
79
|
+
end
|
80
|
+
else
|
81
|
+
@screen.client.add_message( "Error: Cannot update Widget '#{@id}' until it is attached to a screen" )
|
82
|
+
return false
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
end
|
@@ -0,0 +1,111 @@
|
|
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 Widgets
|
30
|
+
|
31
|
+
class VBar
|
32
|
+
include LCDProc::Widget
|
33
|
+
LCDProc::Widget.add_support( :vbar, self )
|
34
|
+
|
35
|
+
attr_accessor :x, :y, :height
|
36
|
+
|
37
|
+
@@widget_count = 0
|
38
|
+
|
39
|
+
|
40
|
+
# Creates a new VBar widget which can then be displayed anywhere on the screen.
|
41
|
+
#
|
42
|
+
# * <tt>:id</tt> - A unique string which identifies this widget. Defaults to "VBarWidget_" + a sequence number.
|
43
|
+
# * <tt>:bar_height</tt> - The height of the bar. Default to 16 (half the height of a 20x4 character screen).
|
44
|
+
# * <tt>:x_pos</tt> - The row in which the bar should be positioned. Defaults to 1.
|
45
|
+
# * <tt>:y_pos</tt> - The column in which the bar should be positioned. Defaults to 1 (bottom of the screen).
|
46
|
+
#
|
47
|
+
# Example:
|
48
|
+
#
|
49
|
+
# w = VBar.new
|
50
|
+
#
|
51
|
+
# or
|
52
|
+
#
|
53
|
+
# w = VBar.new( 'TestBar', 32, 2, 4 )
|
54
|
+
def initialize( id = "VBarWidget_#{@@widget_count}", bar_height = 16, x_pos = 1, y_pos = 1 )
|
55
|
+
if id.nil?
|
56
|
+
id = "VBarWidget_#{@@widget_count}"
|
57
|
+
end
|
58
|
+
|
59
|
+
@id = id
|
60
|
+
@type = :vbar
|
61
|
+
@screen = nil
|
62
|
+
@visible = false
|
63
|
+
|
64
|
+
@height = bar_height
|
65
|
+
@x = x_pos
|
66
|
+
@y = y_pos
|
67
|
+
|
68
|
+
@old_height = nil
|
69
|
+
@old_x = nil
|
70
|
+
@old_y = nil
|
71
|
+
|
72
|
+
@@widget_count += 1
|
73
|
+
end
|
74
|
+
|
75
|
+
|
76
|
+
# Sends to command to the LCDd server to update the widget on screen
|
77
|
+
def update
|
78
|
+
|
79
|
+
# Don't update unless something has actually changed
|
80
|
+
if @x == @old_x and @y == @old_y and @height == @old_height
|
81
|
+
return true
|
82
|
+
end
|
83
|
+
|
84
|
+
if @screen
|
85
|
+
|
86
|
+
bar_height = @height
|
87
|
+
|
88
|
+
if @height < 1
|
89
|
+
bar_height = @height * 120
|
90
|
+
end
|
91
|
+
|
92
|
+
response = @screen.client.send_command( Command.new( "widget_set #{@screen.id} #{self.id} #{@x} #{@y} #{bar_height}" ) )
|
93
|
+
|
94
|
+
if response.successful?
|
95
|
+
@screen.client.add_message( "Widget '#{@id}' was successfully updated" )
|
96
|
+
return true
|
97
|
+
else
|
98
|
+
@screen.client.add_message( "Error: Widget '#{@id}' was NOT successfully updated (#{response.message})" )
|
99
|
+
return true
|
100
|
+
end
|
101
|
+
else
|
102
|
+
@screen.client.add_message( "Error: Cannot update Widget '#{@id}' until it is attached to a screen" )
|
103
|
+
return false
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|