-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathutils.py
More file actions
49 lines (38 loc) · 1.46 KB
/
Copy pathutils.py
File metadata and controls
49 lines (38 loc) · 1.46 KB
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
import win32api
from config import CONFIG
def to_hex(buffer):
return " ".join("{:02x}".format(x) for x in buffer)
def decodeu(data: bytes):
return int.from_bytes(data, byteorder='little', signed=False)
def decodes(data: bytes):
return int.from_bytes(data, byteorder='little', signed=True)
def convert_mac_string_to_value(mac: str):
return int.from_bytes(bytes([int(b, 16) for b in mac.split(":")]), 'big')
def get_stick_xy(data: bytes):
"""Convert 3 bytes containing stick x y values into these values"""
value = decodeu(data)
x = value & 0xFFF
y = value >> 12
return x, y
def signed_looping_difference_16bit(a, b):
diff = (b - a) % 65536
return diff - 65536 if diff > 32768 else diff
def apply_calibration_to_axis(raw_value, center, max_abs, min_abs):
signed_value = raw_value - center
if signed_value > CONFIG.deadzone:
return min(signed_value / max_abs, 1)
if signed_value < -CONFIG.deadzone:
return -min(-signed_value / min_abs, 1)
return 0
def press_or_release_mouse_button(state: bool, prev_state: bool, button: int, mouse_x: int, mouse_y):
if (state and not prev_state):
win32api.mouse_event(button, mouse_x, mouse_y, 0, 0)
if (not state and prev_state):
win32api.mouse_event(button << 1, mouse_x, mouse_y, 0, 0)
def reverse_bits(n: int, no_of_bits: int):
result = 0
for i in range(no_of_bits):
result <<= 1
result |= n & 1
n >>= 1
return result