Hi guys,

OK, I think I'm stuck... I tried to build something using a potential
workaround: use port + number of pin in this port. Inside the lib, I would
define the pin like this (as in device file):

function gp2d02_read_pins(byte out port_vin, byte in number_vin, byte out
port_vout, byte out number_vout) return byte
    var volatile bit pin_vin at port_vin : number_vin
    var volatile bit pin_vout at port_vout : number_vout
    ...
end function

then:

-- pin_a4 : vin
-- pin_a6 : vout
var byte m = gp2d02_read_pins(PORTA,4,PORTA,6)


It appears it can't work: "var volatile ... at : X" requires X to be a
constant. By the time I pass it to the function, it becomes a variable
(whether "in" or "out"). (or do I miss something ?) The function can't take
these parameters, it must directly have access to these definitions. I tried
to put them in an array, then tell the function to access them with an
index, but same problem: one array have to be a "const" array, so index have
to be a constant. Thus not passed through a function parameter...

Due to a compiler bug, I can't pass/use pin name, so I think I'm stuck until
fix (see post in jallist + last bugs on casadeyork, I think this is about
this).

The only remaining options I can see are:

  1. don't provide a lib for GP2D02, and wait for compiler's fix
  2. provide a library for only one GP2D02 instance
  3. build a library with a fixed number of GP2D02 instances

Whatever option 2. or 3., the API will be temporary (thus option 1.: we may
not want providing temporary API). For option 3., these would give something
like this:

var volatile byte gp2d02_vin_0 is pin_a4
var volatile byte gp2d02_vout_0 is pin_a6
var volatile byte gp2d02_vin_1 is pin_a2
var volatile byte gp2d02_vout_1 is pin_a3
...
-- all must be defined, even if only one used (?). Not "acceptable" IMHO


function gp2d02_read(byte in idx) return byte is
    -- can't put this in an array, idx must a constant
    -- this gives some nice "if"
    if idx == 0 then
        pin_vin is gp2d02_vin_0
        pin_vout is gp2d02_vout_0
    elif idx == 1 then

    end if
end function


Since option 3. would really give a horrible API, hardly usable IMHO, I
really consider option 2. -- just deal with one instance, *for now* -- as
the most viable one.

Do you agree ? Do you see any other options ?


Cheers,
Seb

2009/3/18 Joep Suijs <[email protected]>

>
> Looks like a compiler bug, since it compiles okay if you use bytes in
> stead of bits.
>
> procedure gp2d02_read_pins(volatile byte in out pin1, volatile byte in
> out pin2) is
>     -- the logic is like this
>    pin1 = low
>    pin1 = high
>    if pin2 == high then
>        -- do something
>    end if
> end procedure
>
> var volatile byte gp2d02_vin
> var volatile byte gp2d02_vout
>
> var volatile byte q
>
> q = gp2d02_read_pins(gp2d02_vin, gp2d02_vout)
>
> >
>


-- 
Sébastien Lelong
http://www.sirloon.net
http://sirbot.org

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to