Sha256: 09f9adc9ce4b431bfcff2e8a539235a2c011be675ecb6b48ba29cf4ecc18bc99

Contents?: true

Size: 666 Bytes

Versions: 1

Compression:

Stored size: 666 Bytes

Contents

require "socket"

class BTPR880 < Thermal::Printer

  ESC = 27.chr
  GS = 29.chr
  CODES = {
    :bold => ESC+"E",
    :underline => ESC+"-",
    :small => ESC+"M",
    :invert => GS+"B",
    :linebreak => "\n"
  }

  TRANSLATE = {
    :strong => [CODES[:bold]+"1", CODES[:bold]+"0"],
    :u => [CODES[:underline]+"1", CODES[:underline]+"0"],
    :small => [CODES[:small]+"1", CODES[:small]+"0"],
    :mark => [CODES[:invert]+"1", CODES[:invert]+"0"],
    :br => [CODES[:linebreak], ""]
  }

  def self.translate
    TRANSLATE
  end

  def self.print(ip, port=9001, &block)
    sock = TCPSocket.new(ip, port)
    yield sock if block_given?
    sock.close
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thermal-0.1.1 lib/devices/btpr880.rb