def get_onscreen_controls(self, api): title = '' detail_text = '' buttons = [] show_stop = True controls_enabled = False targets_enabled = False show_slider = False promoted_control_id = '' battery_low_land = api.health_monitor.is_battery_critically_low() if battery_low_land: title = 'Low Battery' detail_text = 'Tour disabled' controls_enabled = True elif self.state == TourState.SETUP: title = 'Press Go to Begin Tour' detail_text = 'Drone will automatically film the area.' controls_enabled = True show_stop = False targets_enabled = False buttons.append(UiButton('go', 'Go', style='PRIMARY')) promoted_control_id = 'go' elif self.state == TourState.GOTO: title = 'Tour in Progress' detail_text = "Step {}".format(self.motion_index) show_slider = True targets_enabled = False buttons.append(UiButton('skip', label='Skip')) elif self.state == TourState.STOP: title = 'Press Go to Start New Tour' controls_enabled = True show_stop = False targets_enabled = False buttons.append(UiButton('go', 'Go', style='PRIMARY')) promoted_control_id = 'go' else: er.REPORT_WARNING('Unknown state "{}"'.format(self.state)) return dict( title=title, detail=detail_text, arrows_enabled=controls_enabled, height_slider_enabled=controls_enabled, zoom_slider_enabled=controls_enabled and self.has_subject, steering_enabled=controls_enabled and not self.has_subject, tap_targets_enabled=targets_enabled, double_tap_enabled=controls_enabled, drag_enabled=controls_enabled, show_stop=show_stop, promoted_control='speed' if show_slider else promoted_control_id, buttons=buttons, )
def get_onscreen_controls(self, api): if self.state == self.STATE.PAUSE: title = 'Paused' show_stop = False buttons = [UiButton('resume', 'Resume')] detail = '' elif self.state == self.STATE.LOCKED: title = 'Following' if not self.subject_has_moved: detail = 'waiting for movement' else: locked_time = self.get_time_since_transition(api.utime) time_left = int( self.get_value_for_user_setting('duration') - locked_time) detail = 'time left: {}s'.format(time_left) buttons = [] show_stop = True else: title = string.capitalize(self.state.name) detail = '' buttons = [] show_stop = True controls = {} controls['arrows_enabled'] = not show_stop controls['buttons'] = buttons controls['height_slider_enabled'] = not show_stop controls['show_stop'] = show_stop controls['title'] = title controls['detail'] = detail return controls
def get_onscreen_controls(self, api): """ Add buttons and titles to the skydio app based on current skill state. """ num_sides = int(self.get_value_for_user_setting('num_sides')) controls = dict() if self.running: # Show a title based on the current index. current = int(self.index + 1) controls['title'] = 'Vertex {}/{}'.format(current, num_sides) # Show the red STOP button controls['show_stop'] = True # Hide the manual controls and buttons controls['height_slider_enabled'] = False controls['buttons'] = [] else: # Confirm the number of sides in the polygon with a title controls['title'] = '{}-Sided Polygon'.format(num_sides) # Enable manual controls and a Start Button controls['height_slider_enabled'] = True controls['buttons'] = [UiButton(identifier='start', label='Start')] # Hide the stop button controls['show_stop'] = False return controls
def get_onscreen_controls(self, api): """ Configure the ui. """ controls = {} if self.motion: controls['show_stop'] = True controls['height_slider_enabled'] = False else: controls['show_stop'] = False controls['height_slider_enabled'] = True title = type(self.motion) if self.motion else '' controls['title'] = str(self.data.get('title', title)) controls['detail'] = str(self.data.get('detail', '')) if not self.pressed: controls['buttons'] = [UiButton('send', label='Ping')] else: controls['buttons'] = [] return controls
def get_onscreen_controls(self, api): """ Add buttons and titles to the app based on current skill state. """ controls = dict() if self.running: # Show a title based on detected objects num_detections = len(api.subject.get_all_tracks()) closest_object = get_closest_person(api.subject, self.home_point) if closest_object: distance = np.linalg.norm(closest_object.position - self.home_point) else: distance = -1 if not self.following: controls['title'] = 'Searching' controls['detail'] = \ 'Detections: {}\nClosest: {:.1f}m'.format(num_detections, distance) else: controls['title'] = 'Following' controls['detail'] = '' # Show the red STOP button controls['show_stop'] = True # Hide the manual controls and buttons controls['height_slider_enabled'] = False controls['buttons'] = [] else: controls['title'] = 'Set Home Point' controls['detail'] = '' # Enable manual controls and a Start Button controls['height_slider_enabled'] = True controls['buttons'] = [ UiButton(identifier='set_point', label='Set') ] # Hide the stop button controls['show_stop'] = False return controls
def get_onscreen_controls(self, api): """ Populate the ui elements that should appear on the phone based on the mission status code. """ buttons = [] promoted_control_id = None if self.paused: title = 'Paused' detail = '' resume_btn = UiButton('resume', 'Resume') buttons.append(resume_btn) if self.status_code == MissionStatus.IN_PROGRESS: abort_btn = UiButton('abort', 'Abort', style='DANGER') buttons.append(abort_btn) elif self.status_code == MissionStatus.CONFIG_REQUIRED: title = 'Ready to Inspect' detail = 'Adjust settings then press start' start_btn = UiButton('start', 'Start', style='PRIMARY') buttons.append(start_btn) promoted_control_id = 'start' elif self.status_code == MissionStatus.CALIBRATING: title = 'Calibrating GPS' if self._auto_init_start_utime: delta = int( tm.utime_to_seconds(api.utime - self._auto_init_start_utime)) detail = "t = {}".format(delta) else: detail = '' elif self.status_code == MissionStatus.IN_PROGRESS: title = 'Inspection in Progress' detail = "Waypoint {}/{}".format(self.current_waypoint_index, len(self.global_waypoints)) skip_btn = UiButton('skip', 'Skip') buttons.append(skip_btn) promoted_control_id = 'skip' elif self.status_code == MissionStatus.COMPLETED: title = 'Inspection Complete' detail = 'Press start to scan again' start_btn = UiButton('start', 'Start', style='PRIMARY') buttons.append(start_btn) promoted_control_id = 'start' elif self.status_code == MissionStatus.ABORTED: title = 'Inspection Aborted' detail = 'Press start to scan again' start_btn = UiButton('start', 'Start', style='PRIMARY') buttons.append(start_btn) promoted_control_id = 'start' elif self.status_code == MissionStatus.ERROR: title = 'Error' detail = 'mission failure' controls = dict( title=title, detail=detail, show_stop=not self.manual_control_enabled(), height_slider_enabled=self.manual_control_enabled(), arrows_enabled=self.manual_control_enabled(), buttons=buttons, promoted_control=promoted_control_id or '', ) return controls