]> www.fi.muni.cz Git - slotcarman.git/blob - gui.pl
WIP: Towards internal timekeeping.
[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 => 80 });
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 $track->car(0)->set_model('F1 Ferrari');
26 $track->car(1)->set_model('F1 McLaren');
27 $track->car(2)->set_model('F1 Williams');
28 $track->car(3)->set_model('Citroen Xsara');
29 $track->car(4)->set_model('Citroen C4');
30 $track->car(5)->set_model('Ford Focus');
31
32 $track->car(0)->set_driver('Ivi');
33 $track->car(1)->set_driver('Filípek');
34 $track->car(2)->set_driver('Táta');
35
36 if ($reader) {
37         Glib::IO->add_watch(fileno($reader->fh), 'in', \&scx_read, $reader);
38 } else {
39         # Just display some random values
40
41         $gui->rounds('5/13');
42         $gui->time('53.4');
43         $gui->best_lap('12.3');
44
45         my $now = time;
46         $track->{race_running_since} = $now;
47         $track->{race_running} = 1;
48
49         $track->car(0)->finish_line($now + 2.5, 1);
50 #       $track->car(0)->set_lap(13);
51 #       $track->car(1)->set_lap(11);
52 #       $track->car(2)->set_lap(10);
53 #       $track->car(3)->set_lap(undef);
54 #       $track->car(4)->set_lap(undef);
55 #       $track->car(5)->set_lap(undef);
56
57 #       $track->car(0)->set_laptime(9.12322);
58 #       $track->car(1)->set_laptime(15.313);
59 #       $track->car(2)->set_laptime(5.989);
60
61         $track->car(0)->set_fuel(6);
62         $track->car(1)->set_fuel(2);
63         $track->car(2)->set_fuel(8);
64
65         $track->car(0)->set_throttle(0);
66         $track->car(1)->set_throttle(8);
67         $track->car(2)->set_throttle(12);
68 }
69
70 $gui->show;
71
72 Gtk2->main();
73
74 exit 0;
75
76 sub quit {
77         Gtk2->main_quit;
78         return FALSE;
79 }
80
81 sub scx_read {
82         my ($event, $fh, $reader) = @_;
83
84         $reader->read();
85         return TRUE;
86 }
87