lib/Device/Pertelian.pm

filter: Statementstmt 100% 46 / 46 Branchbran 50.0% 4 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 94.0% 63 / 67 CC 7 SCAR 7.0
CC
7
Cov
93%
new
3.1
_open
3.0
_writeout
2.0
CRAP 2.0
« script/hello_pert.pl ↑ Summary
1 package Device::Pertelian;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use fields qw/device _fh/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use IO::Handle;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Time::HiRes qw/usleep/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 =head1 NAME
12  
13 Device::Pertelian - a driver for the Pertelian X2040 USB LCD
14  
15 =cut
16  
17 2 our $VERSION = '0.03';
18  
19 =head1 SYNOPSIS
20  
21 If you have a Pertelian X2040 USB LCD screen, then you can do
22 things with it.
23  
24 use Device::Pertelian;
25  
26 my $lcd = Device::Pertelian->new('/dev/ttyUSB0');
27 $lcd->clearscreen();
28  
29 # write to the top row
30 $lcd->writeline(0, "Hello, world!");
31 ...
32  
33 =head1 METHODS
34  
35 =head2 new
36  
37 The constructor accepts one parameter, $device, which is a path in /dev.
38 You may find it out from your logs.
39  
40 =cut
41  
42 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.2
Pod documented
43 1 my $self = shift;
44 1 my $device = shift;
45  
46 1 ▶ unless (ref $self) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 1 0 1
47 1 $self = fields::new($self);
48 }
49  
50 1 ▶ if ($device) {
Branch: 1 branch
BranchTrueFalseTotal
if ($device) 1 0 1
51 1 $self->_open($device);
52 }
53  
54 1 return $self;
55 }
56  
57 1 ▶sub _open {
Subroutine _open: called CC=3 SCAR=11.0
58 1 my ($self, $device) = @_;
59  
60 1 ▶ open $self->{_fh}, '>', $device
Branch: 1 branch
BranchTrueFalseTotal
open $self->{"_fh"}, ">", $device or return 1 0 1
61 or return;
62  
63 1 $self->{_fh}->autoflush(1);
64  
65 1 foreach (0x38, 0x06, 0x10, 0x0c) {
66 4 $self->_writeout(pack('CC', 0xfe, $_));
67 }
68  
69 1 return 1;
70 }
71  
72 19 ▶sub _writeout {
Subroutine _writeout: called CC=2 SCAR=7.0
73 19 my ($self, $buf) = @_;
74  
75 19 ▶ if ($self->{_fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_fh"}) 19 0 19
76 19 print {$self->{_fh}} $buf;
77 19 usleep(1000);
78 }
79 }
80  
81 =head2 clearscreen
82  
83 This function does a simple thing -- clears all the 4 lines of the screen.
84  
85 =cut
86  
87 =head2 writeline
88  
89 This function takes two parameters, $row and $text. The screen has 4 rows,
90 so you may pass a number from 0 to 3 as $row and the $text should be
91 under 20 characters, that is the width of the screen.
92  
93 =cut
94  
95 1 ▶sub writeline {
Subroutine writeline: called CC=2 SCAR=6.9
Pod documented
96 1 my $self = shift;
97  
98 1 my ($row, $text) = @_;
99 1 my @rowvals = (
100 0x80,
101 0x80 + 0x40,
102 0x80 + 0x14,
103 0x80 + 0x54);
104 1 my $buf = pack('CC', 0xfe, $rowvals[$row]);
105 1 $self->_writeout($buf);
106  
107 1 foreach (split(//, $text)) {
108 13 $self->_writeout($_);
109 }
110  
111 1 return 1;
112 }
113  
114 1 ▶sub clearscreen {
Subroutine clearscreen: called CC=1 SCAR=0.0
Pod documented
115 1 my $self = shift;
116  
117 1 $self->_writeout(pack('CC', 0xfe, 1));
118 1 usleep(10000);
119 }
120  
121 =head1 AUTHOR
122  
123 Alex Kapranoff, C<< <alex at kapranoff.ru> >>
124  
125 =head1 BUGS
126  
127 Please report any bugs or feature requests to C<bug-device-pertelian at rt.cpan.org>, or through
128 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Device-Pertelian>. I will be notified, and then you'll
129 automatically be notified of progress on your bug as I make changes.
130  
131 =head1 SUPPORT
132  
133 You can find documentation for this module with the perldoc command.
134  
135 perldoc Device::Pertelian
136  
137 You can also look for information at:
138  
139 =over 4
140  
141 =item * RT: CPAN's request tracker
142  
143 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Device-Pertelian>
144  
145 =item * AnnoCPAN: Annotated CPAN documentation
146  
147 L<http://annocpan.org/dist/Device-Pertelian>
148  
149 =item * CPAN Ratings
150  
151 L<http://cpanratings.perl.org/d/Device-Pertelian>
152  
153 =item * Search CPAN
154  
155 L<http://search.cpan.org/dist/Device-Pertelian>
156  
157 =back
158  
159 =head1 DOCUMENTATION
160  
161 See L<http://www.ekenrooi.net/lcd/lcd.shtml>,
162 L<http://web.archive.org/web/20100903020330/http://developer.pertelian.com/index.php?option=com_content&view=section&id=3&Itemid=9>
163 and the pertd software that vanished with the main website pertelian.com.
164  
165 =head1 COPYRIGHT & LICENSE
166  
167 Copyright 2008 Alex Kapranoff, all rights reserved.
168  
169 This program is released under the following license: GPL version 3
170  
171 In the included pertd.tgz archive there is code by:
172 Frans Meulenbroeks, Ron Lauzon, Pred S. Bundalo, Chmouel Boudjnah,
173 W. Richard Stevens.
174  
175 The code in pertd.tgz is either in Public Domain or available for
176 distribution in unmodified form. See the relevant files.
177  
178 =cut
179  
180 2 1;
« script/hello_pert.pl ↑ Summary