Page 1 of 1

Python Uinput

Posted: Mon May 09, 2016 3:36 pm
by pierpa86
Hello, i try to make working a joystick with uinput and now it's work with this code :

Code: Select all

#!/usr/bin/python
 
import spidev
import time
import os
import uinput



 
# Open SPI bus
spi = spidev.SpiDev()
spi.open(0,0)
 
# Function to read SPI data from MCP3008 chip
# Channel must be an integer 0-7
def ReadChannel(channel):
  adc = spi.xfer2([1,(8+channel)<<4,0])
  data = ((adc[1]&3) << 8) + adc[2]
  return data

device =uinput.Device([
                      uinput.ABS_X+(0,900,0,0),
                      uinput.ABS_Y+(0,900,0,0),
                      ])

joy_x=1
joy_y=2

while True:
  
    joy_x_value=ReadChannel(joy_x)
    print ("Joy X Value:{}".format(joy_x_value))
       
    device.emit(uinput.ABS_X,joy_x_value,syn=False)

    joy_y_value=ReadChannel(joy_y)
       
    device.emit(uinput.ABS_Y,joy_y_value)    
    time.sleep(0.020)
Emulatio Station from retropie cant see input. some one can help ?

Re: Python Uinput

Posted: Mon May 09, 2016 4:46 pm
by pierpa86
i see that with "jstest /dev/input/js0"

Joystick (python-uinput) has 2 axes (X, Y)
and 0 buttons ().
Testing ... (interrupt to exit)
Axes: 0: 5097 1: 5752

is that a virtual keyboard ? or is a joystick ?

Re: Python Uinput

Posted: Fri May 13, 2016 9:43 am
by pierpa86
Solved by me :lol: ( emulation station can't detect a Joypad without buttons, you need at least 1 button )

Re: Python Uinput

Posted: Sun Aug 26, 2018 3:09 am
by fedekrum
Can you share the new code?

Re: Python Uinput

Posted: Sun Aug 26, 2018 7:57 am
by DougieLawson
fedekrum wrote:
Sun Aug 26, 2018 3:09 am
Can you share the new code?
Unlikely to happen since that poster hasn't visited since Feb 2017.

Re: Python Uinput

Posted: Fri Aug 31, 2018 10:12 pm
by fedekrum
pierpa86 wrote:
Fri May 13, 2016 9:43 am
Solved by me :lol: ( emulation station can't detect a Joypad without buttons, you need at least 1 button )
And can't detect joypads without axis too !!!!