]> www.fi.muni.cz Git - slotcarman.git/blob - slotcarman
gui.pl renamed to slotcarman
[slotcarman.git] / slotcarman
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 => 100 });
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(2)->set_model('Citroen Xsara');
45 $track->car(3)->set_model('Chevrolet Corvette gelb');
46 $track->car(4)->set_model('Ferrari 360 Red Bull');
47 $track->car(5)->set_model('Ferrari 360 Cric Crac');
48
49 $track->car(0)->set_driver('Ferrari');
50 $track->car(1)->set_driver('McLaren');
51 $track->car(2)->set_driver('Xsara');
52
53 if ($reader) {
54         Glib::IO->add_watch(fileno($reader->fh), 'in', \&scx_read, $reader);
55 } else {
56         # Just display some random values
57
58         $gui->rounds('5/13');
59         $gui->time('53.4');
60         $gui->best_lap('12.3');
61
62         my $now = time;
63         $track->{race_running_since} = $now;
64         $track->{race_running} = 1;
65
66         $track->finish_line($now + 0.5, 1, 2);
67         $track->finish_line($now + 0.7, 1, 1);
68         $track->finish_line($now + 4.9, 1, 1);
69         $track->finish_line($now + 5.3, 1, 2);
70         $track->finish_line($now + 7.2, 1, 1);
71         $track->finish_line($now + 8.1, 0, 2);
72 #       $track->car(0)->set_lap(13);
73 #       $track->car(1)->set_lap(11);
74 #       $track->car(2)->set_lap(10);
75 #       $track->car(3)->set_lap(undef);
76 #       $track->car(4)->set_lap(undef);
77 #       $track->car(5)->set_lap(undef);
78
79         $track->car(0)->set_laptime(9.12322);
80         $track->car(1)->set_laptime(15.313);
81         $track->car(2)->set_laptime(5.989);
82
83         $track->car(0)->set_fuel(6);
84         $track->car(1)->set_fuel(2);
85         $track->car(2)->set_fuel(8);
86
87         $track->car(0)->set_throttle(0);
88         $track->car(1)->set_throttle(8, 1);
89         $track->car(2)->set_throttle(12);
90 }
91
92 $gui->show;
93
94 Gtk2->main();
95
96 exit 0;
97
98 sub quit {
99         Gtk2->main_quit;
100         return FALSE;
101 }
102
103 sub scx_read {
104         my ($event, $fh, $reader) = @_;
105
106         $reader->read();
107         return TRUE;
108 }
109