#!/usr/bin/perl -w

use warnings;
use strict;

use Net::Elexol::EtherIO24;

my $addr = "192.168.1.80";

Net::Elexol::EtherIO24->debug(3);
my $eio = Net::Elexol::EtherIO24->new(target_addr=>$addr, threaded=>1);

if(!$eio) {
	print STDERR "ERROR: Can't create new EtherIO24 object: ".Net::Elexol::EtherIO24->error."\n";
	exit 1;
}

my $finished = 0;

$SIG{INT} = sub { $finished = 1; };

$eio->send_command("%");
$eio->recv_result("%");

for my $line (0..7) {
	print "line $line dir: ".$eio->get_line_dir($line)."  ".
	      "line $line val: ".$eio->get_line($line)."\n";
	$eio->set_line_dir($line, 0);
}

for my $line(0..7) {
	$eio->set_line($line, 1);
}

sleep(1);

my $end = time()+(5*3000);
while(!$finished && time() < $end) {
	for my $line(0..7) {
		$eio->set_line($line, 1);
		my $l = $line - 1;
		$l = 7 if($l < 0);
		$eio->set_line($l, 1);
		$l--; $l = 7 if($l < 0);
		$eio->set_line($l, 0);

		select(undef,undef,undef,0.05);

		last if($finished);
	}
}

for my $line(0..7) {
	$eio->set_line($line, 1);
}

$eio->close;

