pierpa86
Posts: 15
Joined: Sat Apr 16, 2016 8:45 am

Python Uinput

Mon May 09, 2016 3:36 pm

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 ?

pierpa86
Posts: 15
Joined: Sat Apr 16, 2016 8:45 am

Re: Python Uinput

Mon May 09, 2016 4:46 pm

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 ?

pierpa86
Posts: 15
Joined: Sat Apr 16, 2016 8:45 am

Re: Python Uinput

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 )

fedekrum
Posts: 3
Joined: Sat Jun 02, 2018 2:38 pm

Re: Python Uinput

Sun Aug 26, 2018 3:09 am

Can you share the new code?

User avatar
DougieLawson
Posts: 36567
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: Python Uinput

Sun Aug 26, 2018 7:57 am

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.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

fedekrum
Posts: 3
Joined: Sat Jun 02, 2018 2:38 pm

Re: Python Uinput

Fri Aug 31, 2018 10:12 pm

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 !!!!

Return to “Python”