python - Pygame read axis value from BU0836X HID device -


i have bu0836x joystick interface board want use read analog joystick values. http://www.leobodnar.com/shop/index.php?main_page=product_info&products_id=180

on computer there python script running capturing joystick values using pygame's joystick module.

however, it's possible information board, such name, number of axes, number of buttons, etc. supplied calibration tool works fine.

the problem experiencing can't read axis data, works standard gamepad of course. there workaround board , running in pygame enviroment?

here super simple script used testing:

import pygame  pygame.joystick.init()  while true:     joystick_count = pygame.joystick.get_count()     in range(joystick_count):         joystick = pygame.joystick.joystick(i)         joystick.init()         name = joystick.get_name()         axes = joystick.get_numaxes()         hats = joystick.get_numhats()         button = joystick.get_numbuttons()         joy = joystick.get_axis(0)         print (name,joy) 

the output is:

('bu0836x interface', 0.0) 

sometimes problem happens when don´t make calls of pygames event queue functions in each frame of game, documentation states.

if not using other event functions in main game, should call pygame.event.pump() allow pygame handle internal actions, such joystick information.

try following updated code:

while true:    pygame.event.pump() #allow pygame handle internal actions    joystick_count = pygame.joystick.get_count()     in range(joystick_count):         joystick = pygame.joystick.joystick(i)         joystick.init()          name = joystick.get_name()         axes = joystick.get_numaxes()         hats = joystick.get_numhats()         button = joystick.get_numbuttons()          joy = joystick.get_axis(0)          print(name, joy) 

an alternative wait events generated joystick (such joyaxismotion) using pygame.event.get() function instance:

while true:     #get events queue     event in pygame.event.get():          if event.type == pygame.quit:             pygame.quit()          if event.type == pygame.joyaxismotion , event.axis == 0:             print(event.value)     joystick_count = pygame.joystick.get_count()     in range(joystick_count):         joystick = pygame.joystick.joystick(i)         joystick.init() #event queue receive events joystick  

hope helps little bit :)


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -