示例#1
0
        def enable_flippers(self, enable):
		
		"""Enables or disables the flippers AND bumpers."""
                #wpc flippers
		for flipper in self.config['PRFlippers']:
			self.logger.info("Programming flipper %s", flipper)
			main_coil = self.coils[flipper+'Main']
			hold_coil = self.coils[flipper+'Hold']
			switch_num = self.switches[flipper].number

			drivers = []
			if enable:
				drivers += [pinproc.driver_state_pulse(main_coil.state(), main_coil.default_pulse_time)]
				drivers += [pinproc.driver_state_pulse(hold_coil.state(), 0)]
			self.proc.switch_update_rule(switch_num, 'closed_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)
			
			drivers = []
			if enable:
				drivers += [pinproc.driver_state_disable(main_coil.state())]
				if not self.paused or flipper=='FlipperLwL':
					drivers += [pinproc.driver_state_disable(hold_coil.state())]
	
			self.proc.switch_update_rule(switch_num, 'open_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)

			if not enable:
				main_coil.disable()
				hold_coil.disable()

		#bumpers
		self.enable_bumpers(enable)
示例#2
0
	def enable_Upper_flippers(self, flipper,enable):
		#return True
		
		"""Enables or disables the flippers AND bumpers."""

		main_coil = self.coils[flipper+'Main']
		if self.coils.has_key(flipper+'Hold'): 
			style = 'wpc'
			hold_coil = self.coils[flipper+'Hold']
		else: 
			style = 'stern'
		switch_num = self.switches[flipper].number

		drivers = []
		if enable:
			if style == 'wpc':
				drivers += [pinproc.driver_state_pulse(main_coil.state(), main_coil.default_pulse_time)]
				drivers += [pinproc.driver_state_pulse(hold_coil.state(), 0)]
			else:
				drivers += [pinproc.driver_state_patter(main_coil.state(), 2, 18, main_coil.default_pulse_time, True)]
		self.proc.switch_update_rule(switch_num, 'closed_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)
			
		drivers = []
		if enable:
			drivers += [pinproc.driver_state_disable(main_coil.state())]
			if style == 'wpc':
				drivers += [pinproc.driver_state_disable(hold_coil.state())]
	
		self.proc.switch_update_rule(switch_num, 'open_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)

		if not enable:
			main_coil.disable()
			if style == 'wpc':
				hold_coil.disable()
示例#3
0
    def enable_Upper_flippers(self, flipper, enable):
        #return True
        """Enables or disables the flippers AND bumpers."""

        main_coil = self.coils[flipper + 'Main']
        if self.coils.has_key(flipper + 'Hold'):
            style = 'wpc'
            hold_coil = self.coils[flipper + 'Hold']
        else:
            style = 'stern'
        switch_num = self.switches[flipper].number

        drivers = []
        if enable:
            if style == 'wpc':
                drivers += [
                    pinproc.driver_state_pulse(main_coil.state(),
                                               main_coil.default_pulse_time)
                ]
                drivers += [pinproc.driver_state_pulse(hold_coil.state(), 0)]
            else:
                drivers += [
                    pinproc.driver_state_patter(main_coil.state(), 2, 18,
                                                main_coil.default_pulse_time,
                                                True)
                ]
        self.proc.switch_update_rule(switch_num, 'closed_nondebounced', {
            'notifyHost': False,
            'reloadActive': False
        }, drivers,
                                     len(drivers) > 0)

        drivers = []
        if enable:
            drivers += [pinproc.driver_state_disable(main_coil.state())]
            if style == 'wpc':
                drivers += [pinproc.driver_state_disable(hold_coil.state())]

        self.proc.switch_update_rule(switch_num, 'open_nondebounced', {
            'notifyHost': False,
            'reloadActive': False
        }, drivers,
                                     len(drivers) > 0)

        if not enable:
            main_coil.disable()
            if style == 'wpc':
                hold_coil.disable()
示例#4
0
	def enable_flippers(self, enable):
		#return True
		
		"""Enables or disables the flippers AND bumpers."""
		if self.config.has_key('PRFlippers'):
		  for flipper in self.config['PRFlippers']:
			self.logger.info("Programming flipper %s", flipper)
			main_coil = self.coils[flipper+'Main']
			if self.coils.has_key(flipper+'Hold'): 
				style = 'wpc'
				self.logger.info("Enabling WPC style flipper")
				hold_coil = self.coils[flipper+'Hold']
			else: 
				self.logger.info("Enabling Stern style flipper")
				style = 'stern'
			switch_num = self.switches[flipper].number

			drivers = []
			if enable:
				if style == 'wpc':
					drivers += [pinproc.driver_state_pulse(main_coil.state(), main_coil.default_pulse_time)]
					drivers += [pinproc.driver_state_pulse(hold_coil.state(), 0)]
				else:
					drivers += [pinproc.driver_state_patter(main_coil.state(), 2, 18, main_coil.default_pulse_time, True)]
			self.proc.switch_update_rule(switch_num, 'closed_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)
			
			drivers = []
			if enable:
				drivers += [pinproc.driver_state_disable(main_coil.state())]
				if style == 'wpc':
					drivers += [pinproc.driver_state_disable(hold_coil.state())]
	
			self.proc.switch_update_rule(switch_num, 'open_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)

			if not enable:
				main_coil.disable()
				if style == 'wpc':
					hold_coil.disable()

		# Enable the flipper relay on wpcAlphanumeric machines
		if self.machine_type == pinproc.MachineTypeWPCAlphanumeric:
			self.enable_alphanumeric_flippers(enable)

		self.enable_bumpers(enable)
	def enable_flippers(self, enable):
		#return True
		
		"""Enables or disables the flippers AND bumpers."""
		for flipper in self.config['PRFlippers']:
			self.logger.info("Programming flipper %s", flipper)
			main_coil = self.coils[flipper+'Main']
			if self.coils.has_key(flipper+'Hold'): 
				style = 'wpc'
				self.logger.info("Enabling WPC style flipper")
				hold_coil = self.coils[flipper+'Hold']
			else: 
				self.logger.info("Enabling Stern style flipper")
				style = 'stern'
			switch_num = self.switches[flipper].number

			drivers = []
			if enable:
				if style == 'wpc':
					drivers += [pinproc.driver_state_pulse(main_coil.state(), main_coil.default_pulse_time)]
					drivers += [pinproc.driver_state_pulse(hold_coil.state(), 0)]
				else:
					drivers += [pinproc.driver_state_patter(main_coil.state(), 2, 18, main_coil.default_pulse_time, True)]
			self.proc.switch_update_rule(switch_num, 'closed_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)
			
			drivers = []
			if enable:
				drivers += [pinproc.driver_state_disable(main_coil.state())]
				if style == 'wpc':
					drivers += [pinproc.driver_state_disable(hold_coil.state())]
	
			self.proc.switch_update_rule(switch_num, 'open_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)

			if not enable:
				main_coil.disable()
				if style == 'wpc':
					hold_coil.disable()

		# Enable the flipper relay on wpcAlphanumeric machines
		if self.machine_type == pinproc.MachineTypeWPCAlphanumeric:
			self.enable_alphanumeric_flippers(enable)

		self.enable_bumpers(enable)
示例#6
0
    def configure_flipper(self, switch_number_str: str, coil_main_number_str: str, coil_hold_number_str: str, pulse_ms: int):
        """Configure flippers."""
        switch_number = self._parse_switch_number(switch_number_str)
        coil_main_number = self._parse_coil_number(coil_main_number_str)
        coil_hold_number = self._parse_coil_number(coil_hold_number_str)
        rules = [pinproc.driver_state_pulse(self.proc.driver_get_state(coil_main_number), pulse_ms),
                 pinproc.driver_state_pulse(self.proc.driver_get_state(coil_hold_number), 0)]
        self.proc.switch_update_rule(switch_number, "closed_nondebounced", {'notifyHost': False, 'reloadActive': False}, rules)

        rules = [pinproc.driver_state_disable(self.proc.driver_get_state(coil_hold_number))]
        self.proc.switch_update_rule(switch_number, "open_nondebounced", {'notifyHost': False, 'reloadActive': False}, rules)
示例#7
0
 def install_switch_rule_coil_disable(self,
                                      switch_num,
                                      switch_state,
                                      coil_name,
                                      notify_host,
                                      enable,
                                      reload_active=False,
                                      drive_coil_now_if_valid=False):
     coil = self.coils[coil_name]
     drivers = []
     if enable:
         drivers += [pinproc.driver_state_disable(coil.state())]
     self.proc.switch_update_rule(switch_num, switch_state, {
         'notifyHost': notify_host,
         'reloadActive': reload_active
     }, drivers, drive_coil_now_if_valid)
	def install_switch_rule_coil_disable(self, switch_num, switch_state, coil_name, notify_host, enable, reload_active = False, drive_coil_now_if_valid=False):
		coil = self.coils[coil_name];
		drivers = []
		if enable:
			drivers += [pinproc.driver_state_disable(coil.state())]
		self.proc.switch_update_rule(switch_num, switch_state, {'notifyHost':notify_host, 'reloadActive':reload_active}, drivers, drive_coil_now_if_valid)
示例#9
0
    def enable_flippers(self, enable):
        """Enables or disables the flippers AND bumpers."""
        self.party_mode = self.user_settings["Machine (Standard)"]["Party Mode"]
        # stern flippers
        for flipper in self.config["PRFlippers"]:
            self.logger.info("Programming flipper %s", flipper)
            # setup flipper coil naming
            main_coil = self.coils[flipper + "Main"]

            # setup opposite flipper coil naming for party modes
            oppflipper = ""
            if flipper.endswith("R"):
                oppflipper = flipper[:-1] + "L"
            elif flipper.endswith("L"):
                oppflipper = flipper[:-1] + "R"
            opposite_coil = self.coils[oppflipper + "Main"]

            switch_num = self.switches[flipper].number

            drivers = []
            if enable:
                if self.party_mode == "No Hold":
                    drivers += [pinproc.driver_state_pulse(main_coil.state(), main_coil.default_pulse_time)]
                elif self.party_mode == "Double Flip":
                    drivers += [
                        pinproc.driver_state_patter(main_coil.state(), 2, 18, main_coil.default_pulse_time, True)
                    ]
                    drivers += [
                        pinproc.driver_state_patter(
                            opposite_coil.state(), 2, 18, opposite_coil.default_pulse_time, True
                        )
                    ]
                elif self.party_mode == "Reversed":
                    drivers += [
                        pinproc.driver_state_patter(opposite_coil.state(), 2, 18, main_coil.default_pulse_time, True)
                    ]
                else:
                    drivers += [
                        pinproc.driver_state_patter(main_coil.state(), 2, 18, main_coil.default_pulse_time, True)
                    ]

            self.proc.switch_update_rule(
                switch_num,
                "closed_nondebounced",
                {"notifyHost": False, "reloadActive": False},
                drivers,
                len(drivers) > 0,
            )

            drivers = []
            if enable:
                if self.party_mode == "Double Flip":
                    drivers += [pinproc.driver_state_disable(main_coil.state())]
                    drivers += [pinproc.driver_state_disable(opposite_coil.state())]
                elif self.party_mode == "Reversed":
                    drivers += [pinproc.driver_state_disable(opposite_coil.state())]
                else:
                    drivers += [pinproc.driver_state_disable(main_coil.state())]

            self.proc.switch_update_rule(
                switch_num, "open_nondebounced", {"notifyHost": False, "reloadActive": False}, drivers, len(drivers) > 0
            )

            if not enable:
                main_coil.disable()

                # bumpers
        self.enable_bumpers(enable)
示例#10
0
文件: p3_roc.py 项目: jherrm/mpf
    def write_hw_rule(
        self,
        sw,
        sw_activity,
        coil_action_ms,  # 0 = disable, -1 = hold forever
        coil=None,
        pulse_ms=0,
        pwm_on=0,
        pwm_off=0,
        delay=0,
        recycle_time=0,
        debounced=True,
        drive_now=False,
    ):

        """Used to write (or update) a hardware rule to the P3-ROC.

        *Hardware Rules* are used to configure the P3-ROC to automatically
        change driver states based on switch changes. These rules are
        completely handled by the P3-ROC hardware (i.e. with no interaction from
        the Python game code). They're used for things that you want to happen
        fast, like firing coils when flipper buttons are pushed, slingshots,
        pop bumpers, etc.

        You can overwrite existing hardware rules at any time to change or
        remove them.

        Args:
            sw : switch object
                Which switch you're creating this rule for. The parameter is a
                reference to the switch object itsef.
            sw_activity : int
                Do you want this coil to fire when the switch becomes active
                (1) or inactive (0)
            coil_action_ms : int
                The total time (in ms) that this coil action should take place.
                A value of -1 means it's forever.
            coil : coil object
                Which coil is this rule controlling
            pulse_ms : int
                How long should the coil be pulsed (ms)
            pwm_on : int
                If the coil should be held on at less than 100% duty cycle,
                this is the "on" time (in ms).
            pwm_off : int
                If the coil should be held on at less than 100% duty cycle,
                this is the "off" time (in ms).
            delay : int
                Not currently implemented for the P3-ROC hardware
            recycle_time : int
                How long (in ms) should this switch rule wait before firing
                again. Put another way, what's the "fastest" this rule can
                fire? This is used to prevent "machine gunning" of slingshots
                and pop bumpers. Do not use it with flippers. Note the P3-ROC
                has a non-configurable delay time of 125ms. (So it's either
                125ms or 0.) So if you set this delay to anything other than
                0, it will be 125ms.
            debounced : bool
                Should the P3-ROC fire this coil after the switch has been
                debounced? Typically no.
            drive_now : bool
                Should the P3-ROC check the state of the switches when this
                rule is firts applied, and fire the coils if they should be?
                Typically this is True, especially with flippers because you
                want them to fire if the player is holding in the buttons when
                the machine enables the flippers (which is done via several
                calls to this method.)

        """

        self.log.debug(
            "Setting HW Rule. Switch:%s, Action ms:%s, Coil:%s, "
            "Pulse:%s, pwm_on:%s, pwm_off:%s, Delay:%s, Recycle:%s,"
            "Debounced:%s, Now:%s",
            sw.name,
            coil_action_ms,
            coil.name,
            pulse_ms,
            pwm_on,
            pwm_off,
            delay,
            recycle_time,
            debounced,
            drive_now,
        )

        if sw_activity == 0 and debounced:
            event_type = "open_debounced"
        elif sw_activity == 0 and not debounced:
            event_type = "open_nondebounced"
        elif sw_activity == 1 and debounced:
            event_type = "closed_debounced"
        else:  # if sw_activity == 1 and not debounced:
            event_type = "closed_nondebounced"

        # Note the P3-ROC uses a 125ms non-configurable recycle time. So any
        # non-zero value passed here will enable the 125ms recycle.

        reload_active = False
        if recycle_time:
            reload_active = True

        # We only want to notify_host for debounced switch events. We use non-
        # debounced for hw_rules since they're faster, but we don't want to
        # notify the host on them since the host would then get two events
        # one for the nondebounced followed by one for the debounced.

        notify_host = False
        if debounced:
            notify_host = True

        rule = {"notifyHost": notify_host, "reloadActive": reload_active}

        # Now let's figure out what type of P3-ROC action we need to take.
        # We're going to 'brtue force' this here because it's the easiest to
        # understand. (Which makes it the most pythonic, right? :)

        proc_action = "disable"

        patter = False  # makes it easier to understand later...
        if pwm_on and pwm_off:
            patter = True

        if coil_action_ms == -1:  # hold coil forever
            if patter:
                proc_action = "patter"
            else:
                proc_action = "enable"
        elif coil_action_ms > 0:  # timed action of some sort
            if coil_action_ms <= pulse_ms:
                proc_action = "pulse"
                pulse_ms = coil_action_ms
            elif patter:
                if pulse_ms:
                    pass
                    # todo error, P3-ROC can't do timed patter with pulse
                else:  # no initial pulse
                    proc_action = "pulsed_patter"

        this_driver = []
        final_driver = []

        # The P3-ROC ties hardware rules to switches, with a list of linked
        # drivers that should change state based on a switch activity.
        # Since our framework applies the rules one-at-a-time, we have to read
        # the existing linked drivers from the hardware for that switch, add
        # our new driver to the list, then re-update the rule on the hardware.

        if proc_action == "pulse":
            this_driver = [pinproc.driver_state_pulse(coil.hw_driver.state(), pulse_ms)]

        elif proc_action == "patter":
            this_driver = [pinproc.driver_state_patter(coil.hw_driver.state(), pwm_on, pwm_off, pulse_ms, True)]
            # todo above param True should not be there. Change to now?

        elif proc_action == "enable":
            this_driver = [pinproc.driver_state_pulse(coil.hw_driver.state(), 0)]

        elif proc_action == "disable":
            this_driver = [pinproc.driver_state_disable(coil.hw_driver.state())]

        elif proc_action == "pulsed_patter":
            this_driver = [pinproc.driver_state_pulsed_patter(coil.hw_driver.state(), pwm_on, pwm_off, coil_action_ms)]

        # merge in any previously-configured driver rules for this switch

        final_driver = list(this_driver)  # need to make an actual copy
        sw_rule_string = str(sw.name) + str(event_type)
        if sw_rule_string in self.hw_switch_rules:
            for driver in self.hw_switch_rules[sw_rule_string]:
                final_driver.append(driver)
            self.hw_switch_rules[sw_rule_string].extend(this_driver)
        else:
            self.hw_switch_rules[sw_rule_string] = this_driver

        self.log.debug(
            "Writing HW rule for switch: %s, event_type: %s," "rule: %s, final_driver: %s, drive now: %s",
            sw.number,
            event_type,
            rule,
            final_driver,
            drive_now,
        )
        self.proc.switch_update_rule(sw.number, event_type, rule, final_driver, drive_now)
示例#11
0
	def enable_flippers(self, enable):
		#return True
		"""Enables or disables the flippers AND bumpers."""
		if self.machine_type == pinproc.MachineTypeWPC or self.machine_type == pinproc.MachineTypeWPC95 or self.machine_type == pinproc.MachineTypeWPCAlphanumeric:
			for flipper in self.config['PRFlippers']:
				self.logger.info("Programming flipper %s", flipper)
				main_coil = self.coils[flipper+'Main']
				hold_coil = self.coils[flipper+'Hold']
				switch_num = self.switches[flipper].number

				# Chck to see if the flipper should be activated now.
				#if enable:
				#	if self.switches[flipper].is_active():
				#		self.coils[flipper+'Main'].pulse(34)
				#		self.coils[flipper+'Hold'].pulse(0)
				#	else: self.coils[flipper+'Hold'].disable()
				#else: self.coils[flipper+'Hold'].disable()

				drivers = []
				if enable:
					drivers += [pinproc.driver_state_pulse(main_coil.state(), 34)]
					drivers += [pinproc.driver_state_pulse(hold_coil.state(), 0)]
				self.proc.switch_update_rule(switch_num, 'closed_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)
			
				drivers = []
				if enable:
					drivers += [pinproc.driver_state_disable(main_coil.state())]
					drivers += [pinproc.driver_state_disable(hold_coil.state())]
	
				self.proc.switch_update_rule(switch_num, 'open_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)

				if not enable:
					main_coil.disable()
					hold_coil.disable()

			# Enable the flipper relay on wpcAlphanumeric machines
                        if self.machine_type == pinproc.MachineTypeWPCAlphanumeric:
				# 79 corresponds to the circuit on the power/driver board.  It will be 79 for all WPCAlphanumeric machines.
				flipperRelayPRNumber = 79
                                if enable:
                                        self.coils[79].pulse(0)
                                else:
                                        self.coils[79].disable()
                elif self.machine_type == pinproc.MachineTypeSternWhitestar or self.machine_type == pinproc.MachineTypeSternSAM:
			for flipper in self.config['PRFlippers']:
				print("  programming flipper %s" % (flipper))
				main_coil = self.coils[flipper+'Main']
				switch_num = pinproc.decode(self.machine_type, str(self.switches[flipper].number))

				# Check to see if the flipper should be activated now.
				#if enable:
				#	if self.switches[flipper].is_active():
				#		self.coils[flipper+'Main'].patter(3, 22, 34)
				#	else: self.coils[flipper+'Main'].disable()
				#else: self.coils[flipper+'Main'].disable()

				drivers = []
				if enable:
					drivers += [pinproc.driver_state_patter(main_coil.state(), 2, 18, 34)]
	
				self.proc.switch_update_rule(switch_num, 'closed_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)
			
				drivers = []
				if enable:
					drivers += [pinproc.driver_state_disable(main_coil.state())]
	
				self.proc.switch_update_rule(switch_num, 'open_nondebounced', {'notifyHost':False, 'reloadActive':False}, drivers, len(drivers) > 0)

				if not enable:
					main_coil.disable()
	
		for bumper in self.config['PRBumpers']:
			switch_num = self.switches[bumper].number
			coil = self.coils[bumper]

			drivers = []
			if enable:
				drivers += [pinproc.driver_state_pulse(coil.state(), 20)]

			self.proc.switch_update_rule(switch_num, 'closed_nondebounced', {'notifyHost':False, 'reloadActive':True}, drivers, False)