1

I have a gamepad (Buffalo iBuffalo Classic USB Gampe for PC) and want to read its input value when I press the buttons.
I am using,

Ubuntu 16.04
Kernel 4.15 
64 bit

In my code,

import sys
pipe = open("/dev/input/js0", "r", encoding="utf-8")
msg = []
while 1:
    for char in pipe.read(1):
        msg += [ord(char)]
        if len(msg) == 8:
            print(msg)
            msg = []

However, I am getting unicodeDecodeError 'utf-8' codec can't decode byte 0xc8 in position 0: invalid continuation byte. So I used codec module,

import codec
pipe = codec.open("/dev/input/js0", "r", encoding="utf-8")

But I am still getting same error. I also tried to read different mode, rb. How can I read this input values and having it as 8btye values and in hexa format(ex.001c)

jayko03
  • 2,329
  • 7
  • 28
  • 51

0 Answers0