Skip to content

Instantly share code, notes, and snippets.

@lewangdev
Created May 12, 2023 06:23
Show Gist options
  • Save lewangdev/2a02fa2e48de3bdea3ce8094ce89e7af to your computer and use it in GitHub Desktop.
Save lewangdev/2a02fa2e48de3bdea3ce8094ce89e7af to your computer and use it in GitHub Desktop.

Revisions

  1. lewangdev created this gist May 12, 2023.
    32 changes: 32 additions & 0 deletions joystick_event.py
    Original 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