Skip to content
This repository has been archived by the owner on Feb 26, 2022. It is now read-only.

Commit

Permalink
Added display of Fastest Lap information during the race.
Browse files Browse the repository at this point in the history
  • Loading branch information
davepusey committed Nov 10, 2010
1 parent 9d94a32 commit 302776d
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 24 deletions.
16 changes: 16 additions & 0 deletions ChangeLog 100755 → 100644
@@ -1,3 +1,19 @@
2010-11-10 Dave Pusey <dave@puseyuk.co.uk>

* Added display of Fastest Lap information during the race.

2010-07-12 Dave Pusey <dave@puseyuk.co.uk>

* Auto retry if obtain_auth_cookie fails.

* Auto recovery from decryption failure.

* Added display of Weather information.

2010-06-11 Dave Pusey <dave@puseyuk.co.uk>

* Fixed Bug #587493: Handle system messages that begin with "img:".

2010-05-26 Dave Pusey <dave@puseyuk.co.uk>

* Fixed Bug #580064: libintl error when compiling on MacOS X.
Expand Down
31 changes: 15 additions & 16 deletions src/display.c
Expand Up @@ -67,9 +67,6 @@ int cursed = 0;
/* Number of lines being used for the board */
static int nlines = 0;

/* Did we have room for the header? */
static int header = 0;

/* Attributes for the colours */
static int attrs[LAST_COLOUR];

Expand Down Expand Up @@ -167,15 +164,12 @@ clear_board (CurrentState *state)
if (boardwin)
delwin (boardwin);

nlines = MAX (state->num_cars, 22);
nlines = MAX (state->num_cars, 21);
for (i = 0; i < state->num_cars; i++)
nlines = MAX (nlines, state->car_position[i]);
if (nlines + 1 <= LINES) {
header = 1;
nlines += 1;
} else {
header = 0;
}

nlines += 3;

