package App::POS::Hardware::CustomerDisplays::CSI_STARVISION;

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";

  $port->write(chr(0x1B).chr(0x40));
  usleep(2000);

  custom_write($port, $str1);
  usleep(2000);

  custom_write(
    $port,
    chr(0x10).chr(0x10).chr(0x10).chr(0x10).chr(0x10).chr(0x10).
    chr(0x10).chr(0x10).chr(0x10).chr(0x10).chr(0x10).chr(0x10).
    chr(0x10).chr(0x10).chr(0x10).chr(0x10).chr(0x10).chr(0x10).
    chr(0x10).chr(0x10).
    $str2,
  );

  usleep(2000);
}

sub custom_write {
  my( $port_o, $str ) = @_;

  my @c = split //, $str;

  foreach my $c (@c) {
    $port_o->write($c);
    usleep(1000);
  }
}


1;

