demo.py 942 B

12345678910111213141516171819202122232425
  1. #!/usr/bin/env python3
  2. from pathlib import Path
  3. import sys
  4. sys.path.insert(0, str(Path(__file__).resolve().parents[2] / "python"))
  5. from hth6400 import (
  6. SetAll, set_all_uart, set_all_i2c, get_snapshot_i2c,
  7. snapshot_reads, uart_frame, decode_ack_nack,
  8. )
  9. value = SetAll(
  10. ptc=(0,) * 18 + (100,) * 6,
  11. front=(20, 20, 20, 30),
  12. rear=(20, 20, 20, 10),
  13. )
  14. print("UART_SET_ALL", set_all_uart(value).hex().upper())
  15. for index, (address, write, read_length) in enumerate(set_all_i2c(value)):
  16. print("I2C[%d] address=0x%02X write=%s read=%d" %
  17. (index, address, write.hex().upper(), read_length))
  18. address, write, read_length = get_snapshot_i2c()
  19. print("I2C_GET address=0x%02X write=%s read=%d" %
  20. (address, write.hex().upper(), read_length))
  21. print("I2C_SNAPSHOT_READS", [(tx[1].hex().upper(), tx[2]) for tx in snapshot_reads(199, 64)])
  22. ack = uart_frame(0x06, bytes((1, 0x01, 0, 0)))
  23. print("ACK", decode_ack_nack(ack))