Hi,
ok , I tought about this some more and I understand why it needed a
string I see now how that
can be very useful to name the observer that way , I guess this is also
how groups are made
now that I can catch and properly interpret de joystick events
I want to optimise the procedure a bit
it's extremely minimalistic already so the only thing I can see I could
do to make it faster
is to fill the b array in only one read operation
a quick benchmark reveal that in normal operation the joystick will
easily generate 200
events with peaks up to 400 events per seconds
while doing all 8 reads only take between 0.00001 and 0.000024 seconds
to complete reducing
that by 8 could be useful to someone making a game (where input control
lag is intolerable)
is there a way I could fill the b array in one operation ?
right now the code is
dim b[7] as byte
FOR i = 0 TO 7
READ #hJoystick , b[i]
NEXT
I tried READ #jJoystick , b
but I get an error that READ wants a standard type , not an array
it doesn't sounds like it is possible , at least not with READ , but if
there's a way I'd like to hear it
also while doing this , I got the feeling I'm missing some events
so I tried to change the code to
dim b[7] as byte
WHILE NOT Eof(hJoystick)
FOR i = 0 TO 7
READ #hJoystick , b[i]
NEXT
WEND
but that doesn't work because I'm reading for a character device and it
cannot reach eof
I'm not sure I'm missing events because I'm not clear on how File_Read
gets called
if there is at least one readable byte in the file File_Read gets called
, but what if I don't read it all ?
does File_Read gets called as soon as the previous File_Read returns ?
(creating an endless loop if I don't read at least one byte)
next , to complete my joystick interface class I need to implement
something called ioctls
please wait I need to read up on that ... ;)
oh ok , trusty man ioctl tells me that ioctl is a function to control
character devices and probably other special files
it works like this you call it with 3 arguments the first is a valid
file descriptor
the second is a signed interger and the value is driver dependant
that second argument at the same time tells the command you want to
perform (the driver then knows wether this is a in or a out command)
also the size the data to input or output , the third argument is a
pointer to memory
since there's no pointers in gambas I guess this means I need a ioctl
interpreted gambas function which I suppose doesn't exist according to
the built-in doc ?
am I stuck ?
/me goes on to search how you guys managed to use the serial port if you
can't ioctl it
......
ok searching the mailing list the only match on ioctl I found is a very
old ( [Gambas-devel] Parallel port on 02/06/2003) thread I replied to (
off course I completely missed the point back then ;) )
so I guess only a component can do this ...
this is a bit off topic I was just wondering if it was possible to get
the pointer of a variable like in vb6 ?
I know this is totally bad hackery that shouldn't ever be used but it
could be a work around for things like this
this is stuff I learned reading visual basic hardcore a long while ago
http://vb.mvps.org/hardcore/
in vb you can use pointers , when you do an api call since variables are
passed byref the pointer gets passed by default
you also have CopyMemory, VarPtr, StrPtr, and ObjPtr (oh and AddressOf
for the pointer to SUBs , a must for using Callbacks) (I think
CopyMemory at least is another api call and that the real name is
RtlCopyMemory)
http://vb.mvps.org/hardcore/html/bringyourhatchet.htm
copymemory is fun to do stuff like
READ #hJoystick , mysignedinteger
CopyMemory(VarPtr(mysignedinteger) + 2,thethirdbyte,1)
I guess these might not work because there is no garantee how
variable are actually stored in memory and how is the interpreter going
to react if the variables change without it's knowledge , like would
happen if you used CopyMemory
but still while there are no garantee this could work , it just might
(for the current version anyway) that's why , at least for vb6 those
functions are undocumented and I think it could be fun to have those
function in gambas , just don't document them , don't support then and
warn anyone who use them that they could break anytime
... well now I am really off-topic , I'm just throwing this in the wind
tell me what you think and I'm going to resume working on my current
problem (ioctls)
...
oh btw , about the event I mostly got confused because the AS keyword
has multiple uses apparently and the documentation isn't very clear on
making the distinction
I'm not sure it's necessary to force a string constant for event
observer name ? maybe this could be useful in some unseen way ? I mean ,
if it doesn't get in the way other than getting noobs like me confused
.. maybe just spelling out how this all works better in the doc will be
enough .. in fact maybe is it explained properly somewhere in the docs
and I just haven't found where ?
anyway .. I'm going to publish this class to gambasforge when it's done
so it will server also as a good example on how to use custom class' events
-Jean-Francois Perreault