Audio-Radio-Sirius
view release on metacpan or search on metacpan
Revision history for Audio-Radio-Sirius
0.03 06-November-2005 11:00 PM
Fixed some compatibility issues with Device::SerialPort.
0.02 04-November-2005 11:03 PM
Implemented $tuner->set_callback. Notification is now provided for channel updates.
More callbacks to come.
New internal read routine. This (along with a changed monitor method) pretty much
eliminated the duplicate updates from the tuner. They have to be ack'd quick.
The monitor routine now spins 20 times per second (although the parameter is still in
seconds). The effect on CPU utilization seems negligible.
Tests added for a few items.
New internal read routine should actually work on Linux systems, unlike the old scheme.
lib/Audio/Radio/Sirius.pm view on Meta::CPAN
connected => 0,
channel => 0,
gain => 0,
debug => 0,
mute => 0,
verbosity => 0,
_sequence => 0,
_serial => undef,
_lastack => -1,
_lastreq => -1,
_callbacks => {
'channel_update' => undef,
},
_buffer => '',
);
our %SETTABLE = (
debug => 1,
);
our %COMMANDS = (
lib/Audio/Radio/Sirius.pm view on Meta::CPAN
$spins = $spins * 20;
foreach (1..$spins) {
$self->_receive_if_waiting;
sleep (.05); # chill .05 second
}
}
=head2 set_callback (callback type, function reference)
When the tuner sends an update, such as new artist/title information on the current channel, it may be helpful to execute some code which handles this
event. To accomidate this, you may define function callbacks activated when each event occurs. Note that some of the parameters below are marked with
an asterisk. This indicates that they may be undefined when your function is called. You should account for this in your callback function.
=head3 channel_update (channel, *pid, *artist, *title, *composer)
$tuner->set_callback ('channel_update', \&channel);
sub channel {
my ($channel, $pid, $artist, $title, $composer) = @_;
print "Channel $channel is now playing $title.\n";
}
lib/Audio/Radio/Sirius.pm view on Meta::CPAN
Not yet implemented.
=cut
sub set_callback {
my $self = shift;
if (!ref($self) eq 'CODE') { croak "$self isn't an object"; }
my ($reqtype, $funcref) = @_;
if (!ref $funcref) { croak "$funcref must be a reference to a function"; }
if (!exists($DEFAULTS{'_callbacks'}{$reqtype}) ) { croak "$reqtype is not a supported update type"; }
# validated enough for 'ya??
$self->{'_callbacks'}{$reqtype} = $funcref;
}
=head2 verbosity (level)
Not to be confused with C<debug>, verbosity changes the updates the tuner sends. By default, the tuner only sends updates for artist/title/PID
on the current channel. The Generation 2.5 tuners can send artist/title on all channels, the current time, signal strength, and PID information on all
channels.
Internally the tuner treats verbosity as a bitmap allowing you to control each type of update you are interested in. For now, this module treats it
as a boolean. 0 (default) requests that no updates be sent. 1 requests that all of the following updates are sent:
lib/Audio/Radio/Sirius.pm view on Meta::CPAN
# call handler
$self->_call_channel_handler($channel);
}
sub _call_channel_handler {
my $self = shift;
my ($channel) = @_;
# update handler: ($channel, $pid, $artist, $title, $composer)
my $handler = $self->{'_callbacks'}{'channel_update'};
if (ref($handler)) {
&$handler (
$channel,
$self->{'channels'}{$channel}{'pid'},
$self->{'channels'}{$channel}{'artist'},
$self->{'channels'}{$channel}{'title'},
$self->{'channels'}{$channel}{'composer'}
);
}
}
( run in 2.945 seconds using v1.01-cache-2.11-cpan-9b1e4054eb1 )