Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DarkPaw Robot code
#3
rom pyPS4Controller.controller import Controller, Event


class MyController(Controller):

def __init__(self, **kwargs):
Controller.__init__(self, **kwargs)

def on_x_press(self):
print("Hello world")

def on_x_release(self):
print("Goodbye world")


class MyEventDefinition(Event):

def __init__(self, **kwargs):
Event.__init__(self, **kwargs)

# each overloaded function, has access to:
# - self.button_id
# - self.button_type
# - self.value
# use those variables to determine which button is being pressed
def x_pressed(self):
return self.button_id == 0 and self.button_type == 1 and self.value == 1

def x_released(self):
return self.button_id == 0 and self.button_type == 1 and self.value == 0

controller = MyController(interface="/dev/input/js0", connecting_using_ds4drv=False, event_definition=MyEventDefinition)
controller.debug = True # you will see raw data stream for any button press, even if that button is not mapped
# you can start listening before controller is paired, as long as you pair it within the timeout window
controller.listen(timeout=60)
Reply


Messages In This Thread
DarkPaw Robot code - by Tyrelex78 - Nov-26-2020, 07:28 PM
RE: DarkPaw Robot code - by Larz60+ - Nov-26-2020, 10:45 PM
RE: DarkPaw Robot code - by Tyrelex78 - Nov-26-2020, 11:59 PM
RE: DarkPaw Robot code - by Tyrelex78 - Nov-27-2020, 12:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The Wall-E Robot Argentum 1 1,459 Apr-03-2022, 03:01 PM
Last Post: sastonrobert
  Turning Robot towards goal, comparison of angles SpaceTime 0 2,788 Jan-21-2019, 10:26 PM
Last Post: SpaceTime
  how to program robot to pass wise man puzzle steven12341234 0 1,973 Dec-02-2018, 08:31 AM
Last Post: steven12341234
  Help Threading python robot lucandmendes 0 10,185 May-03-2018, 02:42 PM
Last Post: lucandmendes
  Parallel Processing in Python with Robot crcali 6 5,246 Apr-06-2018, 03:48 AM
Last Post: Larz60+
  Robot Stay Inside Circular Ring webmanoffesto 4 6,743 Dec-07-2016, 06:57 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020