Giter VIP home page Giter VIP logo

pascalio's People

Contributors

fliegermichl avatar sameis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pascalio's Issues

Unit fpspi not compilable if compiler switch InheritFromTStream is not set

If compiler switch InheritFromTStream is not defined, the unit fpspi is not compilable.

Compiling package pascalio 0.0: Exit code 1, Errors:5
fpspi.pas(204,6) Error: Identifier not found "EOSError"
fpspi.pas(204,14) Error: Error in type definition
fpspi.pas(206,8) Error: Identifier not found "EOSError"
fpspi.pas(207,5) Error: Illegal qualifier
fpspi.pas(208,10) Error: class type expected, but got "<erroneous type>"

fpspi.pas SetMode procedure issues

fpspi.pas , line 185:

procedure TSPILinuxDevice.SetMode(AValue: TSPIMode);
begin
if FpIOCtl(fHandle, SPI_IOC_RD_MODE, @avalue) = -1 then
DoIoCtlError(SPI_IOC_RD_MODE);
end;

This should be:

procedure TSPILinuxDevice.SetMode(AValue: TSPIMode);
begin
if FpIOCtl(fHandle, SPI_IOC_WR_MODE, @avalue) = -1 then
DoIoCtlError(SPI_IOC_WR_MODE);
end;

Timing Issue when creating Pin

Class has a timing issue when creating a pin.
if you try to change direction direct after creating the pin, nothing happens.
Reason:
The Costructor is exporting GPIOPin. The Kernel now need some time, this is the reason why direction file not exists. the result is a timing issue. Setdirection is trying to write into a file which is not existing, yet.
One solution could be a sleep which seems not useful.
Maybe a checkroutine in Cunstructor to check exported folder would be a solution.
KR
Uwe

Ultrasonic example with HC-SR04 on Orange Pi 5.

I tried pascalio recently on Orange Pi 5.
For ultrasonic example with HC-SR04, existing sample did not work well.
So I have fixed it to make it work.
This is my working sample made with other time routines. (You may use it to publish.)

========== New Working Ultrasonic Sample on Orange Pi 5 =========

program opi5_hc_sr04;

uses sysutils, pascalio, fpgpio, baseunix, unix, math;

const
GPIO_TRIGGER = 52;
GPIO_ECHO = 35;

var
trigger : TGpioPin;
echo : TGpioPin;
distance : Double;

procedure millisecondSleep(const ms : real); // uses BaseUnix
var
// .1 millisecond level sleep (warning 70 microsecond overhead)
Reqested, Remaining : TimeSpec;
ResultVal : Longint;
NanoSecondVal : LongInt;
ErrorOverhead : LongInt = 70000; // 70 microsecond overhead
begin
// 1 milisecond = 1,000,000 nano second
NanoSecondVal := round(ms * 1000000 - ErrorOverhead);
// Here, enter time to sleep (seconds + nanoseconds)
with Reqested do begin
tv_sec := 0;
tv_nsec := NanoSecondVal; // 100 microseconds = .1 milliseconds
end;

// Sleep
ResultVal:=(fpNanoSleep(@Reqested,@Remaining));

if ResultVal <> 0 then begin
writeln('Remaining nanoseconds : ',Remaining.tv_nsec);
writeln('Remaining seconds : ',Remaining.tv_sec);
end;
end;

procedure DoSigInt(sig: cint); cdecl;
begin
Writeln('Signal ', sig, ' received.');
raise Exception.Create('Signal received.');
end;

function MeasureDistance: Double;
var
StartTime: TDateTime;
StopTime: TDateTime;
TimeElapsed: Extended;

  tvprev, tvcur : timeval;  // for fpgettimeofday
  microgap : Longint;

begin
trigger.Value := True;
//WriteLn(ErrOutput, 'TRIGGER set to: ', trigger.Value);
millisecondSleep(10);
trigger.Value := False;
//WriteLn(ErrOutput, 'TRIGGER set to: ', trigger.Value);

StartTime := Now;

while not echo.Value do
fpgettimeofday(@tvprev, nil);

while echo.Value do
fpgettimeofday(@tvcur, nil); // get timestamp AFTER sleep

// Get the gap only for microseconds which is my interest point.
microgap := tvcur.tv_usec - tvprev.tv_usec;

Result := microgap / 58; // 58 for cm. For inch, 148
end;

begin
// Signal handler for SIG_INT (CTRL+C)
FpSignal(SIGINT, @DoSigInt);

// setup GPIO pins
trigger := TGpioLinuxPin.Create(GPIO_TRIGGER);
trigger.Direction := gdOut;
echo := TGpioLinuxPin.Create(GPIO_ECHO );
echo.Direction := gdIn;

try
while True do begin
distance := MeasureDistance;
Writeln(Format('Measured Distance = %4.2f cm', [distance]));
Sleep(200);
end;
except
on Exception do
WriteLn(ErrOutput, 'Terminated');
end;

trigger.Free;
echo.Free;
end.

Linux GPIO direction doesn't reflect the value set

In the following program the testing condition on GPIO's direction is never executed.

program Project1;

{$mode objfpc}{$H+}

uses
  pascalio, fpgpio
  { you can add units after this };
var
  RAIO_RST: TGpioPin;
begin
  RAIO_RST := TGpioLinuxPin.Create(22);
  RAIO_RST.direction := gdin;
  if RAIO_RST.direction = gdIn then begin
    writeln('PIN 22 direction: in');
    Writeln('This is never executed');
  end;
  writeln('ENDE');
  RAIO_RST.Destroy;
end.

pascalio breaks class properties convention

Hi,

you wrote to comment your package on http://www.lazarusforum.de, but there still exists the issue regarding registration (http://www.lazarusforum.de/viewtopic.php?f=14&t=11832).

So I have to make my comment hear:
Your code breaks the class properties convention (https://www.freepascal.org/docs-html/3.0.0/ref/refse39.html). In FPC 3.0.4 your code is wrongly accepted, but in all version 3.1+ it isn't allowed anymore (see http://forum.lazarus-ide.org/index.php/topic,42265.msg306140.html#msg306140).

Best regards,
antispam88

Range error in spidev

On a 64-bit system, this function generates a range error if processing an _IOC_READ. Because SizeInt and TIOCtlRequest are defined at the system level, the best fix appears to be disabling the range check for the duration of the computation.

function _IOC(dir, _type, nr: Longword; size: SizeInt): TIOCtlRequest; begin {$push }{$R- } // If dir is 2 (_IOC_READ) this will set the MSB hence a range error _IOC := (dir shl _IOC_DIRSHIFT) or (_type shl _IOC_TYPESHIFT) or (nr shl _IOC_NRSHIFT) or (size shl _IOC_SIZESHIFT); {$pop } end;

New units

Hello, I send some new units:

  • a PCF8574 port expander control class
  • a SRF02 ultrasonic ranger control class
  • a I2C motor driver circuit (based on Arduino as slave) control class
  • the Arduino source for the motor driver
  • a direct access by /dev/i2c class, read and write blocks of bytes
    I2C-hardware.zip

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.