[Gambas-user] Joystick interface class

Jean-Francois Perreault cmcpero at ...142...
Mon Mar 7 14:51:52 CET 2005


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




More information about the User mailing list