A bit of a mystery in how it works other than it creates an OS fault to signal issues. My new function is more complicated:
{
The ExportPin procedure has been expanded to test to see if it is already
exported. If it was already there then a new bit flag is set so that when
the application calls to unexport pins, the ones that were there are left alone.
}
procedure TSysfsGPIO.ExportPin(const Pin: TPinIdentifier);
var val : StdChar;
begin
// First check to see if we already exported this pin inside this application.
if (not IsPinBitSet(Pin, ExportedBitmask)) then begin
Suggest
if (not (IsPinBitSet(Pin, ExportedBitmask)
or IsPinBitSet(Pin, ExportDefinedBitmask)) then begin
That way you don't waste time with the TryReadCharFromFile() if you already
know it was externally exported.
So where does the delay suggestion you made come in? When we try and set the direction of the pin! Which is done in the user application.
// Switch LED pin for output.
GPIO.PinMode[PinLED] := TPinMode.Output;
I'd put the delay immediately after
// Wasn't exported when program started so now let's export it.
if TryWriteTextToFile(FExportFileName, IntToStr(Pin)) then
begin
SetPinBit(Pin, ExportedBitmask);
*** put delay statement here ***;
end;
The only issue I've run into is the repeat until loop. Seems like the file is readable in about 100mS but fails with the write unless the delay is 500mS.
Which "file" (there are so many created under each exported pin) <G>
It may be that the OS default for those files permits reading -- but
the group hasn't been changed yet so only root can write. Sometime after
the creation, the logic that sets up special groups runs and changes the
file to a group that allows you to write.