|
|
@ -30,9 +30,9 @@ def gamepad_axes(axes_data): |
|
|
|
print('GAMEPAD axes') |
|
|
|
print(axes_data) |
|
|
|
from roberto import serial |
|
|
|
x = axes_data['0'] |
|
|
|
y = axes_data['1'] |
|
|
|
r = axes_data['3'] |
|
|
|
x = applyDeadZone( axes_data['0'], 0.15 ) |
|
|
|
y = x = applyDeadZone( axes_data['1'], 0.15 ) |
|
|
|
r = x = applyDeadZone( axes_data['3'], 0.15 ) |
|
|
|
m0 = +y - x - r |
|
|
|
m1 = +y + x - r |
|
|
|
m2 = -y + x - r |
|
|
@ -43,3 +43,11 @@ def gamepad_axes(axes_data): |
|
|
|
m3 *= 4000 |
|
|
|
command = 'S '+str(int(m0))+','+str(int(m1))+','+str(int(m2))+','+str(int(m3))+'\n' |
|
|
|
serial.write(bytes(command, "utf8")) |
|
|
|
|
|
|
|
def applyDeadZone(value, threshold): |
|
|
|
new_value = ( abs(value) - threshold ) / ( 1 - threshold ) |
|
|
|
if new_value < 0: |
|
|
|
return 0 |
|
|
|
if value < 0: |
|
|
|
new_value = new_value * -1 |
|
|
|
return new_value |
|
|
|