From 9790d2b164360f1a63623beb787b3989f3f81dcb Mon Sep 17 00:00:00 2001 From: Arthur Golubtsov Date: Sat, 15 Jun 2019 13:29:37 +0300 Subject: [PATCH] Server: Repair bug in emegrency land function --- Server/server_qt.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/Server/server_qt.py b/Server/server_qt.py index 4405f267..7e48b328 100644 --- a/Server/server_qt.py +++ b/Server/server_qt.py @@ -1,5 +1,6 @@ import os import glob +import math from PyQt5 import QtWidgets from PyQt5.QtGui import QStandardItemModel, QStandardItem @@ -202,15 +203,16 @@ def emergency(self): result = -1 while (result!=0) and (result != 3) and (result != 4): # light_green_red(min, max) - client_row_mid = int((client_row_max+client_row_min) / 2) + client_row_mid = int(math.ceil((client_row_max+client_row_min) / 2.0)) + print(client_row_min, client_row_mid, client_row_max) for row_num in range(client_row_min, client_row_mid): item = model.item(row_num, 0) copter = Client.get_by_id(item.text()) - copter.send_message("led_fill", {"red": 255}) + copter.send_message("led_fill", {"green": 255}) for row_num in range(client_row_mid, client_row_max + 1): item = model.item(row_num, 0) copter = Client.get_by_id(item.text()) - copter.send_message("led_fill", {"green": 255}) + copter.send_message("led_fill", {"red": 255}) Dialog = QtWidgets.QDialog() ui = Ui_Dialog() ui.setupUi(Dialog) @@ -218,9 +220,18 @@ def emergency(self): result = Dialog.exec() print("Dialog result: {}".format(result)) if (client_row_max != client_row_min): - if (result == 1): - client_row_max = client_row_mid + if (result == 1): + for row_num in range(client_row_mid, client_row_max + 1): + item = model.item(row_num, 0) + copter = Client.get_by_id(item.text()) + copter.send_message("led_fill") + client_row_max = client_row_mid - 1 + elif (result == 2): + for row_num in range(client_row_min, client_row_mid): + item = model.item(row_num, 0) + copter = Client.get_by_id(item.text()) + copter.send_message("led_fill") client_row_min = client_row_mid if result == 0: