use
5.008001;
our
$VERSION
=
'0.031'
;
@IO::LCDproc::Client::ISA
=
qw(IO::LCDproc)
;
sub
new {
my
$proto
=
shift
;
my
$class
=
ref
(
$proto
) ||
$proto
;
my
%params
=
@_
;
croak
"No name for Client: $!"
unless
(
$params
{name});
my
$self
= {};
$self
->{name} =
$params
{name};
$self
->{host} =
$params
{host} ||
"localhost"
;
$self
->{port} =
$params
{port} ||
"13666"
;
$self
->{cmd} =
"client_set name {$self->{name}}\n"
;
$self
->{screen} =
undef
;
bless
(
$self
,
$class
);
return
$self
;
}
sub
add {
my
$self
=
shift
;
$self
->{screen} =
shift
;
}
sub
connect
{
my
$self
=
shift
;
$self
->{lcd} = IO::Socket::INET->new(
Proto
=>
"tcp"
,
PeerAddr
=>
"$self->{host}"
,
PeerPort
=>
"$self->{port}"
) or croak
"Cannot connect to LCDproc port: $!"
;
$self
->{lcd}->autoflush();
sleep
1;
}
sub
initialize {
my
$self
=
shift
;
my
$fh
=
$self
->{lcd};
my
$msgs
;
print
$fh
"hello\n"
;
$msgs
= <
$fh
>;
if
(
$msgs
=~ /lcd.+wid\s+(\d+)\s+hgt\s+(\d+)/){
$self
->{width} = $1;
$self
->{height} = $2;
}
else
{
croak
"No stats reported...: $!"
;
}
fcntl
(
$fh
, F_SETFL, O_NONBLOCK );
print
$fh
$self
->{cmd};
print
$fh
$self
->{screen}->{cmd};
print
$fh
$self
->{screen}->{set};
foreach
(@{
$self
->{screen}->{widgets}}){
print
$fh
$_
->{cmd};
}
}
@IO::LCDproc::Screen::ISA
=
qw(IO::LCDproc)
;
sub
new {
my
$proto
=
shift
;
my
$class
=
ref
(
$proto
) ||
$proto
;
my
%params
=
@_
;
croak
"No name for Screen: $!"
unless
(
$params
{name});
my
$self
= {};
$self
->{client} =
$params
{client} || croak
"No Client: $!"
;
$self
->{name} =
$params
{name};
$self
->{heartbeat}=
$params
{heartbeat} ||
"on"
;
$self
->{cmd} =
"screen_add $self->{name}\n"
;
$self
->{set} =
"screen_set $self->{name} name {$self->{client}->{name}}\n"
;
$self
->{set} .=
"screen_set $self->{name} heartbeat $self->{heartbeat}\n"
;
$self
->{widgets} =
undef
;
bless
(
$self
,
$class
);
return
$self
;
}
sub
add {
my
$self
=
shift
;
foreach
(
@_
){
push
@{
$self
->{widgets}},
$_
;
}
}
@IO::LCDproc::Client::ISA
=
qw(IO::LCDproc)
;
sub
new {
my
$proto
=
shift
;
my
$class
=
ref
(
$proto
) ||
$proto
;
my
%params
=
@_
;
croak
"No name for Widget: $!"
unless
(
$params
{name});
my
$self
= {};
$self
->{screen} =
$params
{screen} || croak
"No Screen: $!"
;
$self
->{name} =
$params
{name};
$self
->{align} =
$params
{align} ||
"left"
;
$self
->{type} =
$params
{type} ||
"string"
;
$self
->{xPos} =
$params
{xPos} ||
""
;
$self
->{yPos} =
$params
{yPos} ||
""
;
$self
->{data} =
$params
{data}
if
(
$params
{data} );
$self
->{cmd} =
"widget_add $self->{screen}->{name} $self->{name} $self->{type}\n"
;
bless
(
$self
,
$class
);
return
$self
;
}
sub
set {
my
$self
=
shift
;
my
%params
=
@_
;
$self
->{xPos} =
$params
{xPos}
if
(
$params
{xPos});
$self
->{yPos} =
$params
{yPos}
if
(
$params
{yPos});
$self
->{data} =
$params
{data}
if
(
$params
{data});
$self
->{data} =
" "
x
$self
->{screen}{client}{width}
if
(
length
(
$self
->{data} ) < 1 );
my
$fh
=
$self
->{screen}->{client}->{lcd};
print
$fh
"widget_set $self->{screen}->{name} $self->{name} $self->{xPos} $self->{yPos} {"
.
(
$self
->{align} =~ /center/ ?
$self
->_center(
$self
->{data}) :
$self
->{data}) .
"}\n"
;
}
sub
_center {
my
$self
=
shift
;
return
(
" "
x ( (
$self
->{screen}->{client}->{width} -
length
(
$_
[0] ) ) / 2 ) .
$_
[0]);
}
sub
save {
my
$self
=
shift
;
$self
->{saved} =
$self
->{data};
}
sub
restore {
my
$self
=
shift
;
$self
->{data} =
$self
->{saved};
$self
->{saved} =
""
;
}
1;