script/hello_pert.pl untested

filter: Statementstmt 0.0% 0 / 48 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 70 CC 2 SCAR 10.3
CC
2
Cov
0%
backlight
6.0
Sleep
2.0
writeout
2.0
CRAP 2.8
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use IO::File;
5 use Time::HiRes qw(usleep);
6  
7 my $device = $ARGV[0];
8 die "usage: $0 device" unless defined $device;
9 my $fh = IO::File->new(">$device") or die "Can't open $device: $!";
10 $fh->autoflush(1);
11  
12 init($fh);
13 clearscreen($fh);
14 backlight($fh, 0);
15  
16 my $index = 0;
17 while (1) {
18 writeline($fh, sprintf("Hello World line %d", $index), 1, $index % 4 + 1);
19 ++$index;
20 Sleep(1000);
21 }
22  
23 sub Sleep {
24 my $millesec = shift;
25 usleep($millesec * 1000);
26 }
27  
28 sub writeout {
29 my($fh, $buf) = @_;
30 $fh->print($buf);
31 Sleep(1);
32 }
33  
34 sub writeline {
35 my($fh, $text, $col, $row) = @_;
36 my @rowvals = (undef,
37 0x80 + ($col - 1),
38 0x80 + ($col - 1) +0x40,
39 0x80 + ($col - 1) +0x14,
40 0x80 + ($col - 1) + 0x54);
41 my $buf = pack("cc", 0xfe, $rowvals[$row]);
42 writeout($fh, $buf);
43  
44 foreach (split(//, $text)) {
45 writeout($fh, $_);
46 }
47 }
48  
49 sub clearscreen {
50 my($fh) = @_;
51  
52 my $buf = pack("cc", 0xfe, 1);
53 writeout($fh, $buf);
54 Sleep(10);
55 }
56  
57 sub backlight {
58 my($fh, $state) = @_;
59  
60 my $buf = pack("cc", 0xfe, 2 | $state? 1 : 0);
61 writeout($fh, $buf);
62 }
63  
64 sub init {
65 my($fh) = @_;
66  
67 my $buf = pack("cc", 0xfe, 0x38);
68 writeout($fh, $buf);
69  
70 $buf = pack("cc", 0xfe, 0x06);
71 writeout($fh, $buf);
72  
73 $buf = pack("cc", 0xfe, 0x10);
74 writeout($fh, $buf);
75  
76 $buf = pack("cc", 0xfe, 0x0c);
77 writeout($fh, $buf);
78 }