if (LINES < nlines) {
close_display ();
fprintf (stderr, "%s: %s\n", program_name,
Expand All @@ -193,7 +187,6 @@ clear_board (CurrentState *state)
wbkgdset (boardwin, attrs[COLOUR_DATA]);
werase (boardwin);

if (header) {
switch (state->event_type) {
case RACE_EVENT:
mvwprintw (boardwin, 0, 0,
Expand All @@ -216,7 +209,6 @@ clear_board (CurrentState *state)
_("Sec 2"), _("Sec 3"), _("Lp"));
break;
}
}

for (i = 1; i <= state->num_cars; i++) {
for (j = 0; j < LAST_CAR_PACKET; j++)
Expand Down Expand Up @@ -257,8 +249,6 @@ _update_cell (CurrentState *state,
y = state->car_position[car - 1];
if (! y)
return;
if (! header)
y--;
if (nlines < y)
clear_board (state);

Expand Down Expand Up @@ -541,8 +531,6 @@ clear_car (CurrentState *state,
y = state->car_position[car - 1];
if (! y)
return;
if (! header)
y--;
if (nlines < y)
clear_board (state);

Expand Down Expand Up @@ -695,13 +683,24 @@ update_status (CurrentState *state)
wmove (statwin, wline, 6);
waddch (statwin, '.');

/* Update fastest lap line (race only) */

if (state->event_type == RACE_EVENT)
{
wmove (boardwin, nlines - 1, 3);
wattrset (boardwin, attrs[COLOUR_RECORD]);
wclrtoeol (boardwin);
wprintw(boardwin, "%2s %-14s %4s %4s %8s", state->fl_car, state->fl_driver, "LAP", state->fl_lap, state->fl_time);
}

/* Update session clock */

_update_time (state);

/* Refresh display */

wnoutrefresh (statwin);
wnoutrefresh (boardwin);
doupdate ();
}

Expand Down
18 changes: 10 additions & 8 deletions src/live-f1.h
Expand Up @@ -96,10 +96,14 @@ typedef struct {
* @flag: track status or flag,
* @track_temp: current track temperature (degrees C),
* @air_temp: current air temperature (degrees C),
* @humidity: current humidity (percentage),
* @wind_speed: current wind speed (meters per second),
* @humidity_temp: current humidity (percentage),
* @pressure: current barometric pressure (millibars),
* @wind_direction: current wind direction (destination in degrees),
* @pressure: current barometric pressure (millibars),
* @fl_car: fastest lap (car number),
* @fl_driver: fastest lap (driver's name),
* @fl_time: fastest lap (lap time),
* @fl_lap: fastest lap (lap number),
* @num_cars: number of cars in the event,
* @car_position: current position of car,
* @car_info: arrays of information about each car.
Expand All @@ -120,13 +124,11 @@ typedef struct {
unsigned int lap;
FlagStatus flag;

int track_temp;
int air_temp;
int wind_speed;
int humidity;
int pressure;
int wind_direction;
int track_temp, air_temp, humidity;
int wind_speed, wind_direction, pressure;

char *fl_car, *fl_driver, *fl_time, *fl_lap;

int num_cars;
int *car_position;
CarAtom **car_info;
Expand Down
9 changes: 9 additions & 0 deletions src/main.c
Expand Up @@ -183,6 +183,15 @@ main (int argc,
state->pressure = 0;
state->wind_direction = 0;

if (state->fl_car) free (state->fl_car);
state->fl_car = calloc(3, sizeof(char));
if (state->fl_driver) free (state->fl_driver);
state->fl_driver = calloc(15, sizeof(char));
if (state->fl_time) free (state->fl_time);
state->fl_time = calloc(9, sizeof(char));
if (state->fl_lap) free (state->fl_lap);
state->fl_lap = calloc(3, sizeof(char));

state->num_cars = 0;
if (state->car_position) {
free (state->car_position);
Expand Down
38 changes: 38 additions & 0 deletions src/packet.c
Expand Up @@ -206,6 +206,15 @@ handle_system_packet (CurrentState *state,
state->pressure = 0;
state->wind_direction = 0;

if (state->fl_car) free (state->fl_car);
state->fl_car = calloc(3, sizeof(char));
if (state->fl_driver) free (state->fl_driver);
state->fl_driver = calloc(15, sizeof(char));
if (state->fl_time) free (state->fl_time);
state->fl_time = calloc(9, sizeof(char));
if (state->fl_lap) free (state->fl_lap);
state->fl_lap = calloc(3, sizeof(char));

state->num_cars = 0;
if (state->car_position) {
free (state->car_position);
Expand Down Expand Up @@ -364,6 +373,35 @@ handle_system_packet (CurrentState *state,
break;
}
break;
case SYS_SPEED:
/* Speed and Fastest Lap data:
* Format: single byte, then string.
*
* The first payload byte indicates which piece of
* information to change.
*/
switch (packet->payload[0]) {
case FL_CAR:
memcpy(state->fl_car, packet->payload+1, 2);
update_status (state);
break;
case FL_DRIVER:
memcpy(state->fl_driver, packet->payload+1, 14);
update_status (state);
break;
case FL_TIME:
memcpy(state->fl_time, packet->payload+1, 8);
update_status (state);
break;
case FL_LAP:
memcpy(state->fl_lap, packet->payload+1, 2);
update_status (state);
break;
default:
/* Unhandled field */
break;
}
break;
case SYS_TRACK_STATUS:
/* Track Status:
* Format: decimal.
Expand Down
16 changes: 16 additions & 0 deletions src/packet.h 100755 → 100644
Expand Up @@ -131,6 +131,22 @@ typedef enum {
WEATHER_WIND_DIRECTION = 7
} WeatherPacketType;

/**
* SpeedPacketType:
*
* Sub-types of the SYS_SPEED packet.
**/
typedef enum {
SPEED_SECTOR1 = 1,
SPEED_SECTOR2 = 2,
SPEED_SECTOR3 = 3,
SPEED_TRAP = 4,
FL_CAR = 5,
FL_DRIVER = 6,
FL_TIME = 7,
FL_LAP = 8
} SpeedPacketType;

/**
* Packet:
* @car: index of car,
Expand Down

0 comments on commit 302776d

Please sign in to comment.