[Gambas-user] Joystick interface class

Jean-Francois Perreault cmcpero at ...142...
Mon Mar 7 15:41:14 CET 2005


hey that worked !!!
why ?

I even tried exactly
cJoystick1 = NEW CJoystick(FMain,"/dev/js0") AS cJoystick1
earlier

why the double quotes ?

... oh wait , now I remember that when I tried
cJoystick1 = NEW CJoystick(FMain,"/dev/js0") AS cJoystick1
the reason that didn't work was because it said

Type mismatch: wanted string, got Cjoystick instead
in fact that was just
cJoystick1 = NEW CJoystick("/dev/js0") AS cJoystick1
because that was before I tried passing the parent class
so I tought it meant it wanted as string for the constructor
sDevice parameter and that this gave that error because something
else was wrong

(I'm too used to having to reinterpret misleading error
message but congratulations that error message was dead on :) )


but still I don't get it , why does it want a string of the name of the 
class instance ?



Benoit Minisini wrote:

>On Monday 07 March 2005 14:51, Jean-Francois Perreault wrote:
>
>>I narrowed my problem down to this
>>
>>I have a CJoystick class and my main form class FMain
>>
>>in FMain I instanciate a CJoystick object as cJoystick1
>>
>>PUBLIC cJoystick1 AS CJoystick
>>
>>PUBLIC SUB cJoystick1_axis(bAxisNumber AS Byte,iValue AS Short,kIsInit
>>AS Boolean,iTimeStamp AS Integer)
>>  PRINT "axis event fired !"
>>END
>>
>>PUBLIC SUB Form_Open()
>>  cJoystick1 = NEW CJoystick(FMain,"/dev/js0")
>>END
>>
>>and my CJoystick class is like this
>>
>>PUBLIC hJoystick AS File
>>
>>PUBLIC SUB _new(hParent AS Object,sDevice AS String)
>>  OPEN sDevice FOR READ WATCH BIG AS #hJoystick
>>  'OPEN "/dev/js0" FOR READ WATCH BIG AS #hJoystick
>>  object.attach(ME,hParent,"Joystick1")
>>END
>>
>>PUBLIC SUB _free()
>>  CLOSE #hJoystick
>>END
>>
>>PUBLIC SUB File_Read()    ' Here is what each of the 8 bytes of an event
>>mean
>>  DIM b[8] AS Byte        ' Byte 0 to 3 is the time stamp , least
>>significant byte first
>>  DIM i AS Byte           ' Byte 4 and 5 is the value , least
>>significant byte first
>>                          ' Byte 6 is the event type flags bit 7 is the
>>INIT flag occurs when the device
>>                                '  is first open or the stack overflowed
>>(maximum 64 events in the stack)
>>                          ' Byte 7 is the number of the axis or button
>>for this event
>>  FOR i = 0 TO 7
>>    READ #hJoystick , b[i]
>>  NEXT
>>
>>  IF b[6] AND JS_EVENT_AXIS THEN RAISE axis(b[7],b[4] + b[5] * 256,b[6]
>>AND JS_EVENT_INIT, b[0] + b[1] * 256 + b[2] * 512 + b[3] * 1024)
>>  IF b[6] AND JS_EVENT_BUTTON THEN RAISE button(b[7],b[4] + b[5] *
>>256,b[6] AND JS_EVENT_INIT, b[0] + b[1] * 256 + b[2] * 512 + b[3] * 1024)
>> IF b[6] AND JS_EVENT_AXIS THEN print "File_Read fired"
>>END
>>
>>
>>the rest of the code in it's lastest version is at
>>http://domn.net/JoystickDemo.tar.gz
>>
>>now this run with no error but the axis and and button event do not fire
>>in the FMain cJoystick1_axis sub
>>on the console I get File_Read fired but not axis event fired !
>>
>>I'm pretty sure the problem is either how I declare cJoystick1 or
>>redeclare it in Form_Open
>>or how I'm using object.attach in CJoystick's _new
>>
>>
>>
>
>Try to remove Object.Attach() in _new(), and to declare cJoystick this way:
>
>cJoystick1 = NEW CJoystick(FMain,"/dev/js0") AS "Joystick1"
>
>Tell me the result...
>
>





More information about the User mailing list