program semaforologica;
{$mode objfpc}{$H+}
uses
cthreads,
Classes, SysUtils, CustApp,
{ you can add units after this }
fpTimer, Crt, keyboard;
type
{ semaforo_logica }
semaforo_logica = class(TCustomApplication)
protected
procedure DoRun; override;
public
Timer1: TFPTimer;
VeicoliSuArchi : array[0..7] of integer;
constructor Create(TheOwner: TComponent); override;
destructor Destroy; override;
procedure WriteHelp; virtual;
procedure Timer1Exec( Sender : TObject );
end;
{ semaforo_logica }
function LetturaTastoPremuto(const TestChar: Char): boolean;
var Key: TKeyEvent;
begin
Result := False;
if PollKeyEvent <> 0 then begin
Key := TranslateKeyEvent(GetKeyEvent);
Result := (GetKeyEventFlags(Key) = kbASCII) and (GetKeyEventChar(Key) = TestChar);
end;
end;
procedure semaforo_logica.DoRun;
var ErrorMsg: String;
begin
// quick check parameters
ErrorMsg := CheckOptions('h', 'help');
if ErrorMsg <> '' then begin
ShowException(Exception.Create(ErrorMsg));
Terminate;
Exit;
end;
// parse parameters
if HasOption('h', 'help') then begin
WriteHelp;
Terminate;
Exit;
end;
//avvia il Timer
timer1.StartTimer;
repeat
CheckSynchronize;
until LetturaTastoPremuto('q');
// stop program loop
Terminate;
end;
constructor semaforo_logica.Create(TheOwner: TComponent);
begin
inherited Create(TheOwner);
StopOnException := True;
end;
destructor semaforo_logica.Destroy;
begin
inherited Destroy;
end;
procedure semaforo_logica.WriteHelp;
begin
{ add your help code here }
writeln('Usage: ', ExeName, ' -h');
writeln('aiuto 1');
writeln('aiuto 2');
end;
procedure semaforo_logica.Timer1Exec( Sender : TObject );
begin
//pulisce la console
ClrScr;
//codice da far eseguire al timer
writeln('Time: '+TimeToStr(Time));
writeln('');
{ add your program here }
//controlla se terminare l'applicazione
if LetturaTastoPremuto('q') then
begin
writeln('Gestore semaforo: TERMINATO');
Terminate;
Exit;
end;
end;
var
Application: semaforo_logica;
begin
Application := semaforo_logica.Create(nil);
Application.Title:='Test timer';
//crea il Timer
Application.Timer1 := TFPTimer.Create(nil);
Application.Timer1.Enabled := True;
Application.Timer1.interval := 1000;
Application.Timer1.onTimer := @Application.Timer1Exec;
//avvia l'applicazione
Application.Run;
Application.Free;
end.