本文整理汇总了Python中gpiozero.pins.mock.MockPin类的典型用法代码示例。如果您正苦于以下问题:Python MockPin类的具体用法?Python MockPin怎么用?Python MockPin使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MockPin类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_output_blink_interrupt_on
def test_output_blink_interrupt_on():
pin = MockPin(2)
device = DigitalOutputDevice(pin)
device.blink(1, 0.1)
sleep(0.2)
device.off() # should interrupt while on
pin.assert_states([False, True, False])
示例2: test_input_is_active
def test_input_is_active():
pin = MockPin(2)
with InputDevice(pin, pull_up=True) as device:
pin.drive_high()
assert not device.is_active
pin.drive_low()
assert device.is_active
示例3: test_output_blink_interrupt_off
def test_output_blink_interrupt_off():
pin = MockPin(2)
with DigitalOutputDevice(pin) as device:
device.blink(0.1, 1)
sleep(0.2)
device.off() # should interrupt while off
pin.assert_states([False, True, False])
示例4: test_input_event_activated
def test_input_event_activated():
event = Event()
pin = MockPin(2)
with DigitalInputDevice(pin) as device:
device.when_activated = lambda: event.set()
assert not event.is_set()
pin.drive_high()
assert event.is_set()
示例5: test_mock_pin_pull
def test_mock_pin_pull():
pin = MockPin(4)
pin.function = 'input'
assert pin.pull == 'floating'
pin.pull = 'up'
assert pin.state
pin.pull = 'down'
assert not pin.state
示例6: test_mock_pin_pull
def test_mock_pin_pull():
pin = MockPin(2)
pin.function = "input"
assert pin.pull == "floating"
pin.pull = "up"
assert pin.state
pin.pull = "down"
assert not pin.state
示例7: test_input_line_sensor
def test_input_line_sensor():
pin = MockPin(2)
with LineSensor(pin) as sensor:
pin.drive_low() # logic is inverted for line sensor
assert sensor.wait_for_line(1)
assert sensor.line_detected
pin.drive_high()
assert sensor.wait_for_no_line(1)
assert not sensor.line_detected
示例8: test_input_motion_sensor
def test_input_motion_sensor():
pin = MockPin(2)
with MotionSensor(pin) as sensor:
pin.drive_high()
assert sensor.wait_for_motion(1)
assert sensor.motion_detected
pin.drive_low()
assert sensor.wait_for_no_motion(1)
assert not sensor.motion_detected
示例9: test_input_is_active_high
def test_input_is_active_high():
pin = MockPin(2)
with InputDevice(pin, pull_up=False) as device:
pin.drive_high()
assert device.is_active
assert repr(device) == '<gpiozero.InputDevice object on pin MOCK2, pull_up=False, is_active=True>'
pin.drive_low()
assert not device.is_active
assert repr(device) == '<gpiozero.InputDevice object on pin MOCK2, pull_up=False, is_active=False>'
示例10: test_input_smoothed_values
def test_input_smoothed_values():
pin = MockPin(2)
with SmoothedInputDevice(pin) as device:
device._queue.start()
assert not device.is_active
pin.drive_high()
assert device.wait_for_active(1)
pin.drive_low()
assert device.wait_for_inactive(1)
示例11: test_input_button
def test_input_button():
pin = MockPin(2)
with Button(pin) as button:
assert pin.pull == 'up'
assert not button.is_pressed
pin.drive_low()
assert button.is_pressed
assert button.wait_for_press(1)
pin.drive_high()
assert not button.is_pressed
assert button.wait_for_release(1)
示例12: test_output_blink_foreground
def test_output_blink_foreground():
pin = MockPin(2)
device = DigitalOutputDevice(pin)
device.blink(0.1, 0.1, n=2, background=False)
pin.assert_states_and_times([
(0.0, False),
(0.0, True),
(0.1, False),
(0.1, True),
(0.1, False)
])
示例13: test_output_blink_background
def test_output_blink_background():
pin = MockPin(2)
device = DigitalOutputDevice(pin)
device.blink(0.1, 0.1, n=2)
device._blink_thread.join() # naughty, but ensures no arbitrary waits in the test
pin.assert_states_and_times([
(0.0, False),
(0.0, True),
(0.1, False),
(0.1, True),
(0.1, False)
])
示例14: test_input_partial_callback
def test_input_partial_callback():
event = Event()
pin = MockPin(2)
def foo(a, b):
event.set()
return a + b
bar = partial(foo, 1)
baz = partial(bar, 2)
with DigitalInputDevice(pin) as device:
device.when_activated = baz
assert not event.is_set()
pin.drive_high()
assert event.is_set()
示例15: test_output_blink_foreground
def test_output_blink_foreground():
pin = MockPin(2)
with DigitalOutputDevice(pin) as device:
start = time()
device.blink(0.1, 0.1, n=2, background=False)
assert isclose(time() - start, 0.4, abs_tol=0.05)
pin.assert_states_and_times([
(0.0, False),
(0.0, True),
(0.1, False),
(0.1, True),
(0.1, False)
])