package App::POS::Hardware::CustomerDisplays::VFD_SERIE_ESC_POS;

use strict;
use warnings;
use Time::HiRes qw( usleep );

use base qw( App::POS::Hardware::CustomerDisplays );

sub type { "SERIAL" }

sub init {
  my $self = shift;
}

sub write {
  my $self = shift;
  my $str = shift || undef;
  return unless defined $str;

  my $port = $self->serial_obj();

  if (! defined $port) {
    print STDERR "port is not defined, returning...\n";
    return;
  }

  my( $str1, $str2 ) = $self->_text_process($str, 20, 20);
  #print STDERR "STR1 : #$str1# #".length($str1)."#\n";
  #print STDERR "STR2 : #$str2# #".length($str2)."#\n";

  #Initialize Display
	

  # clean display/ INITIALIZE DISPLAY (AT)
  $port->write(chr(27).chr(64));
  usleep(2000);

  # Set international characters
  $port->write(chr(0x1B).chr(0x52).chr(0x00));
  usleep(2000);

  # Set portuguese code page
  $port->write(chr(0x1B).chr(0x74).chr(0x03));
  usleep(2000);

  #Move cursor to home position.
  $port->write(chr(0x0B));
  usleep(2000);

  if ($str1) {

    $port->write(chr(0x1F).chr(0x24).chr(0x01).chr(0x01));
    usleep(2000);
    my @chars = split //, $str1;
    for (@chars) {
      $port->write($_);
      usleep(2000);
    }
  }

  if ($str2) {
   
    $port->write(chr(0x1F).chr(0x24).chr(0x01).chr(0x02));
    usleep(2000);
    my @chars = split //, $str2;
    for (@chars) {
      $port->write($_);
      usleep(2000);
    }
  }
}

1;

