| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
package Device::Citizen3540; |
|
3
|
1
|
|
|
1
|
|
991
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
25
|
|
|
5
|
1
|
|
|
1
|
|
4
|
use Fcntl; |
|
|
1
|
|
|
|
|
9
|
|
|
|
1
|
|
|
|
|
260
|
|
|
6
|
1
|
|
|
1
|
|
1330
|
use Text::ASCIITable::Wrap qw/wrap/; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use Data::Dumper; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use vars qw/$VERSION %EXPORT_TAGS @ISA/; |
|
10
|
|
|
|
|
|
|
use Exporter (); |
|
11
|
|
|
|
|
|
|
@ISA = qw/Exporter/; |
|
12
|
|
|
|
|
|
|
%EXPORT_TAGS = (constants => [qw/RED BIG ULINE CENTER/]); |
|
13
|
|
|
|
|
|
|
$VERSION = 0.61; |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Exporter::export_ok_tags('constants'); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
use constant RED => 1 << 0; |
|
18
|
|
|
|
|
|
|
use constant BIG => 1 << 1; |
|
19
|
|
|
|
|
|
|
use constant ULINE => 1 << 2; |
|
20
|
|
|
|
|
|
|
use constant CENTER => 1 << 3; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use constant COLS => 40; # Number of columns the printer supports |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $lpDev = $ENV{'LPDEV'} || '/dev/ttyS0'; |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# These are taken from page 33 of the user manual |
|
27
|
|
|
|
|
|
|
our %chars = ( |
|
28
|
|
|
|
|
|
|
'feedn' => "\x0C", |
|
29
|
|
|
|
|
|
|
'enlarge' => "\x0E", |
|
30
|
|
|
|
|
|
|
'clrenlarge' => "\x0F", |
|
31
|
|
|
|
|
|
|
'lnfeed' => "\x0A", |
|
32
|
|
|
|
|
|
|
'print' => "\x0D", |
|
33
|
|
|
|
|
|
|
'init' => "\x11", |
|
34
|
|
|
|
|
|
|
'invert' => "\x12", |
|
35
|
|
|
|
|
|
|
'red' => "\x13", |
|
36
|
|
|
|
|
|
|
'clear' => "\x18", |
|
37
|
|
|
|
|
|
|
'fcut' => "\x1B\x50\x00", |
|
38
|
|
|
|
|
|
|
'pcut' => "\x1B\x50\x01", |
|
39
|
|
|
|
|
|
|
'uline' => "\x1B\x2D\x01", |
|
40
|
|
|
|
|
|
|
'clruline' => "\x1B\x2D\x00", |
|
41
|
|
|
|
|
|
|
'buzzer' => "\x1E" |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new |
|
46
|
|
|
|
|
|
|
{ |
|
47
|
|
|
|
|
|
|
my $invocant = shift; |
|
48
|
|
|
|
|
|
|
my $class = ref($invocant) || $invocant; |
|
49
|
|
|
|
|
|
|
my $self = { @_ }; |
|
50
|
|
|
|
|
|
|
bless ($self, $class); |
|
51
|
|
|
|
|
|
|
return $self; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub print |
|
55
|
|
|
|
|
|
|
{ |
|
56
|
|
|
|
|
|
|
my $self = shift; |
|
57
|
|
|
|
|
|
|
my @lines = split("\n", wrap(shift, COLS - 2)); # Wrap shorter to prevent weird breaking issues |
|
58
|
|
|
|
|
|
|
my $modes = shift || 0; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sysopen(LP, $lpDev, O_WRONLY | O_APPEND); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
print LP $chars{'enlarge'} if ($modes & BIG); |
|
63
|
|
|
|
|
|
|
print LP $chars{'uline'} if ($modes & ULINE); |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
foreach my $line (@lines) |
|
66
|
|
|
|
|
|
|
{ |
|
67
|
|
|
|
|
|
|
$line = $self->centerText($line) if ($modes & CENTER); |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
print LP $chars{'red'} if ($modes & RED); |
|
70
|
|
|
|
|
|
|
print LP $line; |
|
71
|
|
|
|
|
|
|
print LP "\n"; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
print LP $chars{'clruline'} if ($modes & ULINE); |
|
75
|
|
|
|
|
|
|
print LP $chars{'clrenlarge'} if ($modes & BIG); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
close(LP); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub cut |
|
82
|
|
|
|
|
|
|
{ |
|
83
|
|
|
|
|
|
|
my $self = shift; |
|
84
|
|
|
|
|
|
|
my $partial = shift; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sysopen(LP, $lpDev, O_WRONLY | O_APPEND); |
|
87
|
|
|
|
|
|
|
if (defined($partial)) |
|
88
|
|
|
|
|
|
|
{ |
|
89
|
|
|
|
|
|
|
print LP $chars{'pcut'}; |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
else |
|
92
|
|
|
|
|
|
|
{ |
|
93
|
|
|
|
|
|
|
print LP $chars{'fcut'}; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
close(LP); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub feed |
|
100
|
|
|
|
|
|
|
{ |
|
101
|
|
|
|
|
|
|
my $self = shift; |
|
102
|
|
|
|
|
|
|
my $num = shift || 1; |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sysopen(LP, $lpDev, O_WRONLY | O_APPEND); |
|
105
|
|
|
|
|
|
|
print LP $chars{'lnfeed'} x $num; |
|
106
|
|
|
|
|
|
|
close(LP); |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub beep |
|
110
|
|
|
|
|
|
|
{ |
|
111
|
|
|
|
|
|
|
sysopen(LP, $lpDev, O_WRONLY | O_APPEND); |
|
112
|
|
|
|
|
|
|
print LP $chars{'buzzer'}; |
|
113
|
|
|
|
|
|
|
close(LP); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub centerText |
|
117
|
|
|
|
|
|
|
{ |
|
118
|
|
|
|
|
|
|
my $self = shift; |
|
119
|
|
|
|
|
|
|
my $text = shift; |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
my $len = length($text); |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
return $text if($len >= COLS); #TODO: this might want to warn/croak |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
return (' ' x ((COLS - $len) / 2) . $text); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# make us eval true |
|
129
|
|
|
|
|
|
|
1; |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
__END__ |