Class: Smartware::Interface::Printer

Inherits:
Smartware::Interface show all
Defined in:
lib/smartware/interfaces/printer.rb

Constant Summary collapse

HARDWARE_ERROR =
1
COMMUNICATION_ERROR =
2
OUT_OF_PAPER =
3
PAPER_NEAR_END =
1000

Instance Method Summary collapse

Constructor Details

#initialize(config, service) ⇒ Printer

Returns a new instance of Printer.



10
11
12
13
14
15
16
17
# File 'lib/smartware/interfaces/printer.rb', line 10

def initialize(config, service)
  super

  @printer_mutex = Mutex.new
  Thread.new &method(:poll)
  @render = @device.new_render
  @markdown = Redcarpet::Markdown.new(@render)
end

Instance Method Details



32
33
34
35
36
# File 'lib/smartware/interfaces/printer.rb', line 32

def print(file, max_time = 30)
  File.open(file, "r") do |io|
    print_markdown io.read, max_time
  end
end


38
39
40
# File 'lib/smartware/interfaces/printer.rb', line 38

def print_markdown(text, max_time = 30)
  do_print @markdown.render(text), max_time
end


42
43
44
45
46
47
48
49
50
# File 'lib/smartware/interfaces/printer.rb', line 42

def print_text(text, max_time = 30)
  data = "".force_encoding("BINARY")
  data << @render.doc_header.force_encoding("BINARY") if @render.respond_to? :doc_header
  data << @render.normal_text(text, true).force_encoding("BINARY") if @render.respond_to? :normal_text
  data << @render.linebreak.force_encoding("BINARY") if @render.respond_to? :linebreak
  data << @render.doc_footer.force_encoding("BINARY") if @render.respond_to? :doc_footer

  do_print data, max_time
end

#testObject



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/smartware/interfaces/printer.rb', line 19

def test
  print_markdown <<-EOS
Smartware: **#{Smartware::VERSION}**

Driver:  **#{@config["driver"]}**

Model:   **#{@device.model}**

Version: **#{@device.version}**

EOS
end