File Coverage

blib/lib/Device/Pertelian.pm
Criterion Covered Total %
statement 15 44 34.0
branch 0 8 0.0
condition n/a
subroutine 5 10 50.0
pod 3 3 100.0
total 23 65 35.3


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