From: Saji Hameed Date: 2013-03-04T12:34:51+09:00 Subject: Re: Extending Ruby. Little help or guidance if you are willing! --e89a8fb202ea0c479b04d7110acc Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Cliff, Maybe my ruby binding to the SOMPAK code may serve as a small example... https://github.com/sajinh/SOMPAK_4R/tree/master/sompak_4r However, I noted that you are already using a ruby binding to the C-library (WiringPi)!? cheers, saji On Mon, Mar 4, 2013 at 1:52 AM, Cliff Rosson wrote= : > Thanks Quintus. I'll get around to playing with this today. > > > On Sun, Mar 3, 2013 at 3:07 AM, Quintus wrote: > >> Am Sun, 3 Mar 2013 10:31:25 +0900 >> schrieb Cliff Rosson : >> >> > Hi Folk, >> >> Hi Cliff, >> >> > def display_segments(num, display, io, delay =3D 0.005) >> > # ... >> > sleep delay >> > # ... >> > end >> >> I doubt Ruby=E2=80=99s sleep is exact enough to sleep such a small delay= of >> time, especially given the general Floating-Point precision problems. >> I=E2=80=99d suspect that your #sleep call is actually taking longer than= you >> expect. >> >> > I think the logic in my C method would be the same as my ruby one. >> > The part where I run into trouble is converting values. For example I >> > can't figure out how to decide which pins to light by hash key. In >> > fact I can't even figure out how to get the hash keys... >> >> There are two great sources I use when writing C extensions for Ruby: >> >> * The official README.EXT by Matz: >> >> http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/tags/v2_0_0_0/README.EXT?vie= w=3Dmarkup >> >> * Rubinius=E2=80=99 ruby.h header file, because it=E2=80=99s way better = documented than >> Ruby=E2=80=99s: >> >> https://github.com/rubinius/rubinius/blob/master/vm/capi/19/include/ruby= /ruby.h >> >> For getting values out of hashes, you want rb_hash_aref(). >> >> Vale, >> Marvin >> > > > > -- > vizualize.me/cliffrosson > --=20 Saji N Hameed, ARC-ENV, Center for Advanced Information Science and Technology, University of Aizu, Tsuruga, Ikki-machi, Aizuwakamatsu-shi, Fukushima 965-8580, Japan Tel: +81242 37-2736 Fax:+81242 37-2760 email: saji@u-aizu.ac.jp url: http://www.u-aizu.ac.jp bib: http://www.researcherid.com/rid/B-9188-2009 --e89a8fb202ea0c479b04d7110acc Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi Cliff,

Maybe my ruby bindin= g to the SOMPAK code may serve as a small example...

https://github.com/s= ajinh/SOMPAK_4R/tree/master/sompak_4r

However, I noted that you are already using a ruby binding to the= C-library (WiringPi)!?

cheers,
saji


On Mon, Mar 4, 2013 at 1:5= 2 AM, Cliff Rosson <cliff.rosson@gmail.com> wrote:
Thanks Quintus. I'll ge= t around to=C2=A0playing=C2=A0with this today.


On Sun, Mar 3, 2013 at 3:07 AM, Quintus <quintus@quintilianus.eu= > wrote:
Am Sun, 3 Mar 2013 10:31:25 +0900
schrieb Cliff Rosson <cliff.rosson@gmail.com>:

> Hi Folk,

Hi Cliff,

> def display_segments(num, display, io, delay =3D 0.005)
> =C2=A0 # ...
> =C2=A0 sleep delay
> =C2=A0 # ...
> end

I doubt Ruby=E2=80=99s sleep is exact enough to sleep such a small delay of=
time, especially given the general Floating-Point precision problems.
I=E2=80=99d suspect that your #sleep call is actually taking longer than yo= u
expect.

> I think the logic in my C method would be the same as my ruby one.
> The part where I run into trouble is converting values. For example I<= br> > can't figure out how to decide which pins to light by hash key. In=
> fact I can't even figure out how to get the hash keys...

There are two great sources I use when writing C extensions for Ruby:=

* The official README.EXT by Matz:
=C2=A0 http://svn.ruby-lang.org/cgi-b= in/viewvc.cgi/tags/v2_0_0_0/README.EXT?view=3Dmarkup

* Rubinius=E2=80=99 ruby.h header file, because it=E2=80=99s way better doc= umented than
=C2=A0 Ruby=E2=80=99s:
=C2=A0 https://github.com/rubinius/rubin= ius/blob/master/vm/capi/19/include/ruby/ruby.h

For getting values out of hashes, you want rb_hash_aref().

Vale,
Marvin



--



--

Saji N Hameed,
A= RC-ENV, Center for Advanced Information Science and Technology,
Universi= ty of Aizu, Tsuruga, Ikki-machi,
Aizuwakamatsu-shi, Fukushima 965-8580,<= br> Japan
=C2=A0 =C2=A0 =C2=A0 =C2=A0
Tel: +81242 37-2736
Fax:+81242 = 37-2760
=C2=A0email: saji@u-aizu.ac.jp
=C2=A0url: http://www.u-aizu.ac.jp
=C2=A0bib: http://www.researcherid.com/rid/B-9188-2009
--e89a8fb202ea0c479b04d7110acc--