File: Pin.pm

package info (click to toggle)
libhipi-perl 0.93-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 20,048 kB
  • sloc: perl: 471,917; ansic: 22; makefile: 10
file content (114 lines) | stat: -rw-r--r-- 2,687 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#########################################################################################
# Package        HiPi::GPIO::Pin
# Description:   Pin
# Copyright    : Copyright (c) 2017 Mark Dootson
# License      : This is free software; you can redistribute it and/or modify it under
#                the same terms as the Perl 5 programming language system itself.
#########################################################################################
package HiPi::GPIO::Pin;

#########################################################################################

use strict;
use warnings;
use parent qw( HiPi::Pin );
use Carp;
use HiPi qw( :rpi );

our $VERSION ='0.81';

__PACKAGE__->create_accessors( );

sub _open {
    my ($class, %params) = @_;
    defined($params{pinid}) or croak q(pinid not defined in parameters);
    
    my $self = $class->SUPER::_open(%params);
    return $self;
}

sub _do_getvalue {
    my($self) = @_;
    return HiPi::GPIO->pin_read( $self->pinid );
}

sub _do_setvalue {
    my( $self, $newval) = @_;
    return HiPi::GPIO->pin_write( $self->pinid, $newval );
}

sub _do_getmode {
    my $self = shift;
    return HiPi::GPIO->get_pin_mode( $self->pinid );
}

sub _do_setmode {
    my ($self, $newmode) = @_;
    return HiPi::GPIO->set_pin_mode( $self->pinid, $newmode );
}

sub _do_get_function_name {
    my($self) = @_;
    return HiPi::GPIO->get_pin_function( $self->pinid );
}

sub _do_getinterrupt {
    my ( $self ) = @_;
    return HiPi::GPIO->get_pin_interrupt($self->pinid);
}

sub _do_setinterrupt {
    my ($self, $newedge) = @_;
    return HiPi::GPIO->set_pin_interrupt($self->pinid, $newedge);
}

sub _do_setpud {
    my($self, $pudval) = @_;
    return HiPi::GPIO->set_pin_pud($self->pinid, $pudval);
}

sub _do_getpud {
    my($self ) = @_;
    return HiPi::GPIO->get_pin_pud($self->pinid);
}

sub _do_setschmitt {
    my( $self, $val ) = @_;
    return HiPi::GPIO->set_pin_schmitt($self->pinid, $val);
}

sub _do_getschmitt {
    my( $self ) = @_;
    return HiPi::GPIO->get_pin_schmitt($self->pinid);
}

sub _do_setslew {
    my( $self, $val ) = @_;
    return HiPi::GPIO->set_pin_slew($self->pinid, $val);    
}

sub _do_getslew {
    my( $self ) = @_;
    return HiPi::GPIO->get_pin_slew($self->pinid);
}

sub _do_get_interrupt_filepath {
    my($self) = @_;
    return HiPi::GPIO->get_pin_interrupt_filepath( $self->pinid );
}

sub _do_activelow {
    my($self, $newval) = @_;
    
    my $result = undef;
    
    if( defined( $newval ) ) {
        $result = HiPi::GPIO->set_pin_activelow($self->pinid, $newval);
    } else {
        $result = HiPi::GPIO->get_pin_activelow($self->pinid);
    }
    
    return $result;
}

1;