read pins file if they exist
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 19 Nov 2017 10:20:05 +0000 (11:20 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sun, 19 Nov 2017 10:20:05 +0000 (11:20 +0100)
gpio.pl

diff --git a/gpio.pl b/gpio.pl
index 99134ac..74f3157 100755 (executable)
--- a/gpio.pl
+++ b/gpio.pl
@@ -50,6 +50,7 @@ my $model = slurp('/proc/device-tree/model');
 $model =~ s/\x00$//; # strip kernel NULL
 warn "# model [$model]";
 
+OPEN_PINS_AGAIN:
 open(DATA, '<', $opt_pins) if $opt_pins;
 
 my @lines;
@@ -76,6 +77,15 @@ while(<DATA>) {
        }
 }
 
+if ( ! $opt_pins && ! $pins ) {
+       my $glob = $model;
+       my $glob =~ s/^(\w+).*$/$1/;
+       my @pins = glob "pins/${glob}*";
+       warn "# possible pins: ",dump( \@pins );
+       $opt_pins = $pins[0];
+       goto OPEN_PINS_AGAIN;
+}
+
 die "add pin definition for # $model" unless $pins;
 
 #warn "# lines ",dump( \@lines );