Author image 阿部正浩

NAME

Device::USB::MissileLauncher::RocketBaby - interface to toy missile launchers from Dream Cheeky

SYNOPSIS

  use Device::USB::MissileLauncher::RocketBaby;
  my $ml = Device::USB::MissileLauncher::RocketBaby->new;
  while (<>) {
      /j/ && $ml->do("down");
      /k/ && $ml->do("up");
      /h/ && $ml->do("left");
      /l/ && $ml->do("right");
      /f/ && $ml->do("fire");
      /s/ && $ml->do("stop");
  }

DESCRIPTION

This provides a basic interface to the toy USB missile launchers produced by Dream Cheeky. The device name of USB protocol is "Rocket Baby Rocket Baby".

METHODS

new ()

Creates an instance.

do ( STRING )

send command string to the launcher. commands are following:

  left
  right
  up
  down
  fire
  stop
cando ( STRING )

returns whether the command is executable.

NOTE

cando("fire") returns false only moment of launching. You can launch rockets one by one like this:

  use Time::Hires qw( sleep );

  sub fire1
  {
      my $ml = shift;
      if ($ml->cando("fire")) {
          $ml->do('fire');
          eval {
              local $SIG{ALRM} = sub { die "alarm" };
              alarm 5;
              while ($ml->cando("fire")) {
                  sleep 0.15;
              }
              usleep 0.5;
              alarm 0;
          }
          $ml->do("stop");
      }
  }

You might have to adjust figures.

SEE ALSO

USB::Device::MissileLauncher

http://www.dreamcheeky.com/product/missile-launcher.php

AUTHOR

Abe Masahiro, <pen@thcomp.org>

COPYRIGHT AND LICENSE

Copyright (C) 2007 by Abe Masahiro

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.