#!/usr/bin/perl -w

use strict;
use utf8;

use Gtk2 '-init';
use Glib qw(TRUE FALSE);

use SCX::GUI;
use SCX::Track;
use SCX::Reader;

my $no_reader = 0;

my $gui = SCX::GUI->new;
my $track = SCX::Track->new({ gui => $gui });

if (!$no_reader) {
	my $reader = SCX::Reader->new({
		portname   => '/dev/ttyUSB0',
		logfile    => 'log',
		track      => $track,
	});

	Glib::IO->add_watch(fileno($reader->fh), 'in', \&scx_read, $reader);
}

$track->car(0)->set_model('F1 Ferrari');
$track->car(1)->set_model('F1 McLaren');
$track->car(2)->set_model('F1 Williams');
$track->car(3)->set_model('Citroen Xsara');
$track->car(4)->set_model('Citroen C4');
$track->car(5)->set_model('Ford Focus');

$track->car(0)->set_lap(13);
$track->car(1)->set_lap(11);
$track->car(2)->set_lap(10);
$track->car(3)->set_lap(undef);
$track->car(4)->set_lap(undef);
$track->car(5)->set_lap(undef);

$track->car(0)->set_laptime(9.12322);
$track->car(1)->set_laptime(15.313);
$track->car(2)->set_laptime(8.193);

$track->car(0)->set_driver('Ivi');
$track->car(1)->set_driver('Filípek');
$track->car(2)->set_driver('Táta');

$gui->show;

Gtk2->main();

exit 0;

sub quit {
	Gtk2->main_quit;
	return FALSE;
}

sub scx_read {
	my ($event, $fh, $reader) = @_;

	$reader->read();
	return TRUE;
}

