Example #1
0
    def __init__(self, appname):

        self.appname = appname
        self.static_set = False

        #
        # Structures for Data Capture
        #
        self.info = info  # sim_info
        self.data = dict()

        #
        # GameController Fu
        #
        self.game_controller = GameController()
        self.game_controller.setInitialStatus()
        if self.game_controller.device is None:
            self.data['game_controller'] = 'No Game Controller found'
        else:
            self.data['game_controller'] = self.game_controller.device.get_name()

        #
        # Read the config
        #
        config_dict, self.valid_config = self.read_and_validate_config()
        self.button_forward = config_dict[BUTTON_FORWARD]
        self.button_backward = config_dict[BUTTON_BACK]
        self.raspberry_ip = config_dict[RASPBERRY_IP]
        self.raspberry_udp_port = config_dict[RASPBERRY_UDP_PORT]
        self.hz = config_dict[HZ]
        self.show_debug_window = config_dict[SHOW_DEBUG_WINDOW]

        self.data['raspberry_ip'] = self.raspberry_ip
        self.data['raspberry_udp_port'] = self.raspberry_udp_port

        ac.log("{} config: {}".format(self.appname, pformat(config_dict, indent=0, width=10000)))
        #
        # Set the Interval for Updates
        #
        self.interval = 1.0 / self.hz
        self.data['interval'] = self.interval
        self.data['hz'] = self.hz
        self.last_update_tick = 0
        self.frames_skipped = 0

        #
        # The Debugwindow as Application
        #
        fields_from_static = ('max_rpm', 'car_model', 'player_nick', 'max_fuel', 'num_cars')
        fields_from_physics = ('abs', 'drs', 'tc', 'kers_charge', 'kers_input', 'rpms', 'fuel', 'gear', 'speed_kmh', 'pit_limiter_on')
        fields_from_graphics = ('position', 'number_of_laps', 'completed_laps', 'i_current_time', 'i_last_time', 'i_best_time')

        self.field_shown_in_debug_window = (['static.{0}'.format(s) for s in fields_from_static] +
                                            ['physics.{0}'.format(s) for s in fields_from_physics] +
                                            ['graphics.{0}'.format(s) for s in fields_from_graphics] +
                                            ['frames_skipped', 'interval', 'raspberry_ip', 'raspberry_udp_port'])
        if self.show_debug_window:
            self.debug_window = DataProviderIngameDebugWindow(self.appname, 300, 500)
            for name in self.field_shown_in_debug_window:
                self.debug_window.add_label(Label(self.debug_window.app_id, name, '{}: N/A'.format(name)))
            self.debug_window.pack()

        #
        # create the UDP Socket
        #
        self.udp_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)