@@ -71,19 +71,27 @@ async def run():
71
71
72
72
print (f"\n === Available options ===" )
73
73
print (f"Setting: { selected_setting .setting_id } " )
74
- print (f"Options:" )
75
- print_possible_options (possible_options )
76
-
77
- try :
78
- index_option = await make_user_choose_option (possible_options )
79
- except ValueError :
80
- print ("Invalid index" )
81
- continue
82
-
83
- selected_option = possible_options [index_option - 1 ]
74
+ if (not selected_setting .is_range ):
75
+ print (f"Options:" )
76
+ try :
77
+ print_possible_options (possible_options )
78
+ index_option = await make_user_choose_option (possible_options )
79
+ selected_option = possible_options [index_option - 1 ]
80
+
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 )
83
+ except ValueError :
84
+ print ("Invalid index" )
85
+ continue
86
+ else :
87
+ try :
88
+ selected_value = await make_user_choose_option_range (possible_options )
84
89
85
- print (f"Setting { selected_setting .setting_id } to { selected_option .option_description } !" )
86
- setting = Setting (selected_setting .setting_id , "" , selected_option , selected_setting .is_range )
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 )
92
+ except ValueError :
93
+ print ("Invalid value" )
94
+ continue
87
95
88
96
try :
89
97
await drone .camera .set_setting (setting )
@@ -113,7 +121,10 @@ def print_current_settings():
113
121
print (f"* CAM_MODE: { camera_mode } " )
114
122
for setting in current_settings :
115
123
print (f"* { setting .setting_id } : { setting .setting_description } " )
116
- print (f" -> { setting .option .option_description } " )
124
+ if setting .is_range :
125
+ print (f" -> { setting .option .option_id } " )
126
+ else :
127
+ print (f" -> { setting .option .option_description } " )
117
128
118
129
async def make_user_choose_camera_mode ():
119
130
index_mode_str = await ainput (f"\n Which mode do you want? [1..2] >>> " )
@@ -155,6 +166,23 @@ async def make_user_choose_option(possible_options):
155
166
156
167
return index_option
157
168
169
+ async def make_user_choose_option_range (possible_options ):
170
+ min_value = float (possible_options [0 ].option_id )
171
+ max_value = float (possible_options [1 ].option_id )
172
+
173
+ interval_text = ""
174
+ if len (possible_options ) == 3 :
175
+ interval_value = float (possible_options [2 ].option_id )
176
+ interval_text = f"interval: { interval_value } "
177
+
178
+ value_str = await ainput (f"\n What value do you want? [{ min_value } , { max_value } ] { interval_text } >>> " )
179
+
180
+ value = float (value_str )
181
+ if (value < min_value or value > max_value ):
182
+ raise ValueError ()
183
+
184
+ return str (value )
185
+
158
186
159
187
if __name__ == "__main__" :
160
188
loop = asyncio .get_event_loop ()
0 commit comments