Device-Chip-NoritakeGU_D
view release on metacpan or search on metacpan
lib/Device/Chip/NoritakeGU_D.pm view on Meta::CPAN
method PROTOCOL { $_protocol }
*UART_options = *I2C_options = *SPI_options = method { $_interface->options };
# passthrough
method power
{
return $self->protocol->power( @_ ) if $self->protocol->can( "power" );
return Future->done;
}
method mount ( $adapter, %params )
{
$_interface->mountopts( \%params );
return $self->SUPER::mount( $adapter, %params );
}
method write { $_interface->write( $self, @_ ) }
method read { $_interface->read ( $self, @_ ) }
method write_us { $self->write( pack "C*", 0x1F, @_ ) }
=head1 METHODS
The following methods documented in an C<await> expression return L<Future>
instances.
=cut
=head2 text
await $chip->text( $str );
Draw text at the cursor position.
=cut
async method text ( $text )
{
# Don't allow C0 controls
$text =~ m/[\x00-\x1F]/ and
croak "Invalid characters for ->text";
await $self->write( $text );
}
sub BOOL_COMMAND ( $name, @bytes )
{
my $lastbyte = pop @bytes;
no strict 'refs';
*$name = method ( $on ) {
$self->write_us( @bytes, $lastbyte + !!$on );
};
}
sub INT_COMMAND ( $name, $min, $max, @bytes )
{
my $shortname = ( split m/_/, $name )[-1];
my $lastbyte = pop @bytes;
no strict 'refs';
*$name = method ( $value ) {
$value >= $min and $value <= $max or
croak "Invalid $shortname for ->$name";
$self->write_us( @bytes, $lastbyte + $value );
};
}
sub ENUM_COMMAND ( $name, $values, @bytes )
{
my @values = @$values;
my $shortname = ( split m/_/, $name )[-1];
my $lastbyte = pop @bytes;
no strict 'refs';
*$name = method ( $value ) {
defined( my $index = first { $values[$_] eq $value } 0 .. $#values ) or
croak "Invalid $shortname for ->$name";
$self->write_us( @bytes, $lastbyte + $index );
};
}
=head2 cursor_left
=head2 cursor_right
=head2 cursor_home
await $chip->cursor_left;
await $chip->cursor_right;
await $chip->cursor_linehome;
await $chip->cursor_home;
Move the cursor left or right one character position, to the beginning of the
line, or to the home position (top left corner).
=cut
method cursor_left { $self->write( "\x08" ) }
method cursor_right { $self->write( "\x09" ) }
method cursor_linehome { $self->write( "\x0D" ) }
method cursor_home { $self->write( "\x0B" ) }
=head2 cursor_goto
await $chip->cursor_goto( $x, $y );
Moves the cursor to the C<$x>'th column of the C<$y>'th line (zero-indexed).
=cut
method cursor_goto ( $x, $y )
{
# TODO: Bounds-check $x, $y
$self->write( pack "C C S< S<", 0x1F, 0x24, $x, $y );
}
=head2 linefeed
await $chip->linefeed;
Move the cursor down to the next line.
=cut
method linefeed { $self->write( "\x0A" ) }
( run in 0.682 second using v1.01-cache-2.11-cpan-71847e10f99 )