Trigger Test with pascalio
2023.12.04 15:03
File : /pascalio/examples/linux_interrupt/project1.lpr
{ Interrupt sample application
This demo program shows how to wait for an interrupt.
Orange Pi's GPIO is default Pull-Up status when used in input mode.
}
program project1;
{$mode objfpc}{$H+}
uses
baseunix, fpgpio;
var
input: TGpioLinuxPin;
Terminate: Boolean = False;
NewValue: Boolean;
Procedure DoSig(sig : cint);cdecl;
begin
if Terminate then
halt(2);
Terminate := True;
end;
procedure InstallSignalHandler;
var
na, oa: psigactionrec;
begin
new(na);
new(oa);
na^.sa_Handler:=SigActionHandler(@DoSig);
fillchar(na^.Sa_Mask,sizeof(na^.sa_mask),#0);
na^.Sa_Flags:=0;
{$ifdef Linux} // Linux specific
na^.Sa_Restorer:=Nil;
{$endif}
if fpSigAction(SIGINT,na,oa) <> 0 then
begin
writeln('Error: ',fpgeterrno,'.');
halt(1);
end;
Dispose(na);
Dispose(oa);
end;
begin
InstallSignalHandler;
input := TGpioLinuxPin.Create(92); // wPI #13, Physical # 22
input.Direction := gdIn;
input.InterruptMode := [gimRising, gimFalling]; // interrupt on open and close
repeat
if input.WaitForInterrupt(TGpioLinuxPin.INTERRUPT_WAIT_INFINITE,
NewValue) then
Writeln('Interrupt on Pin ', input.PinID, ' with value ', NewValue)
else
WriteLn('Timeout');
until Terminate;
input.Destroy;
end.
Multimedia video is in attached.