Audio-Radio-XM-PCR
view release on metacpan or search on metacpan
lib/Audio/Radio/XM/PCR.pm view on Meta::CPAN
sub port_state {
my $self = shift;
my $val = shift;
if (!defined($self->{'_port_state'})) {
$self->{'_port_state'} = 'Closed';
}
$self->{_port_state} = $val if (defined($val));
return $self->{_port_state};
}
sub command {
my $self = shift;
my $command = shift;
my $channel = shift;
$self->_write($command, $channel);
$self->_monitor;
}
sub set_trigger {
my $self=shift;
my $action = shift;
my $sub = shift;
$responses->{$action}->{'on_trigger_method'} = $sub;
}
sub get_trigger {
my $self = shift;
my $action = shift;
return $responses->{$action}->{'on_trigger_method'};
}
sub monitor {
my $self=shift;
my $current_channel = $self->{'current_channel'};
#get any old stuff
$self->_monitor();
}
sub full_refresh {
my $self = shift;
my $current_channel = $self->{'current_channel'};
$self->{'full_refresh'}->{'completed'} = 0;
# clear the flags
foreach my $channel (keys %{$self->{'channels'}}) {
if ($channel != $current_channel) {
$self->{'channels'}->{$channel}->{'last_update'} = 0;
}
}
# Iterate - We're out of sync so make a guess
my $last_channel = 1;
while ($self->{'full_refresh'}->{'completed'} == 0) {
for (my $channel = 1; $channel < 256; $channel++) {
next if $channel == $current_channel;
next if !defined $self->{'channels'}->{$channel};
next if $self->{'channels'}->{$channel}->{'last_update'} == 0;
$last_channel = $channel;
}
$self->command('next_channel_info', $last_channel);
$self->_monitor;
}
$self->{'last_full_refresh'} = time;
$self->command('monitor', $current_channel);
}
### --Power--
### Turn on or off the power
### power(action) where action is:
### on - Power On
### off - Power Off
### sleep - Power Saving Mode
sub power {
my $self = shift;
my $command = lc(shift);
if (!defined $command || $command eq 'on') {
$command = 'on';
} elsif ($command ne 'off' && $command ne 'sleep') {
return -1;
}
$self->command($command);
while($self->{'power'} ne $command) {
$self->monitor();
}
}
### --Mute--
### Mute the sound
### mute(action) where action is:
### on - silence the radio
### off - allow the sound to play
sub mute {
my $self = shift;
my $op = lc(shift);
my $command;
if (!defined $op || $op eq 'on') {
$command = 'mute_on';
}
elsif ($op eq 'off') {
$command = 'mute_off';
} else {
return -1;
}
$self->command($command);
}
### --Tune--
( run in 1.222 second using v1.01-cache-2.11-cpan-140bd7fdf52 )