19
19
current_settings = []
20
20
possible_setting_options = []
21
21
22
+
22
23
async def run ():
23
24
drone = System ()
24
25
await drone .connect (system_address = "udp://:14540" )
@@ -27,7 +28,7 @@ async def run():
27
28
asyncio .ensure_future (observe_camera_mode (drone ))
28
29
asyncio .ensure_future (observe_possible_setting_options (drone ))
29
30
30
- while ( True ) :
31
+ while True :
31
32
entered_input = await ainput (usage_str )
32
33
33
34
if (entered_input == "p" ):
@@ -61,7 +62,8 @@ async def run():
61
62
print_possible_settings (possible_setting_options )
62
63
63
64
try :
64
- index_setting = await make_user_choose_setting (possible_setting_options )
65
+ index_setting = await \
66
+ make_user_choose_setting (possible_setting_options )
65
67
except ValueError :
66
68
print ("Invalid index" )
67
69
continue
@@ -75,20 +77,32 @@ async def run():
75
77
print (f"Options:" )
76
78
try :
77
79
print_possible_options (possible_options )
78
- index_option = await make_user_choose_option (possible_options )
80
+ index_option = await \
81
+ make_user_choose_option (possible_options )
79
82
selected_option = possible_options [index_option - 1 ]
80
83
81
- print (f"Setting { selected_setting .setting_id } to { selected_option .option_description } !" )
82
- setting = Setting (selected_setting .setting_id , "" , selected_option , selected_setting .is_range )
84
+ print (f"Setting { selected_setting .setting_id } "
85
+ f"to { selected_option .option_description } !" )
86
+ setting = Setting (
87
+ selected_setting .setting_id ,
88
+ "" ,
89
+ selected_option ,
90
+ selected_setting .is_range )
83
91
except ValueError :
84
92
print ("Invalid index" )
85
93
continue
86
94
else :
87
95
try :
88
- selected_value = await make_user_choose_option_range (possible_options )
89
-
90
- print (f"Setting { selected_setting .setting_id } to { selected_value } !" )
91
- setting = Setting (selected_setting .setting_id , "" , Option (selected_value , "" ), selected_setting .is_range )
96
+ selected_value = await \
97
+ make_user_choose_option_range (possible_options )
98
+
99
+ print (f"Setting { selected_setting .setting_id } "
100
+ f" to { selected_value } !" )
101
+ setting = Setting (
102
+ selected_setting .setting_id ,
103
+ "" ,
104
+ Option (selected_value , "" ),
105
+ selected_setting .is_range )
92
106
except ValueError :
93
107
print ("Invalid value" )
94
108
continue
@@ -102,21 +116,25 @@ async def run():
102
116
print ("Invalid input!" )
103
117
continue
104
118
119
+
105
120
async def observe_camera_mode (drone ):
106
121
global camera_mode
107
122
async for mode in drone .camera .mode ():
108
123
camera_mode = mode
109
124
125
+
110
126
async def observe_current_settings (drone ):
111
127
global current_settings
112
128
async for settings in drone .camera .current_settings ():
113
129
current_settings = settings
114
130
131
+
115
132
async def observe_possible_setting_options (drone ):
116
133
global possible_setting_options
117
134
async for settings in drone .camera .possible_setting_options ():
118
135
possible_setting_options = settings
119
136
137
+
120
138
def print_current_settings ():
121
139
print (f"* CAM_MODE: { camera_mode } " )
122
140
for setting in current_settings :
@@ -126,6 +144,7 @@ def print_current_settings():
126
144
else :
127
145
print (f" -> { setting .option .option_description } " )
128
146
147
+
129
148
async def make_user_choose_camera_mode ():
130
149
index_mode_str = await ainput (f"\n Which mode do you want? [1..2] >>> " )
131
150
index_mode = int (index_mode_str )
@@ -134,38 +153,46 @@ async def make_user_choose_camera_mode():
134
153
135
154
return index_mode
136
155
156
+
137
157
def print_possible_settings (possible_settings ):
138
158
i = 1
139
159
for setting in possible_settings :
140
160
print (f"{ i } . { setting .setting_id } : { setting .setting_description } " )
141
161
i += 1
142
162
163
+
143
164
async def make_user_choose_setting (possible_settings ):
144
165
n_settings = len (possible_settings )
145
- index_setting_str = await ainput (f"\n Which setting do you want to change? [1..{ n_settings } ] >>> " )
166
+ index_setting_str = await \
167
+ ainput (f"\n Which setting do you want to change?"
168
+ f" [1..{ n_settings } ] >>> " )
146
169
147
170
index_setting = int (index_setting_str )
148
171
if (index_setting < 1 or index_setting > n_settings ):
149
172
raise ValueError ()
150
173
151
174
return index_setting
152
175
176
+
153
177
def print_possible_options (possible_options ):
154
178
i = 1
155
179
for possible_option in possible_options :
156
180
print (f"{ i } . { possible_option .option_description } " )
157
181
i += 1
158
182
183
+
159
184
async def make_user_choose_option (possible_options ):
160
185
n_options = len (possible_options )
161
- index_option_str = await ainput (f"\n Which option do you want? [1..{ n_options } ] >>> " )
186
+ index_option_str = await \
187
+ ainput (f"\n Which option do you want? [1..{ n_options } ] >>> " )
162
188
163
189
index_option = int (index_option_str )
164
190
if (index_option < 1 or index_option > n_options ):
165
191
raise ValueError ()
166
192
167
193
return index_option
168
194
195
+
169
196
async def make_user_choose_option_range (possible_options ):
170
197
min_value = float (possible_options [0 ].option_id )
171
198
max_value = float (possible_options [1 ].option_id )
@@ -175,7 +202,9 @@ async def make_user_choose_option_range(possible_options):
175
202
interval_value = float (possible_options [2 ].option_id )
176
203
interval_text = f"interval: { interval_value } "
177
204
178
- value_str = await ainput (f"\n What value do you want? [{ min_value } , { max_value } ] { interval_text } >>> " )
205
+ value_str = await \
206
+ ainput (f"\n What value do you want?"
207
+ f" [{ min_value } , { max_value } ] { interval_text } >>> " )
179
208
180
209
value = float (value_str )
181
210
if (value < min_value or value > max_value ):
0 commit comments