From 4cbf58f8dc4aa92564c4b5cc7585b44494bab5cc Mon Sep 17 00:00:00 2001 From: fly Date: Sun, 15 Dec 2024 18:40:34 +0100 Subject: [PATCH] Fix lag issue Signed-off-by: fly --- fcuSync.py | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/fcuSync.py b/fcuSync.py index 34777a4..4baa130 100755 --- a/fcuSync.py +++ b/fcuSync.py @@ -231,11 +231,17 @@ winwing_fcu_set_led(Leds.EXPED_YELLOW, 70) winwing_fcu_set_led(Leds.SCREEN_BACKLIGHT, 200) winwing_fcu_lcd_set(speed, heading, alt, vs, 0x0) -s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM | socket.SOCK_NONBLOCK) s.bind(('', 12000)) try: + message = "d,100,360,10000,----,0.0,0.0,d" while True: - message, address = s.recvfrom(1024) + time.sleep(0.1) + try: + while True: + message, address = s.recvfrom(1024) + except BlockingIOError: + pass print(message) items = str(message).split(",") winwing_fcu_lcd_set(items[1], items[2], items[3], items[4], 0x0) @@ -320,18 +326,3 @@ try: except KeyboardInterrupt: s.close() - -#while True: -# buf_in = [None] * 7 -# winwing_fcu_set_led(Leds.AP1_GREEN, 1) -# winwing_fcu_set_led(Leds.AP2_GREEN, 0) -# winwing_fcu_lcd_set(speed, heading, alt, vs, 0x0) -# speed = speed + 1 -# heading = heading + 3 -# if heading > 360: -# heading = 0 -# time.sleep(0.5) -# winwing_fcu_set_led(Leds.AP1_GREEN, 0) -# winwing_fcu_set_led(Leds.AP2_GREEN, 1) -# winwing_fcu_lcd_set(speed, heading, alt, vs, 0xff) -# time.sleep(0.5)