line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Cobalt::LCD; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
39517
|
use 5.006000; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
34
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
42
|
|
6
|
1
|
|
|
1
|
|
4725
|
use Time::HiRes qw(time usleep); |
|
1
|
|
|
|
|
4092
|
|
|
1
|
|
|
|
|
6
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require Exporter; |
9
|
1
|
|
|
1
|
|
2482
|
use AutoLoader qw(AUTOLOAD); |
|
1
|
|
|
|
|
2507
|
|
|
1
|
|
|
|
|
7
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
) ] ); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @EXPORT = qw( |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub new { |
26
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $self = { |
29
|
|
|
|
|
|
|
'_SYSTEM_TYPE' => '', |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
'_PROG_GETIP' => '/sbin/lcd-getip', |
32
|
|
|
|
|
|
|
'_PROG_WRITE' => '/sbin/lcd-write', |
33
|
|
|
|
|
|
|
'_PROG_FLASH' => '/sbin/lcd-flash', |
34
|
|
|
|
|
|
|
'_PROG_READBUTTON' => '/sbin/readbutton', |
35
|
|
|
|
|
|
|
'_PROC_SYSTYPE' => '/proc/cobalt/systype', |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
'_DEBOUNCE' => 0, |
38
|
|
|
|
|
|
|
'_DEBOUNCE_TIMEOUT' => 0.5, |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
'_USLEEP' => 1000, |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
'BUTTON_NONE' => 0, |
43
|
|
|
|
|
|
|
'BUTTON_RESET' => 0, |
44
|
|
|
|
|
|
|
'BUTTON_SELECT' => 0, |
45
|
|
|
|
|
|
|
'BUTTON_EXIT' => 0, |
46
|
|
|
|
|
|
|
'BUTTON_LEFT' => 0, |
47
|
|
|
|
|
|
|
'BUTTON_RIGHT' => 0, |
48
|
|
|
|
|
|
|
'BUTTON_UP' => 0, |
49
|
|
|
|
|
|
|
'BUTTON_DOWN' => 0, |
50
|
|
|
|
|
|
|
}; |
51
|
|
|
|
|
|
|
|
52
|
0
|
|
|
|
|
|
bless $self, $proto; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
$self->lcd_init(); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
return $self; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub lcd_init ($) { |
60
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
61
|
0
|
0
|
|
|
|
|
open(PROC,'<'.$self->{_PROC_SYSTYPE}) or die "Cannot open $self->{_PROC_SYSTYPE}!\nCheck to be sure the Cobalt drivers are installed in the kernel."; |
62
|
0
|
|
|
|
|
|
chomp($self->{_SYSTEM_TYPE} = lc()); |
63
|
0
|
|
|
|
|
|
close (PROC); |
64
|
|
|
|
|
|
|
|
65
|
0
|
0
|
|
|
|
|
if ($self->{_SYSTEM_TYPE} eq 'pacifica') { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$self->{BUTTON_NONE} = 0; |
67
|
0
|
|
|
|
|
|
$self->{BUTTON_RESET} = 64512; |
68
|
0
|
|
|
|
|
|
$self->{BUTTON_SELECT} = 32256; |
69
|
0
|
|
|
|
|
|
$self->{BUTTON_EXIT} = 48640; |
70
|
0
|
|
|
|
|
|
$self->{BUTTON_LEFT} = 64000; |
71
|
0
|
|
|
|
|
|
$self->{BUTTON_RIGHT} = 56832; |
72
|
0
|
|
|
|
|
|
$self->{BUTTON_UP} = 62976; |
73
|
0
|
|
|
|
|
|
$self->{BUTTON_DOWN} = 60928; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} elsif ($self->{_SYSTEM_TYPE} eq 'carmel') { |
76
|
0
|
|
|
|
|
|
$self->{BUTTON_NONE} = 0; |
77
|
0
|
|
|
|
|
|
$self->{BUTTON_RESET} = 64512; |
78
|
0
|
|
|
|
|
|
$self->{BUTTON_SELECT} = 32256; |
79
|
0
|
|
|
|
|
|
$self->{BUTTON_EXIT} = 48640; |
80
|
0
|
|
|
|
|
|
$self->{BUTTON_LEFT} = 64000; |
81
|
0
|
|
|
|
|
|
$self->{BUTTON_RIGHT} = 56832; |
82
|
0
|
|
|
|
|
|
$self->{BUTTON_UP} = 62976; |
83
|
0
|
|
|
|
|
|
$self->{BUTTON_DOWN} = 60928; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} elsif ($self->{_SYSTEM_TYPE} eq 'monterey') { |
86
|
0
|
|
|
|
|
|
$self->{BUTTON_NONE} = 0; |
87
|
0
|
|
|
|
|
|
$self->{BUTTON_RESET} = 64512; |
88
|
0
|
|
|
|
|
|
$self->{BUTTON_SELECT} = 32256; |
89
|
0
|
|
|
|
|
|
$self->{BUTTON_EXIT} = 48640; |
90
|
0
|
|
|
|
|
|
$self->{BUTTON_LEFT} = 64000; |
91
|
0
|
|
|
|
|
|
$self->{BUTTON_RIGHT} = 56832; |
92
|
0
|
|
|
|
|
|
$self->{BUTTON_UP} = 62976; |
93
|
0
|
|
|
|
|
|
$self->{BUTTON_DOWN} = 60928; |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
} elsif ($self->{_SYSTEM_TYPE} eq 'alpine') { |
96
|
0
|
|
|
|
|
|
$self->{BUTTON_NONE} = 0; |
97
|
0
|
|
|
|
|
|
$self->{BUTTON_RESET} = 64512; |
98
|
0
|
|
|
|
|
|
$self->{BUTTON_SELECT} = 32256; |
99
|
0
|
|
|
|
|
|
$self->{BUTTON_EXIT} = 48640; |
100
|
0
|
|
|
|
|
|
$self->{BUTTON_LEFT} = 64000; |
101
|
0
|
|
|
|
|
|
$self->{BUTTON_RIGHT} = 56832; |
102
|
0
|
|
|
|
|
|
$self->{BUTTON_UP} = 62976; |
103
|
0
|
|
|
|
|
|
$self->{BUTTON_DOWN} = 60928; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} elsif ($self->{_SYSTEM_TYPE} eq 'bigbear') { |
106
|
0
|
|
|
|
|
|
$self->{BUTTON_NONE} = 0; |
107
|
0
|
|
|
|
|
|
$self->{BUTTON_RESET} = 64512; |
108
|
0
|
|
|
|
|
|
$self->{BUTTON_SELECT} = 32256; |
109
|
0
|
|
|
|
|
|
$self->{BUTTON_EXIT} = 48640; |
110
|
0
|
|
|
|
|
|
$self->{BUTTON_LEFT} = 64000; |
111
|
0
|
|
|
|
|
|
$self->{BUTTON_RIGHT} = 56832; |
112
|
0
|
|
|
|
|
|
$self->{BUTTON_UP} = 62976; |
113
|
0
|
|
|
|
|
|
$self->{BUTTON_DOWN} = 60928; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
} else { |
116
|
0
|
|
|
|
|
|
die sprintf("Cannot determine the system type of the Cobalt.\n/proc/cobalt/systype reports %s.",$self->{_SYSTEM_TYPE}); |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub write ($$$) { |
121
|
0
|
|
|
0
|
0
|
|
my ($self,$line_a,$line_b) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
return system(sprintf('%s "%s" "%s"',$self->{_PROG_WRITE},$line_a,$line_b)); |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub flash ($) { |
127
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
128
|
0
|
|
|
|
|
|
warn "flash() is not currently supported as it locks the LCD."; return; |
|
0
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
#return system(sprintf('%s',$self->{_PROG_FLASH})); |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub buttonstate ($) { |
133
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
return system(sprintf('%s',$self->{_PROG_READBUTTON})) |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
sub waitforbutton ($$$) { |
139
|
0
|
|
|
0
|
0
|
|
my ($self,$timeout_time,$maxdown_time) = @_; |
140
|
0
|
|
|
|
|
|
my ($button,$start_time) = (0,0); |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
while ($self->{_DEBOUNCE} > time()) { |
143
|
0
|
|
|
|
|
|
usleep $self->{_USLEEP}; |
144
|
|
|
|
|
|
|
}; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
$timeout_time += time(); |
147
|
|
|
|
|
|
|
|
148
|
0
|
|
|
|
|
|
while (($button = $self->buttonstate()) == 0) { |
149
|
0
|
|
|
|
|
|
usleep $self->{_USLEEP}; |
150
|
0
|
0
|
|
|
|
|
return ([0,0]) if ($timeout_time <= time()); |
151
|
|
|
|
|
|
|
} |
152
|
0
|
|
|
|
|
|
$start_time = time(); |
153
|
0
|
0
|
|
|
|
|
$maxdown_time = 60 if (!defined($maxdown_time)); |
154
|
0
|
|
|
|
|
|
$maxdown_time += time(); |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
while ($self->buttonstate() != 0) { |
157
|
0
|
|
|
|
|
|
usleep $self->{_USLEEP}; |
158
|
0
|
0
|
|
|
|
|
if ($maxdown_time <= time()) { |
159
|
0
|
|
|
|
|
|
$self->{_DEBOUNCE} = time() + $self->{_DEBOUNCE_TIMEOUT}; |
160
|
0
|
|
|
|
|
|
return ([$button,time()-$start_time]); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
}; |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
return ([$button,time()-$start_time]); |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
sub getip ($$$) { |
168
|
0
|
|
|
0
|
0
|
|
my ($self,$line_a,$ip) = @_; |
169
|
|
|
|
|
|
|
|
170
|
0
|
|
|
|
|
|
my $iip = `$self->{_PROG_GETIP} -1 \"$line_a\" -i $ip`; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
foreach (split(/\./,$iip,4)) { |
173
|
0
|
0
|
0
|
|
|
|
if (($_ < 0) || ($_ > 255)) { |
174
|
0
|
|
|
|
|
|
$iip = '' |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
return $iip; |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
__END__ |