The online racing simulator
My first Out Gauge application in Delphi
NEW VERSION FOR Z25:







Download here


Important!!!
Delphi 7 doesn't know TByte type as Adata in IdUDPServer1UDPRead
so i changed it to TStream, and it's work but compiler sometimes throw you this message:





Just click NO button



The Source Code:

{
******************************************************************************
In ENGLISH: (sorry for any mistakes;) )
Outgauge example for "Live for Speed" written by Radek Szewczyk
Contact: radekteam@gmail.com
GG: 1480359
Myspace: myspace.com/deejayradzio

If you've got any problems with this code just contact me. I try to help you ;)
Thanks to 4programmers.net users for any help.

Important: This program uses Indy10 Components for Delphi 7.
******************************************************************************


******************************************************************************
Po POLSKU:
Przyklad Outgauge dla "Live for Speed" napisany przez Radka Szewczyka
Kontakt: radekteam@gmail.com
GG: 1480359
Myspace: myspace.com/deejayradzio

Jezeli masz jakiekolwiek problemy z tym kodem poprostu sie ze mna skontaktuj.
Postaram sie Ci pomoc.
Podziekowania dla uzytkownikow 4programmers.net za wszelka pomoc.

Wazne: Ten program uzywa komponentow Indy10 dla Delphi 7.
******************************************************************************
}



unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdUDPBase, IdUDPServer,IdSocketHandle, StdCtrls,
ComCtrls, ExtCtrls, Gauges;

type
TPacket = record
Time: longint; // time in milliseconds (to check order)
Car: array[0..3] of char; // Car name
Flags: word; // OG_FLAGS
Gear: byte; // Reverse:0, Neutral:1, First:2...
SpareB: byte;
Speed: single; // M/S
RPM: single; // RPM
Turbo: single; // BAR
EngTemp: single; // C
Fuel: single; // 0 to 1
OilPress: single; // BAR
OilTemp: single; // C
DashLights: longint; // Dash lights available
ShowLights: longint; // Dash lights currently switched on
Throttle: single; // 0 to 1
Brake: single; // 0 to 1
Clutch: single; // 0 to 1
Display1: array[0..15] of char; // Usually Fuel
Display2: array[0..15] of char; // Usually Settings
ID: integer; // optional - only if GameID is specified
end;

