Skip to content

Commit

Permalink
FAST: allow NC switches for cancel switches, v0.57.0.dev20
Browse files Browse the repository at this point in the history
fixes #1717
  • Loading branch information
toomanybrians committed Oct 13, 2023
1 parent 27381c8 commit 4cd47e8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
2 changes: 1 addition & 1 deletion mpf/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"""

__version__ = '0.57.0.dev19' # Also consider whether MPF-MC pyproject.toml should be updated
__version__ = '0.57.0.dev20' # Also consider whether MPF-MC pyproject.toml should be updated
'''The full version of MPF.'''

__short_version__ = '0.57'
Expand Down
8 changes: 8 additions & 0 deletions mpf/platforms/fast/fast_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,14 @@ def set_hardware_rule(self, mode, switch, coil_settings, **kwargs):
if switch.invert:
trigger = self.set_bit(trigger, 4)

# If this driver mode has an off switch, we need to check to see if it's inverted
# and then update the trigger to act on inverted too. Since the off switch object
# does not exist here, we need to go find it.
if new_settings.get('off_switch', None):
off_switch = self.communicator.switches[int(new_settings['off_switch'], 16)]
if off_switch.baseline_switch_config.mode == '02': # inverted
trigger = self.set_bit(trigger, 5)

if self.is_new_config_needed(self.current_driver_config.trigger, trigger):
reconfigured = True
elif trigger != self.current_driver_config.trigger:
Expand Down
22 changes: 20 additions & 2 deletions mpf/tests/machine_files/fast/config/neuron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ switches:
number: io3208-2 # 0x02
s_flipper_opto: # Starts active via SA:
number: io3208-3 # 0x03
type: 'NC'
type: NC
s_autofire_3208:
number: io3208-4 # 0x04
s_autofire_1616:
number: io1616-0 # 0x28
s_test_nc: # Starts active via SA:
number: io3208-5 # 0x05
type: 'NC'
type: NC
s_debounce_auto:
number: io3208-6 # 0x06
debounce: auto
Expand All @@ -58,6 +58,11 @@ switches:
platform_settings:
debounce_open: 26 # 0x1A
debounce_close: 5 # 0x05
s_flipper3:
number: io3208-10 # 0x0A
s_flipper3_eos_nc:
number: io3208-11 # 0x0B
type: NC
s_cab_flipper:
number: cab-0 # 0x38

Expand Down Expand Up @@ -122,6 +127,12 @@ coils:
c_flipper2_hold:
number: io1616-7 # 0x13
allow_enable: true
c_flipper3_main:
number: io1616-8 # 0x14
default_pulse_ms: 17 # 0x11
c_flipper3_hold:
number: io1616-9 # 0x15
allow_enable: true

autofire_coils:
ac_baseline:
Expand Down Expand Up @@ -154,6 +165,13 @@ flippers:
eos_switch: s_flipper_eos
use_eos: true

f_eos_nc:
main_coil: c_flipper3_main
hold_coil: c_flipper3_hold
activation_switch: s_flipper3
eos_switch: s_flipper3_eos_nc
use_eos: true

playfields:
playfield:
tags: default
Expand Down
36 changes: 29 additions & 7 deletions mpf/tests/test_Fast_Neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def create_expected_commands(self):
"SL:07,01,02,02": "SL:P",
"SL:08,01,04,04": "SL:P",
"SL:09,01,05,1A": "SL:P",
"SL:0A,00,00,00": "SL:P",
"SL:0B,00,00,00": "SL:P",
"SL:0A,01,04,04": "SL:P",
"SL:0B,02,04,04": "SL:P",
"SL:0C,00,00,00": "SL:P",
"SL:0D,00,00,00": "SL:P",
"SL:0E,00,00,00": "SL:P",
Expand Down Expand Up @@ -149,6 +149,8 @@ def create_expected_commands(self):
"DL:11,81,00,10,0A,FF,00,00,00": "DL:P",
"DL:12,81,00,10,0F,FF,00,00,00": "DL:P",
"DL:13,81,00,10,0A,FF,00,FF,00": "DL:P",
"DL:14,81,00,10,11,FF,00,00,00": "DL:P",
"DL:15,81,00,10,0A,FF,00,FF,00": "DL:P",
}

self.net_cpu .expected_commands.update(net_commands_from_this_config)
Expand Down Expand Up @@ -556,7 +558,7 @@ def _test_receiving_sa(self):
self.advance_time_and_run()
self.assertSwitchState("s_debounce_custom", 1)

def test_test_flipper_single_coil(self):
def test_test_flipper_single_coil_with_opto_switch(self):
coil = self.machine.coils["c_flipper_single_wound"]
hw_driver = coil.hw_driver
switch = self.machine.switches["s_flipper_opto"].hw_switch
Expand Down Expand Up @@ -661,6 +663,26 @@ def test_test_flipper_two_coils_with_eos(self):
flipper.enable()
self.confirm_commands()

def test_test_flipper_two_coils_with_nc_eos(self):
main_coil = self.machine.coils["c_flipper3_main"]
hold_coil = self.machine.coils["c_flipper3_hold"]
main_hw_driver = main_coil.hw_driver
hold_hw_driver = hold_coil.hw_driver
switch = self.machine.switches["s_flipper3"].hw_switch
eos_switch = self.machine.switches["s_flipper3_eos_nc"].hw_switch
flipper = self.machine.flippers["f_eos_nc"]

self.assertEqual(main_hw_driver.get_current_config(), 'DL:14,81,00,10,11,FF,00,00,00')
self.assertEqual(hold_hw_driver.get_current_config(), 'DL:15,81,00,10,0A,FF,00,FF,00')
self.assertEqual(switch.get_current_config(), 'SL:0A,01,04,04')

# flipper rule enable
# Trigger 21 (bit 0 enable, bit 4 invert second switch), Mode 75 (pulse+hold w/cancel), EOS switch 38
self.net_cpu .expected_commands = {"DL:14,21,0A,75,0B,11,00,00,00": "DL:P",
"DL:15,01,0A,18,0A,FF,FF,00,00": "DL:P",}
flipper.enable()
self.confirm_commands()

def test_machine_reset(self):

# Set the commands that will respond to the query on reset. Some of these are
Expand All @@ -677,8 +699,8 @@ def test_machine_reset(self):
"SL:07": "SL:07,01,02,02",
"SL:08": "SL:08,01,04,04",
"SL:09": "SL:09,01,05,1A",
"SL:0A": "SL:0A,00,00,00",
"SL:0B": "SL:0B,00,00,00",
"SL:0A": "SL:0A,01,04,04",
"SL:0B": "SL:0B,02,04,04",
"SL:0C": "SL:0C,00,00,00",
"SL:0D": "SL:0D,00,00,00",
"SL:0E": "SL:0E,02,00,00",
Expand Down Expand Up @@ -798,8 +820,8 @@ def test_machine_reset(self):
"DL:11": "DL:11,81,00,10,0A,FF,00,00,00",
"DL:12": "DL:12,81,00,10,0F,FF,00,00,00",
"DL:13": "DL:13,81,00,10,0A,FF,00,FF,00",
"DL:14": "DL:14,00,00,00,00,00,00,00,00",
"DL:15": "DL:15,00,00,00,00,00,00,00,00",
"DL:14": "DL:14,81,00,10,11,FF,00,00,00",
"DL:15": "DL:15,81,00,10,0A,FF,00,FF,00",
"DL:16": "DL:16,00,00,00,00,00,00,00,00",
"DL:17": "DL:17,00,00,00,00,00,00,00,00",
"DL:18": "DL:18,00,00,00,00,00,00,00,00",
Expand Down

0 comments on commit 4cd47e8

Please sign in to comment.