diff --git a/lib/Exd/DeviceToBluetooth.pm b/lib/Exd/DeviceToBluetooth.pm index b1912c6..82accfb 100644 --- a/lib/Exd/DeviceToBluetooth.pm +++ b/lib/Exd/DeviceToBluetooth.pm @@ -24,13 +24,11 @@ has port => ( required => 1, ); -has name => ( - is => 'ro', -); +has name => ( is => 'ro', ); has _guts_device => ( is => 'rw' ); -has _tempdir => ( is => 'rw', ); +has _tempdir => ( is => 'rw', ); has _bluetooth => ( is => 'lazy' ); sub _device($self) { @@ -68,7 +66,7 @@ sub lf($self) { sub _build__bluetooth($self) { my $obj = Net::Bluetooth->newsocket('RFCOMM'); $self->_try_to_connect($obj); - return $obj; + return $obj; } sub _obj($self) { @@ -86,21 +84,22 @@ sub print($self) { 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 ) ) { return; } - if ($retries == 0) { + if ( $retries == 0 ) { die 'Unable to connect to bluetooth'; } sleep 1; - return $self->_try_to_connect($obj, $retries - 1); + return $self->_try_to_connect( $obj, $retries - 1 ); } + sub serialize($self) { my $hash = {}; $hash->{address} = $self->address; - $hash->{port} = $self->port; - if (defined $self->name) { + $hash->{port} = $self->port; + if ( defined $self->name ) { $hash->{name} = $self->name; } $hash->{type} = 'bluetooth'; @@ -108,17 +107,22 @@ 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 $dbh = Exd::DB->connect; + my @devices = map { + $class->new($_) + } $dbh->selectall_arrayref( + 'SELECT address, name, port FROM cached_bluetooth_printers;', + { Slice => {} } )->@*; return \@devices; } -sub cache_printers($class, $devices) { - if (scalar @$devices == 0) { +sub cache_printers( $class, $devices ) { + if ( scalar @$devices == 0 ) { return; } - my $insert_query = 'INSERT INTO cached_bluetooth_printers (address, name, port) VALUES '; - for (my $i = 0; $i < scalar @$devices; $i++) { + my $insert_query = + 'INSERT INTO cached_bluetooth_printers (address, name, port) VALUES '; + for ( my $i = 0 ; $i < scalar @$devices ; $i++ ) { $insert_query .= ' (?, ?, ?),'; } $insert_query =~ s/,$/;/; @@ -127,7 +131,7 @@ sub cache_printers($class, $devices) { my @params = map { $_->address, $_->name, $_->port } @$devices; eval { $dbh->do('DELETE FROM cached_bluetooth_printers;'); - $dbh->do($insert_query, {}, @params); + $dbh->do( $insert_query, {}, @params ); $dbh->commit; }; if ($@) { diff --git a/lib/Exd/DeviceToCatPrinter.pm b/lib/Exd/DeviceToCatPrinter.pm index 7c8bb68..31d2155 100644 --- a/lib/Exd/DeviceToCatPrinter.pm +++ b/lib/Exd/DeviceToCatPrinter.pm @@ -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; diff --git a/lib/Exd/Gui/PrinterConfigure.pm b/lib/Exd/Gui/PrinterConfigure.pm index d31131e..366a4a3 100644 --- a/lib/Exd/Gui/PrinterConfigure.pm +++ b/lib/Exd/Gui/PrinterConfigure.pm @@ -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}); } } diff --git a/lib/Exd/Printer.pm b/lib/Exd/Printer.pm index 0c4188a..c34b737 100644 --- a/lib/Exd/Printer.pm +++ b/lib/Exd/Printer.pm @@ -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 . '' ); diff --git a/lib/Exd/Utils/String.pm b/lib/Exd/Utils/String.pm index 44dbb4d..0d96dae 100644 --- a/lib/Exd/Utils/String.pm +++ b/lib/Exd/Utils/String.pm @@ -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) {