Skip to content

Commit

Permalink
Merge branch 'dev' into 0.80.x
Browse files Browse the repository at this point in the history
  • Loading branch information
avanwinkle committed Oct 12, 2024
2 parents 2884054 + 172b5d9 commit 0e9f6ed
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
2 changes: 1 addition & 1 deletion mpf/platforms/fast/communicators/net_neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def update_switches_from_hw_data(self):
This will silently sync the switch.hw_state. If the logical state changes,
it will process it like any switch change.
"""
for switch in self.machine.switches.values():
for switch in [sw for sw in self.machine.switches.values() if sw.platform == self.platform]:
hw_state = self.platform.hw_switch_data[switch.hw_switch.number]

if hw_state != switch.hw_state:
Expand Down
10 changes: 9 additions & 1 deletion mpf/tests/machine_files/fast/config/neuron.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ mpf:
report_crashes: never

hardware:
platform: fast
platform: smart_virtual
coils: fast
dmd: fast
lights: fast
switches: fast

machine: # Needed for the game testing
min_balls: 0
Expand All @@ -30,6 +34,10 @@ fast:
order: 4

switches:
s_mixed_platform_example:
number: 999
platform: smart_virtual

s_baseline: # Starts active via SA:
number: io3208-0 # 0x00
s_flipper:
Expand Down
47 changes: 30 additions & 17 deletions mpf/tests/test_Fast_Neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ def create_expected_commands(self):

self.net_cpu.expected_commands.update(net_commands_from_this_config)

def fast_platform(self):
return self.machine.hardware_platforms['fast']

def fast_net_serial(self):
return self.fast_platform().serial_connections['net']

def test_coils(self):
# The default expected commands will verify all the coils are configured properly.
# We just need to ensure things get enabled properly.
Expand All @@ -179,7 +185,7 @@ def test_coils(self):
'Board 3 - Model: FP-I/O-0024, Firmware: 01.10, Switches: 24, Drivers: 8\n'
)

self.assertEqual(info_str, self.machine.default_platform.get_info_string())
self.assertEqual(info_str, self.machine.hardware_platforms['fast'].get_info_string())

def _test_pulse(self):

Expand Down Expand Up @@ -477,20 +483,26 @@ def test_switches(self):
self._test_switch_changes()
self._test_switch_changes_nc()
self._test_receiving_sa()
self._test_cross_platform_switches()

def _test_cross_platform_switches(self):
self.assertSwitchState("s_mixed_platform_example", 0)
self.assertEqual(self.machine.switches["s_mixed_platform_example"].platform, self.machine.hardware_platforms['smart_virtual'])

def _test_startup_switches(self):
self.assertEqual(self.machine.switches["s_baseline"].platform, self.fast_platform())
self.assertSwitchState("s_baseline", 1)
self.assertSwitchState("s_flipper", 0)
self.assertSwitchState("s_test_nc", 0) # NC which SA reports active should be inactive

def _test_bad_switch_configs(self):
# invalid switch
with self.assertRaises(AssertionError):
self.machine.default_platform.configure_switch('io3208-32', SwitchConfig(name="", debounce='auto', invert=0), {})
self.machine.hardware_platforms['fast'].configure_switch('io3208-32', SwitchConfig(name="", debounce='auto', invert=0), {})

# invalid board
with self.assertRaises(AssertionError):
self.machine.default_platform.configure_switch('brian-0', SwitchConfig(name="", debounce='auto', invert=0), {})
self.machine.hardware_platforms['fast'].configure_switch('brian-0', SwitchConfig(name="", debounce='auto', invert=0), {})

def _test_switch_changes(self):
self.assertSwitchState("s_flipper", 0)
Expand All @@ -501,7 +513,7 @@ def _test_switch_changes(self):
self.assertFalse(self.switch_hit)

self.machine.events.add_handler("s_flipper_eos_active", self._switch_hit_cb)
self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"-L:02\r")
self.fast_net_serial().parse_incoming_raw_bytes(b"-L:02\r")
self.advance_time_and_run(1)

self.assertTrue(self.switch_hit)
Expand All @@ -512,7 +524,7 @@ def _test_switch_changes(self):
self.assertFalse(self.switch_hit)
self.assertSwitchState("s_flipper_eos", 1)

self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"/L:02\r")
self.fast_net_serial().parse_incoming_raw_bytes(b"/L:02\r")
self.advance_time_and_run(1)
self.assertFalse(self.switch_hit)
self.assertSwitchState("s_flipper_eos", 0)
Expand All @@ -523,13 +535,13 @@ def _test_switch_changes_nc(self):
self.assertSwitchState("s_test_nc", 0)
self.assertFalse(self.switch_hit)

self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"-L:05\r")
self.fast_net_serial().parse_incoming_raw_bytes(b"-L:05\r")
self.advance_time_and_run(1)
self.assertFalse(self.switch_hit)
self.assertSwitchState("s_test_nc", 1)

self.machine.events.add_handler("s_test_nc_inactive", self._switch_hit_cb)
self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"/L:05\r")
self.fast_net_serial().parse_incoming_raw_bytes(b"/L:05\r")
self.advance_time_and_run(1)

self.assertSwitchState("s_test_nc", 0)
Expand All @@ -547,15 +559,15 @@ def _test_receiving_sa(self):
self.assertSwitchState("s_cab_flipper", 0)

# Send an SA:
self.loop.run_until_complete(self.machine.default_platform.get_hw_switch_states(True))
self.loop.run_until_complete(self.fast_platform().get_hw_switch_states(True))
self.advance_time_and_run()

self.assertSwitchState("s_cab_flipper", 1)

# Process a random SA coming in (this shouldn't happen but should work in non async mode)
# Switch 0x09 is also now active
self.assertSwitchState("s_debounce_custom", 0)
self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"SA:0E,2902000000000001000000000000\r")
self.fast_net_serial().parse_incoming_raw_bytes(b"SA:0E,2902000000000001000000000000\r")
self.advance_time_and_run()
self.assertSwitchState("s_debounce_custom", 1)

Expand Down Expand Up @@ -884,30 +896,31 @@ def test_fast_game(self):
self.advance_time_and_run()
self.assertIsNotNone(self.machine.game)

net_serial = self.fast_net_serial()
# hit the flipper and to simulate the EOS and everything
# and earlier bug caused it to disable the flipper which is why we test this now
self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"-L:0A\r") # flipper
net_serial.parse_incoming_raw_bytes(b"-L:0A\r") # flipper
self.advance_time_and_run(0.015)
self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"-L:0B\r") # eos
net_serial.parse_incoming_raw_bytes(b"-L:0B\r") # eos
self.advance_time_and_run(3)

# release both
self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"/L:0A\r") # flipper
net_serial.parse_incoming_raw_bytes(b"/L:0A\r") # flipper
self.advance_time_and_run(0.001)
self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"/L:0B\r")
net_serial.parse_incoming_raw_bytes(b"/L:0B\r")
self.advance_time_and_run(3)

# ---

self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"-L:0A\r") # flipper
net_serial.parse_incoming_raw_bytes(b"-L:0A\r") # flipper
self.advance_time_and_run(0.016)
self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"-L:0B\r") # eos
net_serial.parse_incoming_raw_bytes(b"-L:0B\r") # eos
self.advance_time_and_run(0.100)

# release both
self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"/L:0A\r") # flipper
net_serial.parse_incoming_raw_bytes(b"/L:0A\r") # flipper
self.advance_time_and_run(0.100)
self.machine.default_platform.serial_connections['net'].parse_incoming_raw_bytes(b"/L:0B\r")
net_serial.parse_incoming_raw_bytes(b"/L:0B\r")
self.advance_time_and_run(3)

# end game
Expand Down

0 comments on commit 0e9f6ed

Please sign in to comment.