This repository has been archived by the owner on Jan 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·82 lines (62 loc) · 2.44 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import logging
import _thread
import kivy
kivy.require('1.9.0') # replace with your current kivy version !
from kivy.app import App
from kivy.properties import *
from kivy.lang import Builder
from kivy.core.window import Window
from kivy.uix.screenmanager import Screen
from dronemodules.controlloger import MyLabelHandler
from dronemodules.connectionmanager import DroneConnectionDriver
# KV Files with app views
Builder.load_file('src/kvfiles/settingscreen.kv')
Window.clearcolor = (1, 1, 1, 1) # This turn white background
drone_connection_driver = None
log = None
def init_connection(logger, drone_ip, drone_port):
global drone_connection_driver
if drone_connection_driver is None:
drone_connection_driver = DroneConnectionDriver(logger, drone_ip, drone_port)
drone_connection_driver.init_comm_config_process()
else:
drone_connection_driver.init_comm_config_process()
def disconnect_drone():
global drone_connection_driver
if drone_connection_driver.connected():
drone_connection_driver.stop_drone_connection()
else:
print("Drone disconnected.")
class MenuScreen(Screen):
counter = NumericProperty(0)
def my_callback(self, button):
print('The button ' + button + ' has been pushed')
self.counter += 1
class SettingScreen(Screen):
log_text = StringProperty('')
def __init__(self, **kwargs):
super(SettingScreen, self).__init__(**kwargs)
def init_drone_connection(self, connect_btn, drone_ip, drone_port):
global log
btn_state = connect_btn.state
if drone_ip and drone_port:
if btn_state == 'down':
# LOGGERFIX: Crear un archivo de configuracion para el logger
if log is None:
log = logging.getLogger("Control")
log.level = logging.DEBUG
# log.level = logging.INFO
log.addHandler(MyLabelHandler(self.ids['log_box'], logging.DEBUG))
_thread.start_new(init_connection, (log, drone_ip, drone_port,))
connect_btn.text = 'Disconnect'
print('%s:%s', drone_ip, drone_port)
elif btn_state == 'normal':
disconnect_drone()
connect_btn.text = 'Connect'
else:
connect_btn.state = 'normal'
class DroneControllerApp(App):
def build(self):
print("init")
if __name__ == '__main__':
DroneControllerApp().run()