Exemplo n.º 1
0
    def render(self, framebuffer, orientation):
        # Render a heading strip along the top

        self.task_timer.start()
        heading = orientation.get_onscreen_projection_heading()

        # Get the traffic, and bail out of we have none
        traffic_reports = HudDataCache.get_reliable_traffic()

        if traffic_reports is None:
            self.task_timer.stop()
            return

        traffic_reports = filter(
            lambda x: math.fabs(x.altitude - orientation.alt) <
            max_altitude_delta, traffic_reports)
        traffic_reports = traffic_reports[:max_target_bugs]

        # Draw the heading bugs in reverse order so the traffic closest to
        # us will be the most visible
        traffic_reports.reverse()

        [
            self.__render_traffic_heading_bug__(traffic_report, heading,
                                                orientation, framebuffer)
            for traffic_report in traffic_reports
        ]

        self.task_timer.stop()
Exemplo n.º 2
0
    def render(self, framebuffer, orientation):
        self.task_timer.start()

        if not HudDataCache.IS_TRAFFIC_AVAILABLE:
            (texture, size) = HudDataCache.get_cached_text_texture(
                "TRAFFIC UNAVAILABLE",
                self.__font__,
                text_color=RED,
                background_color=BLACK,
                use_alpha=True)
            width = size[0]

            framebuffer.blit(texture, (self.__center_x__ -
                                       (width >> 1), self.__text_y_pos__))
        self.task_timer.stop()
Exemplo n.º 3
0
    def render(self, framebuffer, orientation):
        # Render a heading strip along the top

        self.task_timer.start()
        heading = orientation.get_onscreen_projection_heading()

        # Get the traffic, and bail out of we have none
        traffic_reports = HudDataCache.get_reliable_traffic()

        if traffic_reports is None:
            self.task_timer.stop()
            return

        reports_to_show = filter(lambda x: math.fabs(x.altitude - orientation.alt) < max_altitude_delta, traffic_reports)
        reports_to_show = reports_to_show[:max_target_bugs]

        [self.__render_traffic_heading_bug__(
            traffic_report, heading, orientation, framebuffer) for traffic_report in reports_to_show]

        self.task_timer.stop()
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)