Exemplo n.º 1
0
class HardwarePlatform(VirtualPlatform):
    """Base class for the smart_virtual hardware platform."""

    def __init__(self, machine):
        super(HardwarePlatform, self).__init__(machine)
        self.log = logging.getLogger("Smart Virtual Platform")
        self.log.debug("Configuring smart_virtual hardware interface.")

        self.delay = DelayManager()

    def __repr__(self):
        return '<Platform.SmartVirtual>'

    def initialize(self):
        self.machine.events.add_handler('machine_reset_phase_1',
                                        self._initialize2)

    def _initialize2(self):
        for device in self.machine.ball_devices:
            if not device.is_playfield() and device.config['eject_coil']:
                device.config['eject_coil'].hw_driver.register_ball_switches(
                    device.config['ball_switches'])

                if device.config['eject_targets'][0] is not self.machine.playfield:
                    device.config['eject_coil'].hw_driver.set_target_device(device.config['eject_targets'][0])

    def configure_driver(self, config, device_type='coil'):
        # todo should probably throw out the number that we get since it could
        # be a weird string and just return an incremental int?

        driver = SmartVirtualDriver(config['number'], self.machine, self)

        driver.driver_settings = config
        driver.driver_settings['pulse_ms'] = 30

        return driver, config['number']

    def write_hw_rule(self, *args, **kwargs):
        pass

    def clear_hw_rule(self, sw_name):
        sw_num = self.machine.switches[sw_name].number

        for entry in self.hw_switch_rules.keys():  # slice for copy
            if entry.startswith(
                    self.machine.switches.number(sw_num).name):
                del self.hw_switch_rules[entry]

    def tick(self):
        # ticks every hw loop (typically hundreds of times per sec)

        self.delay._process_delays(self.machine)

    def add_ball_to_device(self, device):
        if device.config['entrance_switch']:
            pass # todo

        found_switch = False

        if device.config['ball_switches']:
            for switch in device.config['ball_switches']:
                if self.machine.switch_controller.is_inactive(switch.name):
                    self.machine.switch_controller.process_switch(switch.name,
                                                                  1,
                                                                  True)
                    found_switch = True
                    break

            if not found_switch:
                raise AssertionError("KABOOM! We just added a ball to {} which"
                                     "was already full.".format(device.name))
Exemplo n.º 2
0
class HardwarePlatform(VirtualPlatform):
    """Base class for the smart_virtual hardware platform."""
    def __init__(self, machine):
        super(HardwarePlatform, self).__init__(machine)
        self.log = logging.getLogger("Smart Virtual Platform")
        self.log.debug("Configuring smart_virtual hardware interface.")

        self.delay = DelayManager()

    def __repr__(self):
        return '<Platform.SmartVirtual>'

    def initialize(self):
        self.machine.events.add_handler('machine_reset_phase_1',
                                        self._initialize2)

    def _initialize2(self):
        for device in self.machine.ball_devices:
            if not device.is_playfield() and device.config['eject_coil']:
                device.config['eject_coil'].hw_driver.register_ball_switches(
                    device.config['ball_switches'])

                if device.config['eject_targets'][
                        0] is not self.machine.playfield:
                    device.config['eject_coil'].hw_driver.set_target_device(
                        device.config['eject_targets'][0])

    def configure_driver(self, config, device_type='coil'):
        # todo should probably throw out the number that we get since it could
        # be a weird string and just return an incremental int?

        driver = SmartVirtualDriver(config['number'], self.machine, self)

        driver.driver_settings = config
        driver.driver_settings['pulse_ms'] = 30

        return driver, config['number']

    def write_hw_rule(self, *args, **kwargs):
        pass

    def clear_hw_rule(self, sw_name):
        sw_num = self.machine.switches[sw_name].number

        for entry in self.hw_switch_rules.keys():  # slice for copy
            if entry.startswith(self.machine.switches.number(sw_num).name):
                del self.hw_switch_rules[entry]

    def tick(self):
        # ticks every hw loop (typically hundreds of times per sec)

        self.delay._process_delays(self.machine)

    def add_ball_to_device(self, device):
        if device.config['entrance_switch']:
            pass  # todo

        found_switch = False

        if device.config['ball_switches']:
            for switch in device.config['ball_switches']:
                if self.machine.switch_controller.is_inactive(switch.name):
                    self.machine.switch_controller.process_switch(
                        switch.name, 1, True)
                    found_switch = True
                    break

            if not found_switch:
                raise AssertionError("KABOOM! We just added a ball to {} which"
                                     "was already full.".format(device.name))