Device-Chip-MAX7219
view release on metacpan or search on metacpan
lib/Device/Chip/MAX7219.pm view on Meta::CPAN
REG_DIGIT => 0x01, # .. to 8
REG_DECODE => 0x09,
REG_INTENSITY => 0x0A,
REG_LIMIT => 0x0B,
REG_SHUTDOWN => 0x0C,
REG_DTEST => 0x0F,
};
async method _writereg ( $reg, $value )
{
await $self->protocol->write( chr( $reg ) . chr( $value ) );
}
=head1 METHODS
The following methods documented in an C<await> expression return L<Future>
instances.
=cut
=head2 write_bcd
await $chip->write_bcd( $digit, $val );
Writes the value at the given digit, setting it to BCD mode if not already so.
C<$val> should be a single digit number or string, or one of the special
recognised characters in BCD mode of C<->, C<E>, C<H>, C<L>, C<P> or space.
The value may optionally be followed by a decimal point C<.>, which will be
set on the display.
Switches the digit into BCD mode if not already so.
=cut
async method write_bcd ( $digit, $val )
{
$digit >= 0 and $digit <= 7 or
croak "Digit must be 0 to 7";
my $dp = ( $val =~ s/\.$// );
length $val == 1 or
croak "BCD value must be 1 character";
( $val = index "0123456789-EHLP ", $val ) > -1 or
croak "Digit value '$val' is not allowed in BCD mode";
my $decodemask = 1 << $digit;
$_decode & $decodemask or
await $self->set_decode( $_decode | $decodemask );
await $self->_writereg( REG_DIGIT+$digit, $val + ( $dp ? 0x80 : 0 ) );
}
=head2 write_raw
await $chip->write_raw( $digit, $bits );
Writes the value at the given digit, setting the raw column lines to the 8-bit
value given.
Switches the digit into undecoded raw mode if not already so.
=cut
async method write_raw ( $digit, $bits )
{
$digit >= 0 and $digit <= 7 or
croak "Digit must be 0 to 7";
my $decodemask = 1 << $digit;
$_decode & $decodemask and
await $self->set_decode( $_decode & ~$decodemask );
await $self->_writereg( REG_DIGIT+$digit, $bits );
}
=head2 write_hex
await $chip->write_hex( $digit, $val );
Similar to C<write_bcd>, but uses a segment decoder written in code rather
than on the chip itself, to turn values into sets of segments to display. This
makes it capable of displaying the letters C<A> to C<F>, in addition to
numbers, C<-> and space.
=cut
my %hex2bits;
async method write_hex ( $digit, $val )
{
my $dp = ( $val =~ s/\.$// );
my $bits = $hex2bits{$val} // croak "Unrecognised hex value $val";
await $self->write_raw( $digit, $bits + ( $dp ? 0x80 : 0 ) );
}
=head2 set_decode
await $chip->set_decode( $bits );
Directly sets the decode mode of all the digits at once. This is more
efficient for initialising digits into BCD or raw mode, than individual calls
to C<write_bcd> or C<write_raw> for each digit individually.
=cut
async method set_decode ( $bits )
{
await $self->_writereg( REG_DECODE, $_decode = $bits );
}
=head2 intensity
await $chip->intensity( $value );
Sets the intensity register. C<$value> must be between 0 and 15, with higher
values giving a more intense output.
=cut
( run in 1.263 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )