Adapting to new cat printer just bought.
This commit is contained in:
parent
ba3a5591cf
commit
59e7904721
@ -24,13 +24,11 @@ has port => (
|
|||||||
required => 1,
|
required => 1,
|
||||||
);
|
);
|
||||||
|
|
||||||
has name => (
|
has name => ( is => 'ro', );
|
||||||
is => 'ro',
|
|
||||||
);
|
|
||||||
|
|
||||||
has _guts_device => ( is => 'rw' );
|
has _guts_device => ( is => 'rw' );
|
||||||
|
|
||||||
has _tempdir => ( is => 'rw', );
|
has _tempdir => ( is => 'rw', );
|
||||||
has _bluetooth => ( is => 'lazy' );
|
has _bluetooth => ( is => 'lazy' );
|
||||||
|
|
||||||
sub _device($self) {
|
sub _device($self) {
|
||||||
@ -68,7 +66,7 @@ sub lf($self) {
|
|||||||
sub _build__bluetooth($self) {
|
sub _build__bluetooth($self) {
|
||||||
my $obj = Net::Bluetooth->newsocket('RFCOMM');
|
my $obj = Net::Bluetooth->newsocket('RFCOMM');
|
||||||
$self->_try_to_connect($obj);
|
$self->_try_to_connect($obj);
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _obj($self) {
|
sub _obj($self) {
|
||||||
@ -86,21 +84,22 @@ sub print($self) {
|
|||||||
close $fh;
|
close $fh;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _try_to_connect($self, $obj, $retries = 3) {
|
sub _try_to_connect( $self, $obj, $retries = 3 ) {
|
||||||
if ( 0 == $obj->connect( $self->address, $self->port ) ) {
|
if ( 0 == $obj->connect( $self->address, $self->port ) ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($retries == 0) {
|
if ( $retries == 0 ) {
|
||||||
die 'Unable to connect to bluetooth';
|
die 'Unable to connect to bluetooth';
|
||||||
}
|
}
|
||||||
sleep 1;
|
sleep 1;
|
||||||
return $self->_try_to_connect($obj, $retries - 1);
|
return $self->_try_to_connect( $obj, $retries - 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
sub serialize($self) {
|
sub serialize($self) {
|
||||||
my $hash = {};
|
my $hash = {};
|
||||||
$hash->{address} = $self->address;
|
$hash->{address} = $self->address;
|
||||||
$hash->{port} = $self->port;
|
$hash->{port} = $self->port;
|
||||||
if (defined $self->name) {
|
if ( defined $self->name ) {
|
||||||
$hash->{name} = $self->name;
|
$hash->{name} = $self->name;
|
||||||
}
|
}
|
||||||
$hash->{type} = 'bluetooth';
|
$hash->{type} = 'bluetooth';
|
||||||
@ -108,17 +107,22 @@ sub serialize($self) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub devices_from_cache($class) {
|
sub devices_from_cache($class) {
|
||||||
my $dbh = Exd::DB->connect;
|
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;
|
return \@devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub cache_printers($class, $devices) {
|
sub cache_printers( $class, $devices ) {
|
||||||
if (scalar @$devices == 0) {
|
if ( scalar @$devices == 0 ) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
my $insert_query = 'INSERT INTO cached_bluetooth_printers (address, name, port) VALUES ';
|
my $insert_query =
|
||||||
for (my $i = 0; $i < scalar @$devices; $i++) {
|
'INSERT INTO cached_bluetooth_printers (address, name, port) VALUES ';
|
||||||
|
for ( my $i = 0 ; $i < scalar @$devices ; $i++ ) {
|
||||||
$insert_query .= ' (?, ?, ?),';
|
$insert_query .= ' (?, ?, ?),';
|
||||||
}
|
}
|
||||||
$insert_query =~ s/,$/;/;
|
$insert_query =~ s/,$/;/;
|
||||||
@ -127,7 +131,7 @@ sub cache_printers($class, $devices) {
|
|||||||
my @params = map { $_->address, $_->name, $_->port } @$devices;
|
my @params = map { $_->address, $_->name, $_->port } @$devices;
|
||||||
eval {
|
eval {
|
||||||
$dbh->do('DELETE FROM cached_bluetooth_printers;');
|
$dbh->do('DELETE FROM cached_bluetooth_printers;');
|
||||||
$dbh->do($insert_query, {}, @params);
|
$dbh->do( $insert_query, {}, @params );
|
||||||
$dbh->commit;
|
$dbh->commit;
|
||||||
};
|
};
|
||||||
if ($@) {
|
if ($@) {
|
||||||
|
@ -97,7 +97,7 @@ sub print($self) {
|
|||||||
$buffer .=
|
$buffer .=
|
||||||
$self->_bytestring( 0xaa, 0x55, 0x17, 0x38, 0x44, 0x5f, 0x5f, 0x5f, 0x44,
|
$self->_bytestring( 0xaa, 0x55, 0x17, 0x38, 0x44, 0x5f, 0x5f, 0x5f, 0x44,
|
||||||
0x38, 0x2c );
|
0x38, 0x2c );
|
||||||
$buffer .= $self->_make_command( 0xa0, $self->_bytestring( 255, 0x00 ) );
|
# $buffer .= $self->_make_command( 0xa0, $self->_bytestring( 255, 0x00 ) );
|
||||||
|
|
||||||
seek $fh, 0xa, 0;
|
seek $fh, 0xa, 0;
|
||||||
read $fh, my $offset, 4;
|
read $fh, my $offset, 4;
|
||||||
|
@ -178,6 +178,7 @@ sub _daemon_bluetooth_search_iteration($self) {
|
|||||||
my $search = Net::Bluetooth::sdp_search($address, "1101", "");
|
my $search = Net::Bluetooth::sdp_search($address, "1101", "");
|
||||||
if (defined $search && defined $search->{RFCOMM}) {
|
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}:$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});
|
push @return, Exd::DeviceToBluetooth->new(name => $devices->{$address}, address => $address, port => $search->{RFCOMM});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,7 +121,7 @@ sub print($self) {
|
|||||||
if system(
|
if system(
|
||||||
qw/convert/,
|
qw/convert/,
|
||||||
$image_file_in,
|
$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_file_out
|
||||||
);
|
);
|
||||||
$image_final = Exd::Utils::get_gd_image( $image_file_out . '' );
|
$image_final = Exd::Utils::get_gd_image( $image_file_out . '' );
|
||||||
|
@ -114,6 +114,12 @@ sub _split_text_lines( $class, $text, $max_width, $font, $font_size ) {
|
|||||||
}
|
}
|
||||||
my $surface = Cairo::ImageSurface->create( 'argb32', 384, 100 );
|
my $surface = Cairo::ImageSurface->create( 'argb32', 384, 100 );
|
||||||
my $cr = Cairo::Context->create($surface);
|
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);
|
my $layout = Pango::Cairo::create_layout($cr);
|
||||||
$layout->set_font_description($font);
|
$layout->set_font_description($font);
|
||||||
while (@lines) {
|
while (@lines) {
|
||||||
|
Loading…
Reference in New Issue
Block a user