lib/tamashii/agent/lcd.rb in tamashii-agent-0.3.0 vs lib/tamashii/agent/lcd.rb in tamashii-agent-0.3.1

- old
+ new

@@ -1,15 +1,13 @@ require 'concurrent' require 'tamashii/agent/common' require 'tamashii/agent/event' -require 'tamashii/agent/adapter/lcd' - module Tamashii module Agent - class LCD < Component + class Lcd < Component class LineAnimator include Common::Loggable attr_reader :text @@ -75,37 +73,37 @@ def print_text(text) @@handler_print_line&.call(text, @line) end end - def initialize(master) + def initialize(name, master, options = {}) super - load_lcd_device - @device_line_count = @lcd.class::LINE_COUNT + @lcd = initialize_device + @device_line_count = @lcd.line_count @device_lock = Mutex.new create_line_animators set_idle_text("[Tamashii]\nIdle...") logger.debug "Using LCD instance: #{@lcd.class}" print_message("Initializing\nPlease wait...") schedule_to_print_idle end + def default_device_name + 'Dummy' + end + + def get_device_class_name(device_name) + "Lcd::#{device_name}" + end + def create_line_animators - LineAnimator.line_width = @lcd.class::WIDTH + LineAnimator.line_width = @lcd.width LineAnimator.handler_print_line = method(:print_line) @line_animators = [] @device_line_count.times {|i| @line_animators << LineAnimator.new(i)} end - def load_lcd_device - @lcd = Adapter::LCD.object - rescue => e - logger.error "Unable to load LCD instance: #{Adapter::LCD.current_class}" - logger.error "Use #{Adapter::LCD.fake_class} instead" - @lcd = Adapter::LCD.fake_class.new - end - def print_message(message) lines = message.lines.map{|l| l.delete("\n")} @device_line_count.times do |line_count| @line_animators[line_count].set_text(lines[line_count]) end @@ -183,11 +181,11 @@ def clear_screen print_message("") end def clean_up - clear_screen super + @lcd.shutdown end end end end