51 lines
2.1 KiB
Python
51 lines
2.1 KiB
Python
"""G20 left-hand feedback and optional small index-root movement test."""
|
|
import argparse
|
|
import time
|
|
import can
|
|
|
|
|
|
def query(bus, prop):
|
|
while bus.recv(timeout=0) is not None:
|
|
pass
|
|
bus.send(can.Message(arbitration_id=0x28, is_extended_id=False, data=[prop]))
|
|
end = time.monotonic() + 0.5
|
|
while time.monotonic() < end:
|
|
msg = bus.recv(timeout=max(0, end - time.monotonic()))
|
|
if msg is not None and not msg.is_error_frame and msg.arbitration_id == 0x28 and len(msg.data) > 1 and msg.data[0] == prop:
|
|
return list(msg.data[1:])
|
|
raise RuntimeError(f"No fresh left-hand response for {prop:#x}")
|
|
|
|
|
|
def main():
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument('--test-motion', action='store_true')
|
|
args = ap.parse_args()
|
|
with can.Bus(channel='can0', interface='socketcan', receive_own_messages=False) as bus:
|
|
print('firmware', query(bus, 0xC2))
|
|
for prop in range(0x41, 0x46):
|
|
print(hex(prop), query(bus, prop))
|
|
if args.test_motion:
|
|
original = query(bus, 0x42)
|
|
if len(original) != 6:
|
|
raise RuntimeError('Unexpected finger payload length')
|
|
target = original.copy()
|
|
target[2] = original[2] - 4 if original[2] >= 4 else original[2] + 4
|
|
try:
|
|
bus.send(can.Message(arbitration_id=0x28, is_extended_id=False, data=[0x42] + target))
|
|
time.sleep(0.8)
|
|
actual = query(bus, 0x42)
|
|
print('index before/target/actual', original, target, actual)
|
|
if abs(actual[2] - target[2]) > 2 or actual[2] == original[2]:
|
|
raise RuntimeError('Motion feedback did not follow target')
|
|
finally:
|
|
bus.send(can.Message(arbitration_id=0x28, is_extended_id=False, data=[0x42] + original))
|
|
time.sleep(0.8)
|
|
restored = query(bus, 0x42)
|
|
print('restored', restored)
|
|
if abs(restored[2] - original[2]) > 2:
|
|
raise RuntimeError('Restoration not verified')
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|