File tree Expand file tree Collapse file tree 1 file changed +26
-8
lines changed Expand file tree Collapse file tree 1 file changed +26
-8
lines changed Original file line number Diff line number Diff line change @@ -252,10 +252,20 @@ def get_thumb_values(state):
252
252
magL = sqrt (LX * LX + LY * LY )
253
253
magR = sqrt (RX * RX + RY * RY )
254
254
255
- normLX = LX / magL
256
- normLY = LY / magL
257
- normRX = RX / magR
258
- normRY = RY / magR
255
+ if magL != 0 :
256
+ normLX = LX / magL
257
+ normLY = LY / magL
258
+ else : # if magL == 0 the stick is centered, there is no direction
259
+ normLX = 0
260
+ normLY = 0
261
+
262
+ if magR != 0 :
263
+ normRX = RX / magR
264
+ normRY = RY / magR
265
+ else : # if magR == 0 the stick is centered, there is no direction
266
+ normRX = 0
267
+ normRY = 0
268
+
259
269
260
270
normMagL = 0
261
271
normMagR = 0
@@ -396,8 +406,12 @@ def get_events():
396
406
397
407
magL = sqrt (LX * LX + LY * LY )
398
408
399
- normLX = LX / magL
400
- normLY = LY / magL
409
+ if magL != 0 :
410
+ normLX = LX / magL
411
+ normLY = LY / magL
412
+ else : # if magL == 0 the stick is centered, there is no direction
413
+ normLX = 0
414
+ normLY = 0
401
415
402
416
normMagL = 0
403
417
@@ -429,8 +443,12 @@ def get_events():
429
443
430
444
magR = sqrt (RX * RX + RY * RY )
431
445
432
- normRX = RX / magR
433
- normRY = RY / magR
446
+ if magR != 0 :
447
+ normRX = RX / magR
448
+ normRY = RY / magR
449
+ else : # if magR == 0 the stick is centered, there is no direction
450
+ normRX = 0
451
+ normRY = 0
434
452
435
453
normMagR = 0
436
454
You can’t perform that action at this time.
0 commit comments