Class: Tamashii::Agent::Lcd::LineAnimator
- Inherits:
-
Object
- Object
- Tamashii::Agent::Lcd::LineAnimator
show all
- Includes:
- Common::Loggable
- Defined in:
- lib/tamashii/agent/lcd.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
#display_name, #logger, #progname
Constructor Details
Returns a new instance of LineAnimator.
22
23
24
25
26
27
|
# File 'lib/tamashii/agent/lcd.rb', line 22
def initialize(line)
@line = line
@text = ""
@pos = -1
@stop_animation = false
end
|
Instance Attribute Details
#text ⇒ Object
Returns the value of attribute text.
12
13
14
|
# File 'lib/tamashii/agent/lcd.rb', line 12
def text
@text
end
|
Class Method Details
.handler_print_line=(value) ⇒ Object
18
19
20
|
# File 'lib/tamashii/agent/lcd.rb', line 18
def self.handler_print_line=(value)
@@handler_print_line = value
end
|
.line_width=(value) ⇒ Object
14
15
16
|
# File 'lib/tamashii/agent/lcd.rb', line 14
def self.line_width=(value)
@@line_width = value
end
|
Instance Method Details
#animation_loop ⇒ Object
55
56
57
58
59
60
61
62
|
# File 'lib/tamashii/agent/lcd.rb', line 55
def animation_loop
loop do
sleep Config.lcd_animation_delay
animation_show_text
break if @stop_animation
sleep Config.lcd_animation_delay if @pos == 0 || @pos == @max_pos
end
end
|
#animation_show_text ⇒ Object
40
41
42
43
44
45
|
# File 'lib/tamashii/agent/lcd.rb', line 40
def animation_show_text
text = @text[@pos, @@line_width]
@pos += 1
@pos = 0 if @pos > @max_pos
print_text(text)
end
|
#print_text(text) ⇒ Object
73
74
75
|
# File 'lib/tamashii/agent/lcd.rb', line 73
def print_text(text)
@@handler_print_line&.call(text, @line)
end
|
#set_text(text) ⇒ Object
29
30
31
32
33
34
35
36
37
38
|
# File 'lib/tamashii/agent/lcd.rb', line 29
def set_text(text)
return if text == @text
stop_animation
@text = text || ""
if @text.size > @@line_width
start_animation
else
print_text(@text)
end
end
|
#start_animation ⇒ Object
47
48
49
50
51
52
53
|
# File 'lib/tamashii/agent/lcd.rb', line 47
def start_animation
@pos = 0
@max_pos = @text.size - @@line_width
@stop_animation = false
logger.debug "Start animation for line #{@line}: #{@text}"
@animation_thread = Thread.new { animation_loop }
end
|
#stop_animation ⇒ Object
64
65
66
67
68
69
70
71
|
# File 'lib/tamashii/agent/lcd.rb', line 64
def stop_animation
@stop_animation = true
if @animation_thread
@animation_thread.join(Config.lcd_animation_delay * 3)
@animation_thread.exit
@animation_thread = nil
end
end
|