line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package RPi::Pin; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
87018
|
use strict; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
121
|
|
4
|
4
|
|
|
4
|
|
24
|
use warnings; |
|
4
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
133
|
|
5
|
|
|
|
|
|
|
|
6
|
4
|
|
|
4
|
|
1976
|
use parent 'WiringPi::API'; |
|
4
|
|
|
|
|
1258
|
|
|
4
|
|
|
|
|
27
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '2.3603'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub new { |
11
|
|
|
|
|
|
|
my ($class, $pin) = @_; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
if (! defined $pin || $pin !~ /^\d+$/){ |
14
|
|
|
|
|
|
|
die "pin must be an integer\n"; |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $self = bless {}, $class; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if (! $ENV{NO_BOARD}){ |
20
|
|
|
|
|
|
|
if (! defined $ENV{RPI_PIN_MODE}){ |
21
|
|
|
|
|
|
|
$ENV{RPI_PIN_MODE} = 1; |
22
|
|
|
|
|
|
|
$self->setup_gpio; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
$self->{pin} = $pin; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
return $self; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
sub mode { |
31
|
|
|
|
|
|
|
my ($self, $mode) = @_; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
if (! defined $mode){ |
34
|
|
|
|
|
|
|
return $self->get_alt($self->num); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
if ($mode != 0 && $mode != 1 && $mode != 2 && $mode != 3){ |
37
|
|
|
|
|
|
|
die "mode() mode param must be either 0 (input), 1 " . |
38
|
|
|
|
|
|
|
"(output), 2 (PWM output) or 3 (GPIO CLOCK output)\n"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
$self->pin_mode($self->num, $mode); |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
sub mode_alt { |
44
|
|
|
|
|
|
|
my ($self, $alt) = @_; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
if (! defined $alt){ |
47
|
|
|
|
|
|
|
return $self->get_alt($self->num); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$self->pin_mode_alt($self->num, $alt); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
sub read { |
53
|
|
|
|
|
|
|
my $state = $_[0]->read_pin($_[0]->num); |
54
|
|
|
|
|
|
|
return $state; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
sub write { |
57
|
|
|
|
|
|
|
my ($self, $value) = @_; |
58
|
|
|
|
|
|
|
if ($value != 0 && $value != 1){ |
59
|
|
|
|
|
|
|
die "Core::write_pin value must be 0 or 1\n"; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
$self->write_pin($self->num, $value); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
sub pull { |
64
|
|
|
|
|
|
|
my ($self, $direction) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# 0 == down, 1 == up, 2 == off |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
if ($direction != 0 && $direction != 1 && $direction != 2){ |
69
|
|
|
|
|
|
|
die "Core::pull_up_down requires either 0, 1 or 2 for direction"; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
$self->pull_up_down($self->num, $direction); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
sub pwm { |
75
|
|
|
|
|
|
|
my ($self, $value) = @_; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $gpio = $self->pin_to_gpio($self->num); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
if ($self->mode != 2 && $gpio == 18){ |
80
|
|
|
|
|
|
|
my $num = $self->num; |
81
|
|
|
|
|
|
|
die "\npin $num isn't set to mode 2 (PWM). pwm() can't be set\n"; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
if ($value > 1023 || $value < 0){ |
85
|
|
|
|
|
|
|
die "\npwm() value must be 0-1023\n"; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
$self->pwm_write($self->num, $value); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
sub num { |
91
|
|
|
|
|
|
|
return $_[0]->{pin}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
sub set_interrupt { |
94
|
|
|
|
|
|
|
my ($self, $edge, $callback) = @_; |
95
|
|
|
|
|
|
|
WiringPi::API::set_interrupt($self->num, $edge, $callback); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
sub interrupt_set { |
98
|
|
|
|
|
|
|
my ($self, $edge, $callback) = @_; |
99
|
|
|
|
|
|
|
$self->set_interrupt($self->num, $edge, $callback); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
sub _vim{1;}; |
102
|
|
|
|
|
|
|
1; |
103
|
|
|
|
|
|
|
__END__ |