-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller_cps.py
62 lines (36 loc) · 1.34 KB
/
controller_cps.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import time, pydualsense
ds = pydualsense.pydualsense() # initialize pydualsense library
controller_connected = False
while not controller_connected:
try:
ds.init() # connect to and initialize controller
print("Controller found!")
controller_connected = True
except:
print("Controller not found, searching again...")
time.sleep(1)
press_count = 0
def cross_counter(state): # event function counting presses
global press_count
if state:
#print(f"Cross: {state}")
press_count += 1
def cross_cps_test(seconds:int):
global press_count
press_count = 0 # Reset counter
print("Recording presses...")
time.sleep(seconds) # pause for seconds amount of time
cps = press_count / seconds # calculate cps
print(f"Done! You achieved {round(cps,2)} clicks per second")
ds.cross_pressed += cross_counter # create event handler for cross button presses
has_printed = False
while not ds.state.R1: # Run program until R1 is pressed
if not has_printed:
print("Press 'SQUARE' to initiate CPS test \nPress 'R1' to exit program")
has_printed = True
if ds.state.square:
cross_cps_test(3)
has_printed = False
print("Exiting program!")
time.sleep(1)
ds.close() # close controller device