Commit e66e6214 authored by Oleg Nikulin's avatar Oleg Nikulin

Изменения в потоке ввода

parent dabc790f
...@@ -13,16 +13,12 @@ temperatures = [30, 45, 50] ...@@ -13,16 +13,12 @@ temperatures = [30, 45, 50]
def temp_input(stop_event): def temp_input():
global temperatures global temperatures
while True: while True:
temps = [0, 0, 0] temps = [0, 0, 0]
temp_input = input('\033[75G' + 'Enter up to 3 temperature values (CSV): ') temp_input = input('\033[75G' + 'Enter up to 3 temperature values (CSV): ')
if stop_event.is_set():
input_thread_running = False
return
error = False error = False
comma_pos = 0 comma_pos = 0
find_start_index = 0 find_start_index = 0
...@@ -44,6 +40,7 @@ def temp_input(stop_event): ...@@ -44,6 +40,7 @@ def temp_input(stop_event):
try: #проверка, введено ли число try: #проверка, введено ли число
temps[i] = int(temp_substring) temps[i] = int(temp_substring)
except ValueError: except ValueError:
print('Temperature value must be a number')
error = True error = True
break break
...@@ -154,8 +151,8 @@ if __name__ == "__main__": ...@@ -154,8 +151,8 @@ if __name__ == "__main__":
if args.speed is not None: if args.speed is not None:
baudrate = args.speed baudrate = args.speed
if args.manual: if args.manual:
input_stop_event = Event() input_thread = threading.Thread(target = temp_input)
input_thread = threading.Thread(target = temp_input, args=(input_stop_event,)) input_thread.daemon = True
temp = '50,51,52' temp = '50,51,52'
if port is None: if port is None:
...@@ -193,14 +190,11 @@ if __name__ == "__main__": ...@@ -193,14 +190,11 @@ if __name__ == "__main__":
if (poll(serial_port)): if (poll(serial_port)):
if args.manual and not input_thread_running: if args.manual and not input_thread_running:
input_stop_event.clear()
input_thread.start() input_thread.start()
input_thread_running = True input_thread_running = True
regularPollInterval = True regularPollInterval = True
except (OSError, termios.error): except (OSError, termios.error):
input_stop_event.set()
print()
print('Serial port error. Trying to open serial port again...') print('Serial port error. Trying to open serial port again...')
serial_port = open_serial(port, baudrate) serial_port = open_serial(port, baudrate)
if serial_port is not None: if serial_port is not None:
...@@ -213,4 +207,5 @@ if __name__ == "__main__": ...@@ -213,4 +207,5 @@ if __name__ == "__main__":
time.sleep(0.5) time.sleep(0.5)
except KeyboardInterrupt: except KeyboardInterrupt:
print()
exit() exit()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment