From: Cliff Rosson Date: 2013-03-13T06:42:01+09:00 Subject: Re: Extending Ruby. Little help or guidance if you are willing! --047d7bdc7f8ac82b0404d7c128fd Content-Type: text/plain; charset=ISO-8859-1 But for numbers that is ok. I'll give it a look. Thanks Josh! On Tue, Mar 12, 2013 at 2:35 PM, Josh Cheek wrote: > On Tue, Mar 12, 2013 at 4:05 PM, tamouse mailing lists < > tamouse.lists@gmail.com> wrote: > >> On Tue, Mar 12, 2013 at 12:28 AM, Josh Cheek >> wrote: >> > Rereading this, I suspect that you might have mis-analyzed the issue. I >> > don't know how the profiler works, but if it's just looking at total >> time, >> > then it should see you spend a lot in this method, because it has both >> IO, >> > and a sleep statement inside of it. The 10-20% could just be what it >> takes >> > to run the Ruby runtime. The flickering could be due to >> > >> > io.write(power, HIGH) >> > sleep delay >> > io.write(power, LOW) >> > >> > I don't know about your device, but is there actually value to writing >> low >> > at all? Could that cause it to flicker? >> > >> > >> > On Mon, Mar 11, 2013 at 10:44 AM, Cliff Rosson >> > wrote: >> >> >> >> Got ya. So it doesn't really matter if I convert things to ID and >> compare >> >> on that basis or keep things a symbol. Thanks Bartosz. >> >> >> > >> > That's true if you mean to just swap them straight over, to avoid >> creating >> > lots of throw-away arrays and iterating over them. >> > >> > There isn't enough code here to know what you can do (e.g. do you have >> > control over the representation shown by display.segments), or to play >> with >> > it (or, for me, to even really understand how the pieces fit together) >> but >> > if your low-level lib takes something like a number where each digit or >> each >> > bit represents the value of a pin in that position, then you could just >> deal >> > with ints like this: >> > >> > case num.to_s >> > when '0' then 0b1111110 >> > when '1' then 0b0110000 >> > when '2' then 0b1101101 >> > when '3' then 0b1111001 >> > when '4' then 0b0110011 >> > when '5' then 0b1011011 >> > when '6' then 0b1011111 >> > when '7' then 0b1110000 >> > when '8' then 0b1111111 >> > when '9' then 0b1110011 >> > end >> > >> > >> >> Why case (plus num.to_s) instead of just an array? >> >> > Oh, I was playing with the idea https://gist.github.com/JoshCheek/5144076and at one point had started to implement characters, too, so this just > allowed me to use digits or character representations of digits. But then I > realized characters like "B" look like "8", and didn't feel like adding > more pins to make it all work, so I took it back out. > > -Josh > -- vizualize.me/cliffrosson --047d7bdc7f8ac82b0404d7c128fd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
But for numbers that is ok. I'll give it a look. Thank= s Josh!


= On Tue, Mar 12, 2013 at 2:35 PM, Josh Cheek <josh.cheek@gmail.com= > wrote:
On T= ue, Mar 12, 2013 at 4:05 PM, tamouse mailing lists <tamouse.lists@gm= ail.com> wrote:
On Tue, Mar 12, 2013 at 12:28 AM, Josh Cheek <josh.cheek@gmail.com> wrot= e:
> Rereading this, I suspect that you might have mis-analyzed the issue. = I
> don't know how the profiler works, but if it's just looking at= total time,
> then it should see you spend a lot in this method, because it has both= IO,
> and a sleep statement inside of it. The 10-20% could just be what it t= akes
> to run the Ruby runtime. The flickering could be due to
>
> =A0 io.write(power, HIGH)
> =A0 sleep delay
> =A0 io.write(power, LOW)
>
> I don't know about your device, but is there actually value to wri= ting low
> at all? Could that cause it to flicker?
>
>
> On Mon, Mar 11, 2013 at 10:44 AM, Cliff Rosson <cliff.rosson@gmail.com>
> wrote:
>>
>> Got ya. So it doesn't really matter if I convert things to ID = and compare
>> on that basis or keep things a symbol. Thanks Bartosz.
>>
>
> That's true if you mean to just swap them straight over, to avoid = creating
> lots of throw-away arrays and iterating over them.
>
> There isn't enough code here to know what you can do (e.g. do you = have
> control over the representation shown by display.segments), or to play= with
> it (or, for me, to even really understand how the pieces fit together)= but
> if your low-level lib takes something like a number where each digit o= r each
> bit represents the value of a pin in that position, then you could jus= t deal
> with ints like this:
>
> =A0 =A0 case num.to_s
> =A0 =A0 when '0' then 0b1111110
> =A0 =A0 when '1' then 0b0110000
> =A0 =A0 when '2' then 0b1101101
> =A0 =A0 when '3' then 0b1111001
> =A0 =A0 when '4' then 0b0110011
> =A0 =A0 when '5' then 0b1011011
> =A0 =A0 when '6' then 0b1011111
> =A0 =A0 when '7' then 0b1110000
> =A0 =A0 when '8' then 0b1111111
> =A0 =A0 when '9' then 0b1110011
> =A0 =A0 end
>
>

Why case (plus num.to_s) instead of just an array?


Oh, I was playing with the idea https:= //gist.github.com/JoshCheek/5144076 and at one point had started to imp= lement characters, too, so this just allowed me to use digits or character = representations of digits. But then I realized characters like "B"= ; look like "8", and didn't feel like adding more pins to mak= e it all work, so I took it back out.

-Josh



--
--047d7bdc7f8ac82b0404d7c128fd--