Skip to content
Permalink
Browse files

more logging for P/P3-Roc calls to libpinproc

  • Loading branch information...
jabdoa2 committed Aug 30, 2019
1 parent 858eb20 commit 163e769fa63bc745ffecce1497458942339212e6
Showing with 72 additions and 81 deletions.
  1. +2 −0 mpf/platforms/p_roc_common.py
  2. +70 −81 mpf/tests/test_P_Roc.py
@@ -199,6 +199,8 @@ def _decrement_running_commands(self, future):

def run_proc_cmd(self, cmd, *args):
"""Run a command in the p-roc thread and return a future."""
if self.debug:
self.debug_log("Calling P-Roc cmd: %s (%s)", cmd, args)
future = asyncio.wrap_future(
asyncio.run_coroutine_threadsafe(self.proc_process.run_command(cmd, *args), self.proc_process_instance),
loop=self.machine.clock.loop)
@@ -125,6 +125,39 @@ def _mock_loop(self):
super()._mock_loop()
self.loop._wait_for_external_executor = True

def _driver_state_pulse(self, driver, milliseconds):
driver["state"] = 1
driver["timeslots"] = 0
driver["waitForFirstTimeSlot"] = False
driver["outputDriveTime"] = milliseconds
driver["patterOnTime"] = 0
driver["patterOffTime"] = 0
driver["patterEnable"] = False
driver["futureEnable"] = False
return driver

def _driver_state_disable(self, driver):
driver["state"] = 0
driver["timeslots"] = 0
driver["waitForFirstTimeSlot"] = False
driver["outputDriveTime"] = 0
driver["patterOnTime"] = 0
driver["patterOffTime"] = 0
driver["patterEnable"] = False
driver["futureEnable"] = False
return driver

def _driver_state_patter(self, driver, millisecondsOn, millisecondsOff, originalOnTime, now):
driver["state"] = True
driver["timeslots"] = 0
driver["waitForFirstTimeSlot"] = not now
driver["outputDriveTime"] = originalOnTime
driver["patterOnTime"] = millisecondsOn
driver["patterOffTime"] = millisecondsOff
driver["patterEnable"] = True
driver["futureEnable"] = False
return driver

def setUp(self):
if sys.version_info[0] == 3 and sys.version_info[1] == 4:
# this fails on python 3.4 because of some asyncio bugs
@@ -157,53 +190,13 @@ def setUp(self):
self.pinproc.dmd_update_config = MagicMock(return_value=True)
p_roc_common.pinproc.PinPROC = MagicMock(return_value=self.pinproc)
p_roc_common.pinproc.normalize_machine_type = self._normalize
p_roc_common.pinproc.driver_state_pulse = MagicMock(
return_value={'driverNum': 8,
'outputDriveTime': 0,
'polarity': True,
'state': False,
'waitForFirstTimeSlot': False,
'timeslots': 0,
'patterOnTime': 0,
'patterOffTime': 0,
'patterEnable': False,
'futureEnable': False})

p_roc_common.pinproc.driver_state_pulsed_patter = MagicMock(
return_value={'driverNum': 9,
'outputDriveTime': 0,
'polarity': True,
'state': False,
'waitForFirstTimeSlot': False,
'timeslots': 0,
'patterOnTime': 0,
'patterOffTime': 0,
'patterEnable': False,
'futureEnable': False})

p_roc_common.pinproc.driver_state_disable = MagicMock(
return_value={'driverNum': 10,
'outputDriveTime': 0,
'polarity': True,
'state': False,
'waitForFirstTimeSlot': False,
'timeslots': 0,
'patterOnTime': 0,
'patterOffTime': 0,
'patterEnable': False,
'futureEnable': False})