TForm1 = class(TForm)
Label1: TLabel;
IdUDPServer1: TIdUDPServer;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label19: TLabel;
Image1: TImage;
Gauge1: TGauge;
Gauge2: TGauge;
Gauge3: TGauge;
GroupBox1: TGroupBox;
CheckBox1: TCheckBox;
CheckBox2: TCheckBox;
CheckBox3: TCheckBox;
CheckBox4: TCheckBox;
CheckBox5: TCheckBox;
CheckBox6: TCheckBox;
CheckBox7: TCheckBox;
CheckBox8: TCheckBox;
CheckBox9: TCheckBox;
CheckBox10: TCheckBox;
CheckBox11: TCheckBox;
CheckBox12: TCheckBox;
CheckBox13: TCheckBox;
CheckBox14: TCheckBox;
CheckBox15: TCheckBox;
CheckBox16: TCheckBox;
GroupBox2: TGroupBox;
GroupBox3: TGroupBox;
Memo1: TMemo;
Memo2: TMemo;
Label18: TLabel;
Label20: TLabel;
Label21: TLabel;
Label22: TLabel;
Label23: TLabel;
Label24: TLabel;
procedure IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
procedure Button1Click(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
paczka: Tpacket;
gear_tmp:string;

const
// values for each light

DL_SHIFT = 1 ; // bit 0 - shift light
DL_FULLBEAM = 2 ; // bit 1 - full beam
DL_HANDBRAKE = 4 ; // bit 2 - handbrake
DL_PITSPEED = 8 ; // bit 3 - pit speed limiter
DL_TC = 16 ; // bit 4 - TC active or switched off
DL_SIGNAL_L = 32 ; // bit 5 - left turn signal
DL_SIGNAL_R = 64 ; // bit 6 - right turn signal
DL_SIGNAL_ANY = 128 ; // bit 7 - shared turn signal
DL_OILWARN = 256 ; // bit 8 - oil pressure warning
DL_BATTERY = 512 ; // bit 9 - battery warning
DL_ABS = 1024 ; // bit 10 - ABS active or switched off
DL_SPARE = 2048 ; // bit 11
DL_NUM = 4096 ; //noinfo
OG_TURBO = 8192 ; // show turbo gauge
OG_KM = 16384 ; // if 0 set - user prefers MILES
OG_BAR = 32768 ; // if 0 set - user prefers PSI

implementation

{$R *.dfm}

procedure TForm1.IdUDPServer1UDPRead(Sender: TObject; AData: TStream;
ABinding: TIdSocketHandle);
begin
Adata.Read(paczka, sizeof(paczka));
label6.Caption :=paczka.Car;
gear_tmp:=intToStr(paczka.gear-1); //
if paczka.gear=1 then gear_tmp:= 'N'; // change gear values 0 and 1 to R and N
if paczka.gear=0 then gear_tmp:= 'R'; //
label12.Caption:=gear_tmp;
label7.Caption := FloatToStr(trunc(paczka.Speed / 0.27777778)) + ' Km/h';
label8.Caption := FloatToStr(trunc(paczka.RPM));
label9.Caption := FloatToStr(trunc(paczka.Turbo*100)) + ' BAR';
label10.Caption := FloatToStr(trunc(paczka.Fuel*100))+'.'+FloatToStr(trunc(paczka.Fuel*10000) - trunc(paczka.Fuel*100)*100 ) + ' %';
Gauge1.Progress:= trunc(paczka.Clutch*100);
Gauge2.Progress:= trunc(paczka.Brake*100);
Gauge3.Progress:= trunc(paczka.Throttle*100);
Label20.Caption:= FloatToStr(paczka.EngTemp) +' °C';
Label23.Caption:= FloatToStr(paczka.OilPress) +' BAR';
Label24.Caption:= FloatToStr(paczka.OilTemp) +' °C';
//////Flags//////

//-----------------------------------------------------//
//if shift light is switched on//
if (paczka.ShowLights AND DL_SHIFT) <> 0 then
CheckBox1.Checked:= True
else
CheckBox1.Checked:= False;

//if shift light is available on dash//
if (paczka.DashLights AND DL_SHIFT) <> 0 then
CheckBox1.Enabled:= True
else
CheckBox1.Enabled:= False;

//-----------------------------------------------------//
//if fullbeam is switched on//
if (paczka.ShowLights AND DL_FULLBEAM) <> 0 then
CheckBox2.Checked:= True
else
CheckBox2.Checked:= False;

//if fullbeam is available on dash//
if (paczka.DashLights AND DL_FULLBEAM) <> 0 then
CheckBox2.Enabled:= True
else
CheckBox2.Enabled:= False;

//-----------------------------------------------------//
//if handbrake is switched on//
if (paczka.ShowLights AND DL_HANDBRAKE) <> 0 then
CheckBox3.Checked:= True
else
CheckBox3.Checked:= False;

//if handbrake is available on dash//
if (paczka.DashLights AND DL_HANDBRAKE) <> 0 then
CheckBox3.Enabled:= True
else
CheckBox3.Enabled:= False;

//-----------------------------------------------------//
//if pit speed limiter is switched on//
if (paczka.ShowLights AND DL_PITSPEED) <> 0 then
CheckBox4.Checked:= True
else
CheckBox4.Checked:= False;

//if pit speed limiter is available on dash//
if (paczka.DashLights AND DL_PITSPEED) <> 0 then
CheckBox4.Enabled:= True
else
CheckBox4.Enabled:= False;

//-----------------------------------------------------//
//if Traction Control is switched on//
if (paczka.ShowLights AND DL_TC) <> 0 then
CheckBox5.Checked:= True
else
CheckBox5.Checked:= False;

//if Traction Control is available on dash//
if (paczka.DashLights AND DL_TC) <> 0 then
CheckBox5.Enabled:= True
else
CheckBox5.Enabled:= False;

//-----------------------------------------------------//
//if left turn signal is switched on//
if (paczka.ShowLights AND DL_SIGNAL_L) <> 0 then
CheckBox6.Checked:= True
else
CheckBox6.Checked:= False;

//if left turn signal is available on dash//
if (paczka.DashLights AND DL_SIGNAL_L) <> 0 then
CheckBox6.Enabled:= True
else
CheckBox6.Enabled:= False;

//-----------------------------------------------------//
//if right turn signal is switched on//
if (paczka.ShowLights AND DL_SIGNAL_R) <> 0 then
CheckBox7.Checked:= True
else
CheckBox7.Checked:= False;

//if right turn signal is available on dash//
if (paczka.DashLights AND DL_SIGNAL_R) <> 0 then
CheckBox7.Enabled:= True
else
CheckBox7.Enabled:= False;

//-----------------------------------------------------//
//if any turn signal is switched on//
if (paczka.ShowLights AND DL_SIGNAL_ANY) <> 0 then
CheckBox8.Checked:= True
else
CheckBox8.Checked:= False;

//if any turn signal is available on dash//
// if (paczka.DashLights AND DL_SIGNAL_ANY) <> 0 then
// CheckBox8.Enabled:= True
// else
// CheckBox8.Enabled:= False;

//-----------------------------------------------------//
//if oil pressure warning is switched on//
if (paczka.ShowLights AND DL_OILWARN) <> 0 then
CheckBox9.Checked:= True
else
CheckBox9.Checked:= False;

//if oil pressure warning is available on dash//
if (paczka.DashLights AND DL_OILWARN) <> 0 then
CheckBox9.Enabled:= True
else
CheckBox9.Enabled:= False;

//-----------------------------------------------------//
//if battery warning is switched on//
if (paczka.ShowLights AND DL_BATTERY) <> 0 then
CheckBox10.Checked:= True
else
CheckBox10.Checked:= False;

//if battery warning is available on dash//
if (paczka.DashLights AND DL_BATTERY) <> 0 then
CheckBox10.Enabled:= True
else
CheckBox10.Enabled:= False;

//-----------------------------------------------------//
//if ABS is switched on//
if (paczka.ShowLights AND DL_ABS) <> 0 then
CheckBox11.Checked:= True
else
CheckBox11.Checked:= False;

//if ABS is available on dash//
if (paczka.DashLights AND DL_ABS) <> 0 then
CheckBox11.Enabled:= True
else
CheckBox11.Enabled:= False;


//-----------------------------------------------------//
//if Turbo Gauge is available//
if (paczka.Flags AND 8192) <> 0 then //show Turbo Gauge
CheckBox14.Checked:= True
else
CheckBox14.Checked:= False;

//-----------------------------------------------------//
//if KM is set//
if (paczka.Flags AND 16384) <> 0 then //users prefers km
CheckBox15.Checked:= True
else
CheckBox15.Checked:= False;
//-----------------------------------------------------//
//if BAR is set//
if (paczka.Flags AND 32768) <> 0 then //users prefers bar
CheckBox16.Checked:= True
else
CheckBox16.Checked:= False;

memo1.Text:=paczka.Display1;
memo2.Text:=paczka.Display2;

end;

procedure TForm1.Button1Click(Sender: TObject);
begin
IdUDPServer1.DefaultPort := 11111;
IdUDPServer1.Active := true;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
IdUDPServer1.Active:=False;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
IdUDPServer1.DefaultPort := 11111;
IdUDPServer1.Active := true;
end;

end.


I hope that it will be helpful for someone
Cool, and from a Demo Racer! Very nice sir, sounds like a good candidate for the nicest, most helpful Demo Racer.
and wat would i use this for?
Quote from Eclipse2000 :and wat would i use this for?

It looks like it displays OutGauge data (car, engine telemetry, read the docs on OutGauge) in a form. If you have any use for such info to use externally (out of LFS) it's a good place to start working if you're coding in Delphi.

In other words, unless you're a Delphi coder, you don't have much use for this. It's essentially a "Hello World" tutorial for accessing/using OutGauge.

Could be wrong though, never had a look at Delphi before
It's only a tutorial code. I have in plans to display those data on HD 44780 lcd ,but now i've put it here for anyone who need help with outgauge in Delphi. It may be usefull Thanks for comments
Its very nice, but i have a question, how to control shiftlight & others?
#7 - ReVoX
uh, nice for the first outgage
Nice prog m8 , keep up the good work .
Quote from Nadeo4441 :Its very nice, but i have a question, how to control shiftlight & others?

Shift lights can be controled by reading RPM. Others? What others? Could you precise your question?
-
(mikey_G) DELETED by mikey_G : bleh
nice, didn't know people still used delphi

Quote from Eclipse2000 :and wat would i use this for?

Check my sig to see what's possible with outgauge
i send email
I'm working now on LCD SMARTIE PLUGIN for LFS. It's almost finished. In few days (maybe Saturday) i will release it.
i mean
#define OG_SHIFTLIGHT 1...
Oh yea, in declared packet you have variable called Flags - here are summed the values of all OG_ - you just must know how to decode it - if you want i can tell you how to decode it but it's complicated to explain in one post
Well, i have no idea how to decode it..
Decoding them is easy.


#define OG_SHIFTLIGHT 1
#define OG_FULLBEAM 2
#define OG_HANDBRAKE 4
#define OG_PITSPEED 8
#define OG_TC 16
#define OG_HEADLIGHTS 32
#define OG_SIGNAL_L 64
#define OG_SIGNAL_R 128
#define OG_REDLINE 256
#define OG_OILWARN 512
#define OG_1 1024
#define OG_2 2048
#define OG_3 4096
#define OG_4 8192
#define OG_KM 16384
#define OG_BAR 32768

You see the number behind the flag? If you bitwise AND it to the Flags variable, you can check if a flag is on or off.

basically you do this:

if Flags AND 256 = NOT 0 //og_redline is on

I never really used Delphi, but it should be something like that.
Yes, kingfag you've got right. It should be working in delphi too.
But it doesnt work
Quote from Nadeo4441 :But it doesnt work

That's a bit like going to a garage and saying "my car doesn't work", without giving a clue what doesn't work.

The proper syntax would be

if (Flags AND 4) <> 0 then
writeln('handbrake is on');
else
writeln('handbrake is not on');

Yes you are right , im idiot
I have forgot to put it to ()
Nice, keep it up!
Quote from papu24ar :hi men... i have some problems with delphi 7... whats delphi version are you use ?... i compiling your source code and have errors =S

Screenshot:
http://img247.imageshack.us/img247/2849/dibujogz3.jpg

Sorry MY BAD English.. I From Argentina..

I'm using Delphi 7 Personal. You should try to install the newest indy 10 components. This maybe the reason why your delphi throws you this error
my modified version can you make it with analog gauge ?
Attached images
08072008(004).jpg
Hey, on what device do you run it ?
Quote from SilverFox_cz :my modified version can you make it with analog gauge ?

I think I can, but I must find component for analog gauges or write it myself( and it's not easy). BTW Nice device

FGED GREDG RDFGDR GSFDG