Created
May 12, 2023 06:23
-
-
Save lewangdev/2a02fa2e48de3bdea3ce8094ce89e7af to your computer and use it in GitHub Desktop.
Revisions
-
lewangdev created this gist
May 12, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ def joystickLoop(eventFile): FORMAT = 'llHHI' EVENT_SIZE = struct.calcsize(FORMAT) with open(eventFile, 'rb') as infile: while True: event = infile.read(EVENT_SIZE) _, _, t, c, v = struct.unpack(FORMAT, event) print(t, c, v) if t == 3 and v == 4294967295: if c == 17: # press UP: elif c == 16: # press LEFT elif t == 3 and v == 1: if c == 17: # press DOWN: elif c == 16: # press RIGHT elif t == 3 and v == 0: if c == 17 or c == 16: # pass elif t == 1 and v == 1: if c == 307: # Camera up if c == 305: # Cameta down if c == 304: # Cameta right if c == 308: # Camera left elif t == 1 and v == 1: pass