| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Device::Pertelian; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 42369 | use warnings; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 57 |  | 
| 4 | 2 |  |  | 2 |  | 11 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 48 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 2 |  |  | 2 |  | 8520 | use fields qw/device _fh/; | 
|  | 2 |  |  |  |  | 4813 |  | 
|  | 2 |  |  |  |  | 18 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 2 |  |  | 2 |  | 3041 | use IO::Handle; | 
|  | 2 |  |  |  |  | 14503 |  | 
|  | 2 |  |  |  |  | 89 |  | 
| 9 | 2 |  |  | 2 |  | 1626 | use Time::HiRes qw/usleep/; | 
|  | 2 |  |  |  |  | 3038 |  | 
|  | 2 |  |  |  |  | 9 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | =head1 NAME | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | Device::Pertelian - a driver for the Pertelian X2040 USB LCD | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =cut | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | 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 |  |  |  |  |  |  | sub new { | 
| 43 | 1 |  |  | 1 | 1 | 16 | my $self = shift; | 
| 44 | 1 |  |  |  |  | 3 | my $device = shift; | 
| 45 |  |  |  |  |  |  |  | 
| 46 | 1 | 50 |  |  |  | 5 | unless (ref $self) { | 
| 47 | 1 |  |  |  |  | 8 | $self = fields::new($self); | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 | 1 | 50 |  |  |  | 9918 | if ($device) { | 
| 51 | 1 |  |  |  |  | 9 | $self->_open($device); | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 1 |  |  |  |  | 13 | return $self; | 
| 55 |  |  |  |  |  |  | } | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | sub _open { | 
| 58 | 1 |  |  | 1 |  | 5 | my ($self, $device) = @_; | 
| 59 |  |  |  |  |  |  |  | 
| 60 | 1 | 50 |  | 1 |  | 54 | open $self->{_fh}, '>', $device | 
|  | 1 |  |  |  |  | 14 |  | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 15 |  | 
| 61 |  |  |  |  |  |  | or return; | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 1 |  |  |  |  | 2070 | $self->{_fh}->autoflush(1); | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 1 |  |  |  |  | 82 | foreach (0x38, 0x06, 0x10, 0x0c) { | 
| 66 | 4 |  |  |  |  | 70 | $self->_writeout(pack('CC', 0xfe, $_)); | 
| 67 |  |  |  |  |  |  | } | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 1 |  |  |  |  | 11 | return 1; | 
| 70 |  |  |  |  |  |  | } | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | sub _writeout { | 
| 73 | 19 |  |  | 19 |  | 52 | my ($self, $buf) = @_; | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 19 | 50 |  |  |  | 88 | if ($self->{_fh}) { | 
| 76 | 19 |  |  |  |  | 30 | print {$self->{_fh}} $buf; | 
|  | 19 |  |  |  |  | 90 |  | 
| 77 | 19 |  |  |  |  | 21951 | 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 |  |  |  |  |  |  | sub writeline { | 
| 96 | 1 |  |  | 1 | 1 | 3 | my $self = shift; | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 1 |  |  |  |  | 5 | my ($row, $text) = @_; | 
| 99 | 1 |  |  |  |  | 6 | my @rowvals = ( | 
| 100 |  |  |  |  |  |  | 0x80, | 
| 101 |  |  |  |  |  |  | 0x80 + 0x40, | 
| 102 |  |  |  |  |  |  | 0x80 + 0x14, | 
| 103 |  |  |  |  |  |  | 0x80 + 0x54); | 
| 104 | 1 |  |  |  |  | 9 | my $buf = pack('CC', 0xfe, $rowvals[$row]); | 
| 105 | 1 |  |  |  |  | 11 | $self->_writeout($buf); | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 1 |  |  |  |  | 13 | foreach (split(//, $text)) { | 
| 108 | 13 |  |  |  |  | 56 | $self->_writeout($_); | 
| 109 |  |  |  |  |  |  | } | 
| 110 |  |  |  |  |  |  |  | 
| 111 | 1 |  |  |  |  | 26 | return 1; | 
| 112 |  |  |  |  |  |  | } | 
| 113 |  |  |  |  |  |  |  | 
| 114 |  |  |  |  |  |  | sub clearscreen { | 
| 115 | 1 |  |  | 1 | 1 | 1783 | my $self = shift; | 
| 116 |  |  |  |  |  |  |  | 
| 117 | 1 |  |  |  |  | 9 | $self->_writeout(pack('CC', 0xfe, 1)); | 
| 118 | 1 |  |  |  |  | 10162 | usleep(10000); | 
| 119 |  |  |  |  |  |  | } | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | =head1 AUTHOR | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | Alex Kapranoff, C<<  >> | 
| 124 |  |  |  |  |  |  |  | 
| 125 |  |  |  |  |  |  | =head1 BUGS | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  | Please report any bugs or feature requests to C, or through | 
| 128 |  |  |  |  |  |  | the web interface at L.  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 | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | =item * AnnoCPAN: Annotated CPAN documentation | 
| 146 |  |  |  |  |  |  |  | 
| 147 |  |  |  |  |  |  | L | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | =item * CPAN Ratings | 
| 150 |  |  |  |  |  |  |  | 
| 151 |  |  |  |  |  |  | L | 
| 152 |  |  |  |  |  |  |  | 
| 153 |  |  |  |  |  |  | =item * Search CPAN | 
| 154 |  |  |  |  |  |  |  | 
| 155 |  |  |  |  |  |  | L | 
| 156 |  |  |  |  |  |  |  | 
| 157 |  |  |  |  |  |  | =back | 
| 158 |  |  |  |  |  |  |  | 
| 159 |  |  |  |  |  |  | =head1 DOCUMENTATION | 
| 160 |  |  |  |  |  |  |  | 
| 161 |  |  |  |  |  |  | See L, | 
| 162 |  |  |  |  |  |  | L | 
| 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 |  |  |  |  |  |  | 1; |