# Sample Perl script to transmit number
# to Arduino then listen for the Arduino
# to echo it back

use Device::SerialPort;

# Set up the serial port
# 9600, 81N on the USB ftdi driver
my $port = Device::SerialPort->new("/dev/ttyUSB1");
$port->databits(8);
$port->baudrate(9600);
$port->parity("none");
$port->stopbits(1);

$| = 1;

my $count = 0;
while (1) {
    # Poll to see if any data is coming in
    my $char = $port->lookfor();
    if ($char) {
       #print $char.$/;
       my @v = split(/\s+/,$char);
       #print join(",",@v).$/;
       my @args = ();
       for my $i (0..$#v) {
          my $j = $i + 1;
          push @args, [$j,$v[$i]] if $v[$i] ne "_";
       }
       if (@args) {
          foreach my $arg (@args) {
             my ($x,$y) = @$arg;
             print STDERR ".";
	     print "i1 0.001 0.5 ".($x*100 + 2500)." ".(100+$y+$x*(100 + 10*$x*$y)).$/;
          }
       }
    }
    #my @v = split("\t",$char);
    #for my $i (0..$#v) {
    #   next if ($v[$i] eq '_');
    #   print "$i $v[$i]$/";
    #}
}


