def run_ahrs_hud_element(element_type, use_detail_font=True): """ Runs an AHRS based HUD element alone for testing purposes Arguments: element_type {type} -- The class to create. Keyword Arguments: use_detail_font {bool} -- Should the detail font be used. (default: {True}) """ from heads_up_display import HeadsUpDisplay from aircraft import AhrsSimulation from datetime import datetime clock = pygame.time.Clock() __backpage_framebuffer__, screen_size = display_init() # args.debug) __width__, __height__ = screen_size pygame.mouse.set_visible(False) pygame.font.init() font_size_std = int(__height__ / 10.0) font_size_detail = int(__height__ / 12.0) __font__ = pygame.font.Font("./assets/fonts/LiberationMono-Bold.ttf", font_size_std) __detail_font__ = pygame.font.Font( "./assets/fonts/LiberationMono-Bold.ttf", font_size_detail) if use_detail_font: font = __detail_font__ else: font = __font__ __aircraft__ = AhrsSimulation() __pixels_per_degree_y__ = ( __height__ / configuration.CONFIGURATION.get_degrees_of_pitch() ) * configuration.CONFIGURATION.get_pitch_degrees_display_scaler() hud_element = element_type( configuration.CONFIGURATION.get_degrees_of_pitch(), __pixels_per_degree_y__, font, (__width__, __height__)) while True: orientation = __aircraft__.ahrs_data orientation.utc_time = str(datetime.utcnow()) __aircraft__.simulate() __backpage_framebuffer__.fill(BLACK) hud_element.render(__backpage_framebuffer__, orientation) pygame.display.flip() clock.tick(60)
def __init__(self, logger): """ Initialize and create a new HUD. """ self.__last_perf_render__ = None self.__logger__ = logger self.__view_element_timers = {} self.__fps__ = RollingStats('FPS') self.__texture_cache_size__ = RollingStats('TextureCacheSize') self.__texture_cache_misses__ = RollingStats('TextureCacheMisses') self.__texture_cache_purges__ = RollingStats('TextureCachePurges') self.render_perf = TaskTimer('Render') self.frame_setup = TaskTimer('Setup') self.frame_cleanup = TaskTimer('Cleanup') self.__frame_timers__ = { 'Setup': self.frame_setup, 'Render': self.render_perf, 'Cleanup': self.frame_cleanup } self.cache_perf = TaskTimer('Cache') self.__fps__.push(0) adsb_traffic_address = "ws://{0}/traffic".format( CONFIGURATION.stratux_address()) self.__connection_manager__ = traffic.ConnectionManager( adsb_traffic_address) self.__backpage_framebuffer__, screen_size = display.display_init( ) # args.debug) self.__width__, self.__height__ = screen_size pygame.mouse.set_visible(False) pygame.font.init() self.__should_render_perf__ = False font_size_std = int(self.__height__ / 10.0) font_size_detail = int(self.__height__ / 12.0) font_size_loading = int(self.__height__ / 4.0) self.__font__ = pygame.font.Font( get_absolute_file_path("./assets/fonts/LiberationMono-Bold.ttf"), font_size_std) self.__detail_font__ = pygame.font.Font( get_absolute_file_path("./assets/fonts/LiberationMono-Bold.ttf"), font_size_detail) self.__loading_font__ = pygame.font.Font( get_absolute_file_path( "./assets/fonts/LiberationMono-Regular.ttf"), font_size_loading) self.__show_boot_screen__() self.__aircraft__ = Aircraft(self.__logger__) self.__pixels_per_degree_y__ = int( (self.__height__ / CONFIGURATION.get_degrees_of_pitch()) * CONFIGURATION.get_pitch_degrees_display_scaler()) self.__ahrs_not_available_element__ = self.__build_ahrs_hud_element( ahrs_not_available.AhrsNotAvailable) self.__hud_views__ = self.__build_hud_views() self.__view_index__ = 0 logger = None if self.__logger__ is not None: logger = self.__logger__.logger self.web_server = restful_host.HudServer() RecurringTask("rest_host", 0.1, self.web_server.run, start_immediate=False) RecurringTask("purge_old_traffic", 10.0, self.__purge_old_reports__, start_immediate=False) RecurringTask("update_traffic", 0.1, self.__update_traffic_reports__, start_immediate=True) RecurringTask("update_aithre", 5.0, self.__update_aithre__, start_immediate=True)
def run_adsb_hud_element(element_type, use_detail_font=True): """ Runs a ADSB based HUD element alone for testing purposes Arguments: element_type {type} -- The class to create. Keyword Arguments: use_detail_font {bool} -- Should the detail font be used. (default: {True}) """ from heads_up_display import HeadsUpDisplay from hud_elements import HudDataCache from aircraft import AhrsSimulation from traffic import SimulatedTraffic simulated_traffic = (SimulatedTraffic(), SimulatedTraffic(), SimulatedTraffic()) clock = pygame.time.Clock() __backpage_framebuffer__, screen_size = display_init() # args.debug) __width__, __height__ = screen_size pygame.mouse.set_visible(False) pygame.font.init() font_size_std = int(__height__ / 10.0) font_size_detail = int(__height__ / 12.0) __font__ = pygame.font.Font("./assets/fonts/LiberationMono-Bold.ttf", font_size_std) __detail_font__ = pygame.font.Font( "./assets/fonts/LiberationMono-Bold.ttf", font_size_detail) if use_detail_font: font = __detail_font__ else: font = __font__ __aircraft__ = AhrsSimulation() __pixels_per_degree_y__ = (__height__ / configuration.CONFIGURATION.get_degrees_of_pitch()) * \ configuration.CONFIGURATION.get_pitch_degrees_display_scaler() hud_element = element_type( configuration.CONFIGURATION.get_degrees_of_pitch(), __pixels_per_degree_y__, font, (__width__, __height__)) while True: for test_data in simulated_traffic: test_data.simulate() AdsbTrafficClient.TRAFFIC_MANAGER.handle_traffic_report( test_data.to_json()) HudDataCache.purge_old_traffic_reports() orientation = __aircraft__.ahrs_data __aircraft__.simulate() __backpage_framebuffer__.fill(BLACK) hud_element.render(__backpage_framebuffer__, orientation) pygame.display.flip() clock.tick(60)
def __init__(self, logger): """ Initialize and create a new HUD. """ self.__logger__ = logger self.render_perf = TaskTimer("Render") self.orient_perf = TaskTimer("Orient") adsb_traffic_address = "ws://{0}/traffic".format( CONFIGURATION.stratux_address()) self.__connection_manager__ = traffic.ConnectionManager( adsb_traffic_address) self.__backpage_framebuffer__, screen_size = display.display_init( ) # args.debug) self.__width__, self.__height__ = screen_size pygame.mouse.set_visible(False) pygame.font.init() self.__should_render_perf__ = False font_name = "consolas,monaco,courier,arial,helvetica" font_size_std = int(self.__height__ / 10.0) font_size_detail = int(self.__height__ / 12.0) font_size_loading = int(self.__height__ / 4.0) self.__font__ = pygame.font.Font( get_absolute_file_path("./assets/fonts/LiberationMono-Bold.ttf"), font_size_std) self.__detail_font__ = pygame.font.Font( get_absolute_file_path("./assets/fonts/LiberationMono-Bold.ttf"), font_size_detail) self.__loading_font__ = pygame.font.SysFont(font_name, font_size_loading, True, False) self.__show_boot_screen__() self.__aircraft__ = Aircraft() self.__pixels_per_degree_y__ = ( self.__height__ / HeadsUpDisplay.DEGREES_OF_PITCH ) * HeadsUpDisplay.PITCH_DEGREES_DISPLAY_SCALER self.__ahrs_not_available_element__ = self.__build_ahrs_hud_element( ahrs_not_available.AhrsNotAvailable) bottom_compass_element = self.__build_ahrs_hud_element( compass_and_heading_bottom_element.CompassAndHeadingBottomElement, True) adsb_target_bug_element = adsb_target_bugs.AdsbTargetBugs( HeadsUpDisplay.DEGREES_OF_PITCH, self.__pixels_per_degree_y__, self.__font__, (self.__width__, self.__height__)) adsb_onscreen_reticle_element = adsb_on_screen_reticles.AdsbOnScreenReticles( HeadsUpDisplay.DEGREES_OF_PITCH, self.__pixels_per_degree_y__, self.__font__, (self.__width__, self.__height__)) altitude_element = self.__build_ahrs_hud_element( altitude.Altitude, True) time_element = self.__build_ahrs_hud_element(time.Time, True) system_info_element = self.__build_ahrs_hud_element( system_info.SystemInfo, False) groundspeed_element = self.__build_ahrs_hud_element( groundspeed.Groundspeed, True) traffic_only_view = [ bottom_compass_element, adsb_target_bug_element, adsb_onscreen_reticle_element ] system_info_view = [system_info_element] traffic_listing_view = [ adsb_traffic_listing.AdsbTrafficListing( HeadsUpDisplay.DEGREES_OF_PITCH, self.__pixels_per_degree_y__, self.__detail_font__, (self.__width__, self.__height__)) ] # norden_view = [ # bottom_compass_element, # heading_target_bugs.HeadingTargetBugs(HeadsUpDisplay.DEGREES_OF_PITCH, self.__pixels_per_degree_y__, self.__detail_font__, # (self.__width__, self.__height__)), # # Draw the ground speed and altitude last so they # # will appear "on top". # self.__build_ahrs_hud_element(target_count.TargetCount, True), # groundspeed_element, # altitude_element # ] ahrs_view = [ self.__build_ahrs_hud_element(level_reference.LevelReference, True), self.__build_ahrs_hud_element(artificial_horizon.ArtificialHorizon, True), bottom_compass_element, altitude_element, self.__build_ahrs_hud_element(skid_and_gs.SkidAndGs, True), self.__build_ahrs_hud_element(roll_indicator.RollIndicator, True), groundspeed_element ] time_view = [time_element] self.__hud_views__ = [ ("Traffic", traffic_only_view), ("AHRS", ahrs_view), ("ADSB List", traffic_listing_view), # ("Norden", norden_view), ("Time", time_view), ("System Info", system_info_view), ("", []) ] self.__view_index__ = 0 logger = None if self.__logger__ is not None: logger = self.__logger__.logger