comp.lang.ada
 help / color / mirror / Atom feed
From: Dennis Lee Bieber <wlfraed@ix.netcom.com>
Subject: Re: GNATCOLL-Mmap example
Date: Wed, 29 Jan 2020 21:45:36 -0500
Date: 2020-01-29T21:45:36-05:00	[thread overview]
Message-ID: <8vf43fdbipjulcs8kpjpansjctsa80ho4g@4ax.com> (raw)
In-Reply-To: bcabe239-c048-417b-a435-adb54d377e20@googlegroups.com

On Wed, 29 Jan 2020 13:56:56 -0800 (PST), Bob Goddard
<1963bib@googlemail.com> declaimed the following:

>On Wednesday, 29 January 2020 08:19:11 UTC, Dmitry A. Kazakov  wrote:

>> What about this
>> 
>>        use GNAT.OS_Lib;
>> 
>>        FD     : File_Descriptor;
>>        Buffer : aliased char;
>>     begin
>>        FD := Open_Read ("/sys/class/gpio/gpio/XXX/value", Binary);
>>        Lseek (FD, 0, Seek_Set);
>>        if 1 = Read (FD, Buffer'Address, 1) then
>>           if Buffer = '1' then
>>              ...
>
>Well... the call does not block, but I get spurious info back. It fires 1000 in around 1/4s, when it should be about 50Hz, that being the mains line frequency here.
>

	Since your actual code is not present, one must rely upon crystal
balls...

	If it is an input GPIO, then its value will reflect the state of
whatever is applied to the pin. If you have some voltage reducing filter
tracking your AC power, then that pin will return "1" so long as the
voltage is above whatever the design threshold is.

	Your "1000 in around 1/4s" likely reflects how fast your read loop is
processing.

	If you are trying to track changes in the state of the pin, your loop
may need to incorporate a "lastState" variable, and you only report a state
change when the newly read value is different from the "lastState" (and
then update "lastState" to the new value)

        FD     : File_Descriptor;
        Buffer : aliased char;
	  lastState : char;
     begin
        FD := Open_Read ("/sys/class/gpio/gpio/XXX/value", Binary);
        Lseek (FD, 0, Seek_Set);
        if 1 = Read (FD, Buffer'Address, 1) then
	    if lastState /= Buffer then
             lastState := Buffer;
             if Buffer = '1' then
...

{OR... you figure out IF a state change interrupt can be tied to the GPIO
AND how to define an interrupt handler in Ada for it}


-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
	wlfraed@ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/


  reply	other threads:[~2020-01-30  2:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-25 21:52 GNATCOLL-Mmap example Bob Goddard
2020-01-28  2:10 ` Stephen Leake
2020-01-28  5:59   ` J-P. Rosen
2020-01-28  8:25 ` Dmitry A. Kazakov
2020-01-28 18:53   ` Bob Goddard
2020-01-28 20:07     ` Dmitry A. Kazakov
2020-01-28 20:17       ` Bob Goddard
2020-01-29  8:19         ` Dmitry A. Kazakov
2020-01-29 21:56           ` Bob Goddard
2020-01-30  2:45             ` Dennis Lee Bieber [this message]
2020-01-31 16:59     ` Björn Lundin
2020-01-28 19:11   ` Philip Munts
2020-01-28 20:15     ` Dmitry A. Kazakov
2020-01-28 20:18     ` Philip Munts
2020-01-28 22:06       ` Bob Goddard
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox