From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!feeder5.feed.usenet.farm!feed.usenet.farm!tr2.eu1.usenetexpress.com!feeder.usenetexpress.com!tr1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!buffer1.nntp.dca1.giganews.com!buffer2.nntp.dca1.giganews.com!news.giganews.com.POSTED!not-for-mail NNTP-Posting-Date: Wed, 29 Jan 2020 20:45:36 -0600 From: Dennis Lee Bieber Newsgroups: comp.lang.ada Subject: Re: GNATCOLL-Mmap example Date: Wed, 29 Jan 2020 21:45:36 -0500 Organization: IISS Elusive Unicorn Message-ID: <8vf43fdbipjulcs8kpjpansjctsa80ho4g@4ax.com> References: <6a365294-65bb-4bd5-82d1-69d7b5aac04b@googlegroups.com> User-Agent: ForteAgent/8.00.32.1272 X-No-Archive: YES MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Usenet-Provider: http://www.giganews.com X-Trace: sv3-8Q2R2IJ5KYYvVePCAZ0iBzLmV558cdfWuBioJME25zUAcQ+QPEhU0e295DtPHOErtoMT3aEOXhlqswn!cBpOtN/+AuCyO+SR+hVO16zCgf+ACTQir9Cd9n9cz0IUD46IhcHGNGV5U7Wwkn9cjCkd+Uac X-Complaints-To: abuse@giganews.com X-DMCA-Notifications: http://www.giganews.com/info/dmca.html X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 3404 Xref: reader01.eternal-september.org comp.lang.ada:57983 Date: 2020-01-29T21:45:36-05:00 List-Id: 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/