I am very green to python and python3. Most of my background has come from microprocessor work such as arduinos and basic stamp.
So I am writing something for being able to control an IP camera from a joystick. Plan is to use something like a Pi to run the code. The program will read a usb joystick in and convert it into an URL for the cameras API. i have got this far but with an issue.
the code with be run on a linux os proberly ubuntu or raspbian
I have got so far and seem to be working well apart from a snag that I have come across with the bit of code I am using to read the joystick.
this is just a snippet of the rest of the code
import sys
pipe = open('/dev/input/js0', 'rb') #open joystick
action = []
while True:
StickValue = readStik(pipe)
print ("StickValue")
def readStick(pipe):
action = []
while stop == 1:
for character in pipe.read(1):
action += [int(character)]
if len(action) == 8:
StickValue = action
action = []
stop = 2
##when joystick is stationary code hangs here.
return StickValue
#do some more stuff here while waiting for new joystick inputs apposed to hanging
I can see why it hangs as its waiting till all 8bytes have been read out before stopping the while loop but am struggling to working out how I get around it or is there a better way of reading the joystick. I have been looking at pygame now but would mean a major re write of the rest of the code.
Thanks