Device-Chip-Adapter-Gpiod

 view release on metacpan or  search on metacpan

lib/Device/Chip/Adapter/Gpiod.pm  view on Meta::CPAN

}

sub list_gpios {
    my $self = shift;

    if (!defined $self->{gpiod_chip})
    {
        return undef;
    }

    my $num_lines = gpiod_num_lines($self->{gpiod_chip});
    return map {"line$_"} (0..$num_lines-1);
}

sub read_gpios {
    my $self = shift;
    my $lines = shift;

    if (!defined $self->{gpiod_chip})
    {
        return Future->done(undef);
    }

    my @lines = map {/line(\d+)/ && $1} @$lines;
    my @values = gpiod_read_lines($self->{gpiod_chip}, @lines);

    if (@values == @lines)
    {
        my %return;
        for (my $i=0; $i<=$#lines; $i++)
        {
            $return{$lines->[$i]} = $values[$i];
        }

        Future->done(\%return);
    } else
    {
        Future->done(undef);
    }
}

sub write_gpios {
    my $self = shift;
    my $lines = shift;

    if (!defined $self->{gpiod_chip})
    {
        return Future->done;
    }

    my @lines_values;
    for my $line(sort {$a<=>$b} map{/line(\d+)/ && $1} keys %$lines)
    {
        push @lines_values, $line, $lines->{"line$line"};
    }
    gpiod_write_lines($self->{gpiod_chip}, @lines_values);

    Future->done;
}

=head1 BUGS AND LIMITATIONS

The C<meta_gpios> method is not yet supported.

The C<tris_gpios> method is not yet supported.

Libgpiod supports passing a C<consumer> string when GPIO lines are
opened that can identify the application using them. This is currently
always set to C<"Device::Chip">.

=head1 AUTHOR

Stephen Cavilia E<lt>sac@atomicradi.usE<gt>

=head1 COPYRIGHT

Copyright 2021 Stephen Cavilia

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.


=cut

1;



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