b3603: nicer output
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 28 Jun 2019 19:20:22 +0000 (21:20 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Tue, 2 Jul 2019 14:14:41 +0000 (16:14 +0200)
psu.pl

diff --git a/psu.pl b/psu.pl
index 3c2be90..7ac4aa7 100755 (executable)
--- a/psu.pl
+++ b/psu.pl
@@ -32,12 +32,15 @@ $ob->write( shift(@commands) . "\n" );
 my $got = '';
 my $s;
 
+my $show_response = $debug;
+
 while ( 1 ) {
        my ($count_in, $string_in) = $ob->read($InBytes);
        print "<< $count_in << ",dump($string_in),"\n" if $debug && $count_in > 0;
        $got .= $string_in;
        if ( $got =~ m/(OK|E!)\r\n/ ) {
-               warn "# got = ",dump( $got ) if $debug;
+               warn "# got = ",dump( $got ) if $show_response;
+               $show_response = $debug;
                my $new;
                foreach ( split(/[\r\n]+/,$got) ) {
                        my ($k,$v) = split(/:\s+/,$_,2);
@@ -48,20 +51,54 @@ while ( 1 ) {
                                $s->{$k} = $v;
                        }
                }
-               warn "# new = ",dump( $new );
+               warn "# new = ",dump( $new ) if $debug;
+
+               print join("", map {
+                       my $n = $_;
+                       if ( my $v = $s->{$n} ) {
+                               $v =~ s/(\d+) (\d+)$/$1/; # strip adc
+                               "$n $v" . ( exists $new->{$n} ? '*' : ' ' );
+                       } else { '?' };
+               } qw(
+VIN
+VSET
+VOUT
+CSET
+COUT
+OUTPUT
+CONSTANT
+               ) ), "\n";
+
+
                $got = '';
                if ( @commands ) {
                        $ob->write( shift(@commands) . "\n" );
                } else {
-                       print ">> ";
                        alarm(1);
                        my $c;
                        eval {
                                local $SIG{ALRM} = sub { die };
                                $c = <STDIN>;
+                               chomp $c;
+                               alarm(0);
+                               if ( length($c) == 0 ) {
+                                       print ">> ";
+                                       $c = <STDIN>;
+                                       chomp $c;
+                               }
+                               $show_response = 1;
                        };
-                       $c ||= "status\n";
-                       $ob->write( $c );
+
+
+                       if ( $c eq '?' ) {
+                               print dump($s);
+                               $c = '';
+                       } 
+
+                       # always emit something to keep update working
+                       $c ||= "status";
+                       warn ">> ",dump($c) if $debug;
+                       $ob->write( "$c\n" );
                }
        }
 }