From 75985456bc8a202ccca48997acac6cae43276b09 Mon Sep 17 00:00:00 2001 From: Thomas Lavocat Date: Wed, 4 Sep 2019 01:43:24 +0200 Subject: [PATCH] Rajout des diagonnales MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Le premier joystick est complété --- control.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/control.py b/control.py index 0f81003..2599a30 100644 --- a/control.py +++ b/control.py @@ -238,10 +238,8 @@ t1.start() absx = -1 prev_absx = -1 -state_absx=False absy = -1 prev_absy = -1 -state_absy=False prev_action = -1 @@ -251,32 +249,36 @@ while (True) : for event in events: if event.code =="ABS_X": absx = raffine_entree(event.state) - if (absx > 0 and absx>DEAD_ZONE) or (absx <0 and absx<-DEAD_ZONE): - state_absx = True if event.code =="ABS_Y": absy = raffine_entree(event.state) - if (absy > 0 and absy>DEAD_ZONE) or (absy <0 and absy<-DEAD_ZONE): - state_absy = True if abs(absx) < DEAD_ZONE and abs(absy) < DEAD_ZONE : neutral = 2 action_voulue = -1 - if state_absx == True : + if abs(absx) > DEAD_ZONE : if absx < -80 : action_voulue = 13 elif absx > 80 : action_voulue = 14 - #print("absx : {}".format(absx)) - state_absx = False - if state_absy == True : + if abs(absy) > DEAD_ZONE : if absy < -80 : action_voulue = 2 elif absy > 80 : action_voulue = 7 - #print("absy : {}".format(absx)) - state_absy = False + + if abs(absx) > DEAD_ZONE and abs(absy) > DEAD_ZONE : + print("absy : {}".format(absx)) + print("absx : {}".format(absy)) + if (absx <0 and absx < -40) and (absy <0 and absy < -40) : + action_voulue = 5 + elif (absx >0 and absx > 40) and (absy <0 and absy < -40) : + action_voulue = 6 + elif (absx >0 and absx > 40) and (absy >0 and absy > 40) : + action_voulue = 11 + elif (absx <0 and absx < -40) and (absy >0 and absy > 40) : + action_voulue = 10 if neutral == 2 :