p_roc_common.pinproc.driver_state_patter = MagicMock(
return_value={'driverNum': 11,
'outputDriveTime': 0,
'polarity': True,
'state': False,
'waitForFirstTimeSlot': False,
'timeslots': 0,
'patterOnTime': 0,
'patterOffTime': 0,
'patterEnable': False,
'futureEnable': False})
p_roc_common.pinproc.driver_state_pulse = self._driver_state_pulse

p_roc_common.pinproc.driver_state_pulsed_patter = None

p_roc_common.pinproc.driver_state_disable = self._driver_state_disable

p_roc_common.pinproc.driver_state_patter = self._driver_state_patter

self.pinproc.switch_get_states = MagicMock(return_value=[0, 1] + [0] * 100)
self.pinproc.read_data = self.read_data
@@ -239,20 +232,20 @@ def test_platform(self):
self.assertEqual(info_str, self.machine.default_platform.get_info_string())

def _test_pulse_and_hold(self):
self.assertEqual("PD-16 Board 1 Bank 1", self.machine.coils.c_test.hw_driver.get_board_name())
self.assertEqual("PD-16 Board 1 Bank 1", self.machine.coils["c_test"].hw_driver.get_board_name())
# pulse coil A1-B1-2
self.machine.coils.c_test.pulse()
self.machine.coils["c_test"].pulse()
self.wait_for_platform()
# A1-B1-2 -> address 16 + 8 + 2 = 26 in P3-Roc
# for 23ms (from config)
number = self.machine.coils.c_test.hw_driver.number
number = self.machine.coils["c_test"].hw_driver.number
self.pinproc.driver_pulse.assert_called_with(
number, 23)
assert not self.pinproc.driver_schedule.called

def _test_alpha_display(self):
self.pinproc.aux_send_commands = MagicMock(return_value=True)
self.machine.segment_displays.display1.add_text("1234", key="score")
self.machine.segment_displays["display1"].add_text("1234", key="score")
self.advance_time_and_run(.1)
self.wait_for_platform()
self.pinproc.aux_send_commands.assert_has_calls([
@@ -261,7 +254,7 @@ def _test_alpha_display(self):
], any_order=False)

