highlight cell which changed
[x300-pci] / gpio.pl
1 #!/usr/bin/perl
2
3 my @last;
4
5 while(1) {
6
7 my @pcf = `gpio -x pcf8591:120:0x48 readall`;
8 my @gpio = `gpio -g readall`;
9 my $i = 0;
10 foreach (@gpio) {
11         chomp;
12 #       next unless /\d\s/;
13
14         # kill wiringpi mapping columns
15         s/^(.{8}).{6}/$1/;
16         s/.{6}(.{8})$/$1/;
17
18         s/([ \d]{2})(...GPIO.)../$1$2$1/;
19         s/(GPIO.)..(...)(\s*\d+)/$1$3$2$3/;
20
21         my $line = $_ . ( shift @pcf || '');
22         chomp $line;
23         if ( $last[$i] && $line ne $last[$i] ) {
24                 my @l = split(/\|/, $line);
25                 my @o = split(/\|/, $last[$i]);
26                 foreach my $i ( 0 .. $#l ) {
27                         $l[$i] = "\e[33;7;1m$l[$i]\e[0m" if $l[$i] ne $o[$i];
28                 }
29                 print join('|', @l), "|\n";
30         } else {
31                 print "$line\n";
32         }
33         $last[$i] = $line;
34         $i++;
35 }
36
37 my $cmd = <STDIN>;
38 chomp $cmd;
39 if ( $cmd =~ m/^(\d+)$/ ) {
40         my $v = `gpio -g read $1`;
41         warn "# pin $1 ", $v;
42         $v ^= 1;
43         system "gpio -g write $1 $v";
44 }
45
46
47 } #/while
48