Adapting to new cat printer just bought.

This commit is contained in:
Sergiotarxz 2024-10-28 12:14:38 +01:00
parent ba3a5591cf
commit 59e7904721
5 changed files with 30 additions and 19 deletions

View File

@ -24,9 +24,7 @@ has port => (
required => 1,
);
has name => (
is => 'ro',
);
has name => ( is => 'ro', );
has _guts_device => ( is => 'rw' );
@ -96,6 +94,7 @@ sub _try_to_connect($self, $obj, $retries = 3) {
sleep 1;
return $self->_try_to_connect( $obj, $retries - 1 );
}
sub serialize($self) {
my $hash = {};
$hash->{address} = $self->address;
@ -109,7 +108,11 @@ sub serialize($self) {
sub devices_from_cache($class) {
my $dbh = Exd::DB->connect;
my @devices = map { $class->new($_) } $dbh->selectall_arrayref('SELECT address, name, port FROM cached_bluetooth_printers;', {Slice => {}})->@*;
my @devices = map {
$class->new($_)
} $dbh->selectall_arrayref(
'SELECT address, name, port FROM cached_bluetooth_printers;',
{ Slice => {} } )->@*;
return \@devices;
}
@ -117,7 +120,8 @@ sub cache_printers($class, $devices) {
if ( scalar @$devices == 0 ) {
return;
}
my $insert_query = 'INSERT INTO cached_bluetooth_printers (address, name, port) VALUES ';
my $insert_query =
'INSERT INTO cached_bluetooth_printers (address, name, port) VALUES ';
for ( my $i = 0 ; $i < scalar @$devices ; $i++ ) {
$insert_query .= ' (?, ?, ?),';
}

View File

@ -97,7 +97,7 @@ sub print($self) {
$buffer .=
$self->_bytestring( 0xaa, 0x55, 0x17, 0x38, 0x44, 0x5f, 0x5f, 0x5f, 0x44,
0x38, 0x2c );
$buffer .= $self->_make_command( 0xa0, $self->_bytestring( 255, 0x00 ) );
# $buffer .= $self->_make_command( 0xa0, $self->_bytestring( 255, 0x00 ) );
seek $fh, 0xa, 0;
read $fh, my $offset, 4;

View File

@ -178,6 +178,7 @@ sub _daemon_bluetooth_search_iteration($self) {
my $search = Net::Bluetooth::sdp_search($address, "1101", "");
if (defined $search && defined $search->{RFCOMM}) {
say "$devices->{$address}:$address supports Serial Port and may be a printer, the port is: $search->{RFCOMM}";
say $devices->{$address};
push @return, Exd::DeviceToBluetooth->new(name => $devices->{$address}, address => $address, port => $search->{RFCOMM});
}
}

View File

@ -121,7 +121,7 @@ sub print($self) {
if system(
qw/convert/,
$image_file_in,
qw/-resize 384x -dither FloydSteinberg -remap pattern:gray50 -monochrome/,
qw/-resize 384x -brightness-contrast +10 -dither FloydSteinberg -remap pattern:gray50/,
$image_file_out
);
$image_final = Exd::Utils::get_gd_image( $image_file_out . '' );

View File

@ -114,6 +114,12 @@ sub _split_text_lines( $class, $text, $max_width, $font, $font_size ) {
}
my $surface = Cairo::ImageSurface->create( 'argb32', 384, 100 );
my $cr = Cairo::Context->create($surface);
$cr->set_source_rgb( 1, 1, 1 );
$cr->rectangle( 0, 0, 384, 100 );
$cr->fill;
my $layout = Pango::Cairo::create_layout($cr);
$layout->set_font_description($font);
while (@lines) {