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