line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
30483
|
use 5.008001; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
84
|
|
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.037'; |
4
|
|
|
|
|
|
|
package IO::LCDproc; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
############################################################################### |
7
|
|
|
|
|
|
|
package IO::LCDproc::Client; |
8
|
|
|
|
|
|
|
@IO::LCDproc::Client::ISA = qw(IO::LCDproc); |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
106
|
|
11
|
1
|
|
|
1
|
|
13
|
use Fcntl; |
|
1
|
|
|
|
|
23
|
|
|
1
|
|
|
|
|
366
|
|
12
|
1
|
|
|
1
|
|
6280
|
use IO::Socket::INET; |
|
1
|
|
|
|
|
27596
|
|
|
1
|
|
|
|
|
8
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
0
|
|
|
0
|
|
|
my $proto = shift; |
16
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
17
|
0
|
|
|
|
|
|
my %params = @_; |
18
|
0
|
0
|
|
|
|
|
croak "No name for Client: $!" unless($params{name}); |
19
|
0
|
|
|
|
|
|
my $self = {}; |
20
|
0
|
|
|
|
|
|
$self->{name} = $params{name}; |
21
|
0
|
|
0
|
|
|
|
$self->{host} = $params{host} || "localhost"; |
22
|
0
|
|
0
|
|
|
|
$self->{port} = $params{port} || "13666"; |
23
|
0
|
|
|
|
|
|
$self->{cmd} = "client_set name {$self->{name}}\n"; |
24
|
0
|
|
|
|
|
|
$self->{screen} = undef; |
25
|
0
|
|
|
|
|
|
bless ($self, $class); |
26
|
0
|
|
|
|
|
|
return $self; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub add { |
30
|
0
|
|
|
0
|
|
|
my $self = shift; |
31
|
0
|
|
|
|
|
|
$self->{screen} = shift; |
32
|
0
|
|
|
|
|
|
$self->{screen}{client} = $self; |
33
|
0
|
|
|
|
|
|
$self->{screen}{set} = "screen_set $self->{screen}{name} name {$self->{screen}{name}}\n"; |
34
|
0
|
|
|
|
|
|
$self->{screen}{set}.= "screen_set $self->{screen}{name} heartbeat $self->{screen}{heartbeat}\n"; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub connect { |
38
|
0
|
|
|
0
|
|
|
my $self = shift; |
39
|
0
|
0
|
|
|
|
|
$self->{lcd} = IO::Socket::INET->new( |
40
|
|
|
|
|
|
|
Proto => "tcp", PeerAddr => "$self->{host}", PeerPort => "$self->{port}" |
41
|
|
|
|
|
|
|
) or croak "Cannot connect to LCDproc port: $!"; |
42
|
0
|
|
|
|
|
|
$self->{lcd}->autoflush(); |
43
|
0
|
|
|
|
|
|
sleep 1; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub initialize { |
47
|
0
|
|
|
0
|
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my $fh = $self->{lcd}; |
49
|
0
|
|
|
|
|
|
my $msgs; |
50
|
0
|
|
|
|
|
|
print $fh "hello\n"; |
51
|
0
|
|
|
|
|
|
$msgs = <$fh>; |
52
|
0
|
0
|
|
|
|
|
if($msgs =~ /lcd.+wid\s+(\d+)\s+hgt\s+(\d+)\s+cellwid\s+(\d+)\s+cellhgt\s+(\d+)/){ |
53
|
0
|
|
|
|
|
|
$self->{width} = $1; |
54
|
0
|
|
|
|
|
|
$self->{height} = $2; |
55
|
0
|
|
|
|
|
|
$self->{cellwidth} = $3; |
56
|
0
|
|
|
|
|
|
$self->{cellheight} = $4; |
57
|
|
|
|
|
|
|
} else { |
58
|
0
|
|
|
|
|
|
croak "No stats reported...: $!"; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
|
|
|
|
|
fcntl( $fh, F_SETFL, O_NONBLOCK ); |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
print $fh $self->{cmd}; |
63
|
0
|
|
|
|
|
|
print $fh $self->{screen}{cmd}; |
64
|
0
|
|
|
|
|
|
print $fh $self->{screen}{set}; |
65
|
0
|
|
|
|
|
|
foreach(@{$self->{screen}{widgets}}){ |
|
0
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
print $fh $_->{cmd}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub answer { |
71
|
0
|
|
|
0
|
|
|
my $self = shift; |
72
|
0
|
|
|
|
|
|
my $fh = $self->{lcd}; |
73
|
0
|
|
|
|
|
|
my $answ; |
74
|
0
|
|
|
|
|
|
$answ = <$fh>; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return $answ; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub flushAnswers { |
80
|
0
|
|
|
0
|
|
|
my $self = shift; |
81
|
0
|
|
|
|
|
|
while ($self->answer()) {} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
############################################################################### |
86
|
|
|
|
|
|
|
package IO::LCDproc::Screen; |
87
|
|
|
|
|
|
|
@IO::LCDproc::Screen::ISA = qw(IO::LCDproc); |
88
|
|
|
|
|
|
|
|
89
|
1
|
|
|
1
|
|
1305
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
289
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub new { |
92
|
0
|
|
|
0
|
|
|
my $proto = shift; |
93
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
94
|
0
|
|
|
|
|
|
my %params = @_; |
95
|
0
|
0
|
|
|
|
|
croak "No name for Screen: $!" unless($params{name}); |
96
|
0
|
|
|
|
|
|
my $self = {}; |
97
|
0
|
|
|
|
|
|
$self->{name} = $params{name}; |
98
|
0
|
|
0
|
|
|
|
$self->{heartbeat} = $params{heartbeat} || "on"; |
99
|
0
|
|
|
|
|
|
$self->{cmd} = "screen_add $self->{name}\n"; |
100
|
0
|
|
|
|
|
|
$self->{widgets} = undef; |
101
|
0
|
|
|
|
|
|
bless ($self, $class); |
102
|
0
|
|
|
|
|
|
return $self; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub add { |
106
|
0
|
|
|
0
|
|
|
my $self = shift; |
107
|
0
|
|
|
|
|
|
foreach (@_){ |
108
|
0
|
|
|
|
|
|
push @{$self->{widgets}}, $_; |
|
0
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$_->{screen}=$self; |
110
|
0
|
|
|
|
|
|
$_->{cmd} = "widget_add $_->{screen}{name} $_->{name} $_->{type}\n"; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub set_prio { |
115
|
0
|
|
|
0
|
|
|
my $self = shift; |
116
|
0
|
|
|
|
|
|
my $prio = shift; |
117
|
0
|
|
|
|
|
|
my $fh = $self->{client}->{lcd}; |
118
|
0
|
|
|
|
|
|
print $fh "screen_set $self->{name} -priority $prio\n"; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
############################################################################### |
122
|
|
|
|
|
|
|
package IO::LCDproc::Widget; |
123
|
|
|
|
|
|
|
@IO::LCDproc::Client::ISA = qw(IO::LCDproc); |
124
|
|
|
|
|
|
|
|
125
|
1
|
|
|
1
|
|
9
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
52
|
|
126
|
1
|
|
|
1
|
|
1626
|
use overload '++' => \&xIncrement; |
|
1
|
|
|
|
|
1107
|
|
|
1
|
|
|
|
|
8
|
|
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub new { |
129
|
0
|
|
|
0
|
|
|
my $proto = shift; |
130
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
131
|
0
|
|
|
|
|
|
my %params = @_; |
132
|
0
|
0
|
|
|
|
|
croak "No name for Widget: $!" unless($params{name}); |
133
|
0
|
|
|
|
|
|
my $self = {}; |
134
|
0
|
|
|
|
|
|
$self->{name} = $params{name}; |
135
|
0
|
|
0
|
|
|
|
$self->{align} = $params{align} || "left"; |
136
|
0
|
|
0
|
|
|
|
$self->{type} = $params{type} || "string"; |
137
|
0
|
|
0
|
|
|
|
$self->{xPos} = $params{xPos} || ""; |
138
|
0
|
|
0
|
|
|
|
$self->{yPos} = $params{yPos} || ""; |
139
|
0
|
0
|
|
|
|
|
$self->{data} = $params{data} if( $params{data} ); |
140
|
0
|
|
|
|
|
|
bless ($self, $class); |
141
|
0
|
|
|
|
|
|
return $self; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub set { |
145
|
0
|
|
|
0
|
|
|
my $self = shift; |
146
|
0
|
|
|
|
|
|
my %params = @_; |
147
|
0
|
0
|
|
|
|
|
$self->{xPos} = $params{xPos} if($params{xPos}); |
148
|
0
|
0
|
|
|
|
|
$self->{yPos} = $params{yPos} if($params{yPos}); |
149
|
0
|
0
|
|
|
|
|
$self->{data} = $params{data} if($params{data}); |
150
|
0
|
0
|
|
|
|
|
$self->{data} = " " x $self->{screen}{client}{width} if(length( $self->{data} ) < 1 ); |
151
|
0
|
|
|
|
|
|
my $fh = $self->{screen}->{client}->{lcd}; |
152
|
0
|
0
|
|
|
|
|
print $fh "widget_set $self->{screen}->{name} $self->{name} $self->{xPos} $self->{yPos} {" . |
|
|
0
|
|
|
|
|
|
153
|
|
|
|
|
|
|
($self->{align} =~ /center/ ? $self->_center($self->{data}) : |
154
|
|
|
|
|
|
|
($self->{align} =~ /right/ ? $self->_right($self->{data}) : $self->{data}) |
155
|
|
|
|
|
|
|
) . "}\n"; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub _center { |
159
|
0
|
|
|
0
|
|
|
my $self = shift; |
160
|
0
|
|
|
|
|
|
return(" " x (($self->{screen}{client}{width} - length($_[0]))/2) . $_[0]); |
161
|
|
|
|
|
|
|
} |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
sub _right { |
164
|
0
|
|
|
0
|
|
|
my $self = shift; |
165
|
0
|
|
|
|
|
|
return(" " x (($self->{screen}{client}{width} - length($_[0]))) . $_[0]); |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub save { |
169
|
0
|
|
|
0
|
|
|
my $self = shift; |
170
|
0
|
|
|
|
|
|
$self->{saved} = $self->{data}; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
sub restore { |
174
|
0
|
|
|
0
|
|
|
my $self = shift; |
175
|
0
|
|
|
|
|
|
$self->{data} = $self->{saved}; |
176
|
0
|
|
|
|
|
|
$self->{saved} = ""; |
177
|
0
|
|
|
|
|
|
$self->set; |
178
|
|
|
|
|
|
|
} |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
sub xIncrement { |
181
|
0
|
|
|
0
|
|
|
my $self = shift; |
182
|
0
|
|
|
|
|
|
$self->{xPos}++ |
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
1; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
__END__ |