self.pinproc.aux_send_commands = MagicMock(return_value=True)
self.machine.segment_displays.display1.remove_text_by_key("score")
self.machine.segment_displays["display1"].remove_text_by_key("score")
self.advance_time_and_run(.1)
self.wait_for_platform()
self.pinproc.aux_send_commands.assert_has_calls([
@@ -272,33 +265,30 @@ def _test_alpha_display(self):
def _test_enable_exception(self):
# enable coil which does not have allow_enable
with self.assertRaises(AssertionError):
self.machine.coils.c_test.enable()
self.machine.coils["c_test"].enable()

def _test_allow_enable(self):
self.machine.coils.c_test_allow_enable.enable()
self.machine.coils["c_test_allow_enable"].enable()
self.wait_for_platform()
number = self.machine.coils.c_test_allow_enable.hw_driver.number
number = self.machine.coils["c_test_allow_enable"].hw_driver.number
self.pinproc.driver_schedule.assert_called_with(
number, 0xffffffff, 0, True)

def _test_hw_rule_pulse(self):
self.machine.coils.c_slingshot_test.hw_driver.state = MagicMock(return_value=8)
self.machine.autofires.ac_slingshot_test.enable()
self.wait_for_platform()
self.pinproc.switch_update_rule.assert_any_call(
40, 'closed_nondebounced',
{'notifyHost': False, 'reloadActive': True},
[{'patterEnable': False,
'patterOnTime': 0,
'timeslots': 0,
'futureEnable': False,
'state': False,
'patterOffTime': 0,
'outputDriveTime': 0,
'driverNum': 8,
'polarity': True,
'waitForFirstTimeSlot': False}], False)
self.machine.autofires.ac_slingshot_test.disable()
self.pinproc.switch_update_rule = MagicMock()
self.machine.autofires["ac_slingshot_test"].enable()
self.wait_for_platform()
coil_number = self.machine.coils["c_slingshot_test"].hw_driver.number
self.pinproc.switch_update_rule.assert_has_calls([
call(40, 'open_nondebounced', {'notifyHost': False, 'reloadActive': True}, [], False),
call(40, 'closed_nondebounced', {'notifyHost': False, 'reloadActive': True},
[{'futureEnable': False, 'patterOffTime': 0, 'polarity': True, 'waitForFirstTimeSlot': False,
'timeslots': 0, 'patterOnTime': 0, 'outputDriveTime': 10, 'patterEnable': False, 'state': 1,
'driverNum': coil_number}], False),
call(40, 'open_debounced', {'notifyHost': True, 'reloadActive': True}, [], False),
call(40, 'closed_debounced', {'notifyHost': True, 'reloadActive': True}, [], False),
], any_order=True)
self.machine.autofires["ac_slingshot_test"].disable()

def _test_initial_switches(self):
self.assertMachineVarEqual(2, "p_roc_version")
@@ -360,7 +350,6 @@ def _test_switches(self):
self.assertFalse(self.machine.switch_controller.is_active("s_test_no_debounce"))

def _test_dmd_update(self):

self.machine.default_platform.pinproc.DMDBuffer = MockDMD
self.pinproc.dmd_draw = MagicMock(return_value=True)

@@ -412,14 +401,14 @@ def _test_pdb_matrix_light(self):
# test enable of matrix light
assert not self.pinproc.driver_patter.called
assert not self.pinproc.driver_schedule.called
self.machine.lights.test_pdb_light.on()
self.machine.lights["test_pdb_light"].on()
self.advance_time_and_run(.02)
self.wait_for_platform()
self.pinproc.driver_schedule.assert_called_with(
32, 4294967295, 0, True
)

self.machine.lights.test_pdb_light.on(brightness=128)
self.machine.lights["test_pdb_light"].on(brightness=128)
self.advance_time_and_run(.02)
self.wait_for_platform()
self.pinproc.driver_patter.assert_called_with(
@@ -428,7 +417,7 @@ def _test_pdb_matrix_light(self):

# test disable of matrix light
assert not self.pinproc.driver_disable.called
self.machine.lights.test_pdb_light.off()
self.machine.lights["test_pdb_light"].off()
self.advance_time_and_run(.1)
self.wait_for_platform()
self.pinproc.driver_disable.assert_called_with(32)
@@ -468,8 +457,8 @@ def _test_pdb_matrix_light(self):

def _test_pdb_gi_light(self):
# test gi on
device = self.machine.lights.test_gi
num = self.machine.coils.test_gi.hw_driver.number
device = self.machine.lights["test_gi"]
num = self.machine.coils["test_gi"].hw_driver.number
self.pinproc.driver_patter = MagicMock(return_value=True)
self.pinproc.driver_schedule = MagicMock(return_value=True)
device.color("white")
@@ -513,7 +502,7 @@ def test_load_wpc(self):
def test_load_snux(self):
"""Test snux."""
# test enable
self.machine.coils.c_flipper_enable_driver.enable()
self.machine.coils["c_flipper_enable_driver"].enable()
self.wait_for_platform()
self.pinproc.driver_schedule.assert_called_with(
9923, 0xffffffff, 0, True)
@@ -530,9 +519,9 @@ def test_load_snux(self):
# pulse a and c side
self.pinproc.driver_schedule = MagicMock(return_value=True)
self.pinproc.driver_pulse = MagicMock(return_value=True)
self.machine.coils.c_test_a_side.pulse(100)
self.machine.coils["c_test_a_side"].pulse(100)
self.advance_time_and_run(.001)
self.machine.coils.c_test_c_side.pulse(50)
self.machine.coils["c_test_c_side"].pulse(50)
self.advance_time_and_run(.040)
self.wait_for_platform()
self.advance_time_and_run(.001)

0 comments on commit 163e769

Please sign in to comment.
You can’t perform that action at this time.