Device-BlinkStick
view release on metacpan or search on metacpan
lib/Device/BlinkStick.pm view on Meta::CPAN
# ABSTRACT:
=head1 NAME
Device::BlinkStick
=head1 SYNOPSIS
use 5.10.0 ;
use strict ;
use warnings ;
use Device::BlinkStick;
my $bs = Device::BlinkStick->new() ;
# set first LED on all devices to blue
my $all_devices = $bs->devices() ;
foreach my $k ( keys %$all_devices) {
$all->{$k}->set_color( 'blue') ;
}
# get the first blinkstick found
my $device = $bs->first() ;
# make it red
$first->led( color => 'red') ;
sleep( 2) ;
# blink red for 5 times, delaying for 250ms between black and the color
$first->blink( color => 'red', delay => 250, times => 5) ;
=head1 DESCRIPTION
Module to control a number of blinkstick devices L<http://blinkstick.com> connected via USB.
=cut
package Device::BlinkStick ;
$Device::BlinkStick::VERSION = '0.4.0';
use 5.014 ;
use warnings ;
use strict ;
# we need to set the PERL_INLINE_DIRECTORY environment variable to something
# not in the current directory BEFORE we load Device::USB
BEGIN {
use Path::Tiny ;
my $user = getlogin || getpwuid($<) || "anyone";
$ENV{PERL_INLINE_DIRECTORY} = "/tmp/_Inline/$user/" . __PACKAGE__ ;
$ENV{PERL_INLINE_DIRECTORY} =~ s/::/_/g ;
# make sure the directory exists
path( $ENV{PERL_INLINE_DIRECTORY})->mkpath() ;
}
use Moo ;
use Device::USB ;
use Device::BlinkStick::Stick ;
# ----------------------------------------------------------------------------
use constant VENDOR_ID => 0x20a0 ;
use constant PRODUCT_ID => 0x41e5 ;
use constant UPDATE_TIME => 2 ;
# ----------------------------------------------------------------------------
# mapping of serial IDs to device info
has devices => ( is => 'ro', init_arg => 0 ) ;
# the first device found
has first => ( is => 'ro', init_arg => 0 ) ;
has verbose => ( is => 'ro' ) ;
has inverse => ( is => 'ro' ) ;
has _last_refresh => ( is => 'ro', init_arg => 0, default => sub { 0 } );
# ----------------------------------------------------------------------------
=head2 new
Instantiate a new object, also finds all currently connected devices and populates
the accessor method variables
=head3 parameters
=over 4
=item verbose
output some debug as things happen
=back
=head3 access methods
=over 4
=item devices
Get all blinkstick device L<Device::BlinkStick::Stick> objects available as a hash ref
my $bs = Device::BlinkStick->new() ;
my $devices = $bs->devices() ;
=item first
Get the first blink stick device (object L<Device::BlinkStick::Stick>) found
( run in 1.649 second using v1.01-cache-2.11-cpan-437f7b0c052 )