]> www.fi.muni.cz Git - slotcarman.git/blob - gui.pl
7cfe6085f24085b14aa7fdf8c1cfb32927d45423
[slotcarman.git] / gui.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use utf8;
5
6 use Gtk2 '-init';
7 use Glib qw(TRUE FALSE);
8
9 use SCX::GUI;
10 use SCX::Track;
11 use SCX::Reader;
12 use SCX::RaceParser;
13
14 my $gui = SCX::GUI->new({ img_height => 120 });
15 my $track = SCX::Track->new({ gui => $gui });
16
17 my $logfile = 'log';
18 my $tty = '/dev/ttyUSB0';
19
20 if (defined $ARGV[0] && $ARGV[0] eq '-') {
21         $logfile = undef;
22         $tty = '-';
23 }
24
25 my $parser = SCX::RaceParser->new({
26         track => $track,
27         logfile => $logfile,
28 });
29
30 my $reader = eval {
31         SCX::Reader->new({
32                 filename   => $tty,
33                 parser     => $parser,
34         });
35 };
36
37 if ($@) {
38         print STDERR "Demo mode only: $@";
39 }
40
41 $track->car(0)->set_model('F1 Ferrari');
42 $track->car(1)->set_model('F1 McLaren');
43 $track->car(2)->set_model('F1 Williams');
44 $track->car(3)->set_model('Citroen Xsara');
45 $track->car(4)->set_model('Citroen C4');
46 $track->car(5)->set_model('Ford Focus');
47
48 $track->car(0)->set_driver('Ivi');
49 $track->car(1)->set_driver('Filípek');
50 $track->car(2)->set_driver('Táta');
51
52 if ($reader) {
53         Glib::IO->add_watch(fileno($reader->fh), 'in', \&scx_read, $reader);
54 } else {
55         # Just display some random values
56
57         $gui->rounds('5/13');
58         $gui->time('53.4');
59         $gui->best_lap('12.3');
60
61         my $now = time;
62         $track->{race_running_since} = $now;
63         $track->{race_running} = 1;
64
65         $track->finish_line($now + 0.5, 1, 2);
66         $track->finish_line($now + 0.7, 1, 1);
67         $track->finish_line($now + 4.9, 1, 1);
68         $track->finish_line($now + 5.3, 1, 2);
69         $track->finish_line($now + 7.2, 1, 1);
70         $track->finish_line($now + 8.1, 0, 2);
71 #       $track->car(0)->set_lap(13);
72 #       $track->car(1)->set_lap(11);
73 #       $track->car(2)->set_lap(10);
74 #       $track->car(3)->set_lap(undef);
75 #       $track->car(4)->set_lap(undef);
76 #       $track->car(5)->set_lap(undef);
77
78         $track->car(0)->set_laptime(9.12322);
79         $track->car(1)->set_laptime(15.313);
80         $track->car(2)->set_laptime(5.989);
81
82         $track->car(0)->set_fuel(6);
83         $track->car(1)->set_fuel(2);
84         $track->car(2)->set_fuel(8);
85
86         $track->car(0)->set_throttle(0);
87         $track->car(1)->set_throttle(8, 1);
88         $track->car(2)->set_throttle(12);
89 }
90
91 $gui->show;
92
93 Gtk2->main();
94
95 exit 0;
96
97 sub quit {
98         Gtk2->main_quit;
99         return FALSE;
100 }
101
102 sub scx_read {
103         my ($event, $fh, $reader) = @_;
104
105         $reader->read();
106         return TRUE;
107 }
108