JoyGetDeviceCapsA%()

Blitz3D Forums/Blitz3D Userlibs/JoyGetDeviceCapsA%()

_PJ_(Posted 2010) [#1]
I'm unable to find the problem in this code:
;EnableDirectInput True

;Const MM_LOGITECH%=1133
;Const MP_PC_JOYSTICK=49685

Const CDC_MID%			= 0
Const CDC_PID%			= 2
Const CDC_NAME%			= 4
Const CDC_XMIN%			= 36
Const CDC_XMAX%			= 40
Const CDC_YMIN%			= 44
Const CDC_YMAX%			= 48
Const CDC_ZMIN%			= 52
Const CDC_ZMAX%			= 56
Const CDC_NUMBUTTONS%	= 60
Const CDC_PERIODMIN%	= 64
Const CDC_PERIODMAX%	= 68
Const CDC_RMIN%			= 72
Const CDC_RMAX%			= 76
Const CDC_UMIN%			= 80
Const CDC_UMAX%			= 84
Const CDC_VMIN%			= 88
Const CDC_VMAX%			= 92
Const CDC_CAPS%			= 96
Const CDC_MAXAXES%		= 100
Const CDC_NUMAXES%		= 104
Const CDC_MAXBUTTONS%	= 108
Const CDC_REGKEY%		= 112
Const CDC_OEMVXD%		= 144

Function GetControllerInput$(nInput%,nPort%=0)
	Local bOutBuffer%
	Local sReturn$=""
	Local nError%
	Select(nInput)
		Case CDC_MID: 
			bOutBuffer=CreateBank(2)
			nError%=Winmm_JoyGetDevCapsA(nPort%,bOutBuffer,2)
			If (Not(nError)) Then sReturn=Str(PeekShort(bOutBuffer,0))
		Case CDC_PID: 
			bOutBuffer=CreateBank(2)
			nError%=Winmm_JoyGetDevCapsA(nPort%,bOutBuffer,2)
			If (Not(nError)) Then sReturn=Str(PeekShort(bOutBuffer,0))		
		Case CDC_NAME: 
			bOutBuffer=CreateBank(32)
			nError%=Winmm_JoyGetDevCapsA(nPort%,bOutBuffer,32)
			If (Not(nError)) Then sReturn=PeekString(bOutBuffer,0)
		Case CDC_REGKEY:
			bOutBuffer=CreateBank(32)
			nError%=Winmm_JoyGetDevCapsA(nPort%,bOutBuffer,32)
			If (Not(nError)) Then sReturn=PeekString(bOutBuffer,0)
		Case CDC_OEMVXD: 
			bOutBuffer=CreateBank(32)
			nError%=Winmm_JoyGetDevCapsA(nPort%,bOutBuffer,32)
			If (Not(nError)) Then sReturn=PeekString(bOutBuffer,0)
		Default:
			bOutBuffer=CreateBank(4)
			nError%=Winmm_JoyGetDevCapsA(nPort%,bOutBuffer,4)
			If (Not(nError)) 
				sReturn=Str(PeekInt(bOutBuffer,0))
			End If			
		End Select	
		FreeBank bOutBuffer
		Return sReturn$
End Function

Function PeekString$(bBank%,nOffset%=0)
	Local sReturn$=""
	Local Size%=BankSize(bBank)
	If ((Size)*(nOffset<(Size+1)))
		Local IterBytes%
		Local Byte%
		For IterBytes=nOffset To Size-1
			Byte=PeekByte(bBank,IterBytes)
			If (Byte)
				sReturn = sReturn + Chr$(Byte)
			Else
				Exit
			End If
		Next
	End If
	Return sReturn$
End Function

;~IDEal Editor Parameters:
;~C#Blitz3D


Which was based on an example by Fredborg (Which DOES work):
 ;
;.lib "winmm.dll"
;joyGetDevCapsA%(id%,lpCaps*,uSize%):"joyGetDevCapsA"

;
; Joystick Property constants
; Do not change!
;

EnableDirectInput True
Graphics 400,400,0,2

Const joy_Mid			= 0
Const joy_Pid			= 2
Const joy_Name			= 4
Const joy_Xmin			= 36
Const joy_Xmax			= 40
Const joy_Ymin			= 44
Const joy_Ymax			= 48
Const joy_Zmin			= 52
Const joy_Zmax			= 56
Const joy_NumButtons	= 60
Const joy_PeriodMin		= 64
Const joy_PeriodMax		= 68
Const joy_Rmin			= 72
Const joy_Rmax			= 76
Const joy_Umin			= 80
Const joy_Umax			= 84
Const joy_Vmin			= 88
Const joy_Vmax			= 92
Const joy_Caps			= 96
Const joy_MaxAxes		= 100
Const joy_NumAxes		= 104
Const joy_MaxButtons	= 108
Const joy_RegKey		= 112
Const joy_OEMVxD		= 144

;
; Use this function to get a joystick property
;
Function GetJoyProperty$(port,property)

	joybank = CreateBank(1024)

	ret$ = ""
	For i = 0 To 1023
		error = winmm_joygetdevcapsa(port,joybank,i)
		If error = 0 
			If (property = joy_Mid) Or (property = joy_Pid)
				ret$ = PeekShort(joybank,property)			
			ElseIf (property = joy_Name) Or (property = joy_RegKey) Or (property = joy_OEMVxD)
				For j = property To BankSize(joybank)-1
					ch = PeekByte(joybank,j)
					If ch = 0 Then Exit
					ret$ = ret$+Chr$(ch)
				Next
			Else
				ret$ = PeekInt(joybank,property)
			End If
			Exit
		End If
	Next
	
	FreeBank joybank
	
	If error <> 0
		Return "Joystick "+port+" Not Found!"
	Else
		Return ret$
	End If
	
End Function

;
; (Really useless) example
;



joyport =0
Print "Joystick "+joyport+" Properties:"
Print "  Mid        - "+GetJoyProperty(joyport,joy_Mid)
Print "  Pid        - "+GetJoyProperty(joyport,joy_Pid)
Print "  Name       - "+GetJoyProperty(joyport,joy_Name)
Print "  Xmin       - "+GetJoyProperty(joyport,joy_Xmin)
Print "  Xmax       - "+GetJoyProperty(joyport,joy_Xmax)
Print "  Ymin       - "+GetJoyProperty(joyport,joy_Ymin)
Print "  Ymax       - "+GetJoyProperty(joyport,joy_Ymax)
Print "  Zmin       - "+GetJoyProperty(joyport,joy_Zmin)
Print "  Zmax       - "+GetJoyProperty(joyport,joy_Zmax)
Print "  NumButtons - "+GetJoyProperty(joyport,joy_NumButtons)
Print "  PeriodMin  - "+GetJoyProperty(joyport,joy_PeriodMin)
Print "  PeriodMax  - "+GetJoyProperty(joyport,joy_PeriodMax)
Print "  Rmin       - "+GetJoyProperty(joyport,joy_Rmin)
Print "  Rmax       - "+GetJoyProperty(joyport,joy_Rmax)
Print "  Umin       - "+GetJoyProperty(joyport,joy_Umin)
Print "  Umax       - "+GetJoyProperty(joyport,joy_Umax)
Print "  Vmin       - "+GetJoyProperty(joyport,joy_Vmin)
Print "  Vmax       - "+GetJoyProperty(joyport,joy_Vmax)
Print "  Caps       - "+GetJoyProperty(joyport,joy_Caps)
Print "  MaxAxes    - "+GetJoyProperty(joyport,joy_MaxAxes)
Print "  NumAxes    - "+GetJoyProperty(joyport,joy_NumAxes)
Print "  MaxButtons - "+GetJoyProperty(joyport,joy_MaxButtons)
Print "  RegKey     - "+GetJoyProperty(joyport,joy_RegKey)
Print "  OEMVxD     - "+GetJoyProperty(joyport,joy_OEMVxD)
Print
Print "Press any key to quit!"
WaitKey()
End


Can anyone help?

Last edited 2010


ZJP(Posted 2010) [#2]
Pb with the .decls ?!

.lib "winmm.dll"
Winmm_JoyGetDevCapsA%(id%,lpCaps*,uSize%):"joyGetDevCapsA"


JP

Last edited 2010


_PJ_(Posted 2010) [#3]
Oh Sorry.. bad editing on my part. I used a different name for the function to the one originally given by fredborg, but in the test, each used a matching decls and the same function name in the code...

If you ignore the difference between

winmm_joygetdevcapsa(port,joybank,i)
and
joyGetDevCapsAController%(id%,lpCaps*,uSize%):"joyGetDevCapsA"

My function still doesn't work. (nError returns True)

Thanks, though ZJP.

---
(I've updated the code provided above to reflect the correct versions with equivalent decls and function names)


rickavzstx(Posted 2011) [#4]
hello,

I test this program, but it does not give me the real name of the joystick!

I have a LOGITECH DUAL ACTION and it gives me JOYSTICK DRIVERS MICROSOFT

you have a solution.
thank you.


_PJ_(Posted 2011) [#5]
That's because it returns the drivers used.

To get the actual product name, I guess it'd need the PID from the registry