mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[robotpy] Mirror most other subprojects (#8208)
GitOrigin-RevId: ac60fd3cf4a24023184376687da28373d14b781a This mirrors the robotpy files for the following projects: - apriltag - datalog - hal - ntcore - romiVendordep - wpilibc - wpimath - xrpVendordep This excludes cscore and the halsim wrappers for at this time. NOTE: This does not hook these projects up to the build system, just simply mirrors the files. The building will take place in a follow up PR to make it easier to review the changes necessary to build.
This commit is contained in:
41
hal/src/test/python/test_hal_simulation.py
Normal file
41
hal/src/test/python/test_hal_simulation.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import hal
|
||||
import hal.simulation
|
||||
|
||||
import typing
|
||||
|
||||
|
||||
def test_value_changed_callback():
|
||||
|
||||
recv: typing.Optional[typing.Tuple[bool, str, int]] = None
|
||||
|
||||
def created_cb(
|
||||
name: str, handle: int, direction: hal.SimValueDirection, value: hal.Value
|
||||
):
|
||||
nonlocal recv
|
||||
recv = (True, name, value.value)
|
||||
|
||||
def cb(name: str, handle: int, direction: hal.SimValueDirection, value: hal.Value):
|
||||
nonlocal recv
|
||||
recv = (False, name, value.value)
|
||||
|
||||
dev = hal.SimDevice("simd")
|
||||
|
||||
# Must keep the returned value alive or the callback will be unregistered
|
||||
devunused = hal.simulation.registerSimValueCreatedCallback(dev, created_cb, True)
|
||||
assert recv is None
|
||||
|
||||
val = dev.createInt("answer", 0, 42)
|
||||
|
||||
assert recv == (True, "answer", 42)
|
||||
recv = None
|
||||
|
||||
# Must keep the returned value alive or the callback will be unregistered
|
||||
unused = hal.simulation.registerSimValueChangedCallback(val, cb, True)
|
||||
|
||||
assert recv == (False, "answer", 42)
|
||||
recv = None
|
||||
|
||||
val.set(84)
|
||||
|
||||
assert recv == (False, "answer", 84)
|
||||
recv = None
|
||||
Reference in New Issue
Block a user