Device-PiGlow

 view release on metacpan or  search on metacpan

lib/Device/PiGlow.pm  view on Meta::CPAN

=cut

has I2CBusDevicePath =>	(
			   is  => 'rw',
                           isa => 'Str',
                           default => '/dev/i2c-1',
			);

=item I2CDeviceAddress

This sets the i2c device address,  this defaults to 0x54.  Unless you have
somehow altered the address you shouldn't need to change this.

=cut

has I2CDeviceAddress => (
			   is  => 'rw',
                           isa => 'Num',
                           default => 0x54,
			);

=back

=item device_smbus

This is the L<Device::SMBus> object we will be using to interact with i2c.
It will be initialised with the attributes described above.  You may want
this if you need to do something to the PiGlow I haven't thought of.

=cut

has device_smbus  => (
                        is => 'ro',
                        isa => 'Device::SMBus',
                        lazy => 1,
                        builder => '_get_device_smbus',
                        handles => {
                                     i2c_file => 'I2CBusFilenumber',
                                     _write_byte => 'writeByteData',
                                   },
		     );

sub _get_device_smbus
{
   my ( $self ) = @_;

   my $smbus = Device::SMBus->new(
				    I2CBusDevicePath => $self->I2CBusDevicePath,
                                    I2CDeviceAddress => $self->I2CDeviceAddress
                                 );
   return $smbus;
}

=item update

This updates the values set to the LED registers to the LEDs and changes
the display.

=cut

sub update
{
   my ( $self ) = @_;
   
   return $self->_write_byte(CMD_UPDATE, 0xFF);
}

=item enable_output

This sets the state of the device to active.  

=cut

sub enable_output
{
   my ( $self ) = @_;
   return $self->_write_byte(CMD_ENABLE_OUTPUT, 0x01);
}

has '_led_bank_enable_registers' => (
                                       is  => 'ro',
                                       isa => 'ArrayRef',
                                       lazy => 1,
                                       auto_deref => 1,
                                       default  => sub {
                                          return [
                                                   CMD_ENABLE_LEDS_1,
                                                   CMD_ENABLE_LEDS_2,
                                                   CMD_ENABLE_LEDS_3,
                                                 ];
                                       },
                                    );

=item enable_all_leds

This turns on all three banks of LEDs.

=cut

sub enable_all_leds
{
   my ( $self ) = @_;
   return $self->write_block_data(CMD_ENABLE_LEDS, [0xFF, 0xFF, 0xFF]);
}

=item write_all_leds

This writes the PWM values supplied as an Array Reference and immediately
calls C<update> to apply the values to the LEDs.

The array must be exactly 18 elements long.

The optional second argument will cause the gamma correction to be applied
if the value is true.

=cut

sub write_all_leds
{
   my ( $self, $values, $fix ) = @_;



( run in 1.404 second using v1.01-cache-2.11-cpan-39bf76dae61 )