|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +import sys |
| 4 | + |
| 5 | +import base58 |
| 6 | + |
| 7 | +from openlifu.io.LIFUInterface import LIFUInterface |
| 8 | + |
| 9 | +# set PYTHONPATH=%cd%\src;%PYTHONPATH% |
| 10 | +# python notebooks/test_console.py |
| 11 | +""" |
| 12 | +Test script to automate: |
| 13 | +1. Connect to the device. |
| 14 | +2. Test HVController: Turn HV on/off and check voltage. |
| 15 | +3. Test Device functionality. |
| 16 | +""" |
| 17 | +print("Starting LIFU Test Script...") |
| 18 | +interface = LIFUInterface(TX_test_mode=False) |
| 19 | +tx_connected, hv_connected = interface.is_device_connected() |
| 20 | +if tx_connected and hv_connected: |
| 21 | + print("LIFU Device Fully connected.") |
| 22 | +else: |
| 23 | + print(f'LIFU Device NOT Fully Connected. TX: {tx_connected}, HV: {hv_connected}') |
| 24 | + |
| 25 | +if not hv_connected: |
| 26 | + print("HV Controller not connected.") |
| 27 | + sys.exit() |
| 28 | + |
| 29 | +print("Ping the device") |
| 30 | +interface.hvcontroller.ping() |
| 31 | + |
| 32 | +print("Toggle LED") |
| 33 | +interface.hvcontroller.toggle_led() |
| 34 | + |
| 35 | +print("Get Version") |
| 36 | +version = interface.hvcontroller.get_version() |
| 37 | +print(f"Version: {version}") |
| 38 | + |
| 39 | +print("Echo Data") |
| 40 | +echo, echo_len = interface.hvcontroller.echo(echo_data=b'Hello LIFU!') |
| 41 | +if echo_len > 0: |
| 42 | + print(f"Echo: {echo.decode('utf-8')}") # Echo: Hello LIFU! |
| 43 | +else: |
| 44 | + print("Echo failed.") |
| 45 | + |
| 46 | +print("Get HW ID") |
| 47 | +hw_id = interface.hvcontroller.get_hardware_id() |
| 48 | +print(f"HW ID: {hw_id}") |
| 49 | +encoded_id = base58.b58encode(bytes.fromhex(hw_id)).decode() |
| 50 | +print(f"OW-LIFU-CON-{encoded_id}") |
| 51 | + |
| 52 | +print("Get Temperature1") |
| 53 | +temp1 = interface.hvcontroller.get_temperature1() |
| 54 | +print(f"Temperature1: {temp1}") |
| 55 | + |
| 56 | +print("Get Temperature2") |
| 57 | +temp2 = interface.hvcontroller.get_temperature2() |
| 58 | +print(f"Temperature2: {temp2}") |
| 59 | + |
| 60 | +print("Set Bottom Fan Speed to 20%") |
| 61 | +btfan_speed = interface.hvcontroller.set_fan_speed(fan_id=0, fan_speed=20) |
| 62 | +print(f"Bottom Fan Speed: {btfan_speed}") |
| 63 | + |
| 64 | +print("Set Top Fan Speed to 40%") |
| 65 | +tpfan_speed = interface.hvcontroller.set_fan_speed(fan_id=1, fan_speed=40) |
| 66 | +print(f"Bottom Fan Speed: {tpfan_speed}") |
| 67 | + |
| 68 | +print("Get Bottom Fan Speed") |
| 69 | +btfan_speed = interface.hvcontroller.get_fan_speed(fan_id=0) |
| 70 | +print(f"Bottom Fan Speed: {btfan_speed}") |
| 71 | + |
| 72 | +print("Get Top Fan Speed") |
| 73 | +tpfan_speed = interface.hvcontroller.get_fan_speed(fan_id=1) |
| 74 | +print(f"Bottom Fan Speed: {tpfan_speed}") |
| 75 | + |
| 76 | +print("Set RGB LED") |
| 77 | +rgb_led = interface.hvcontroller.set_rgb_led(rgb_state=2) |
| 78 | +print(f"RGB STATE: {rgb_led}") |
| 79 | + |
| 80 | +print("Get RGB LED") |
| 81 | +rgb_led_state = interface.hvcontroller.get_rgb_led() |
| 82 | +print(f"RGB STATE: {rgb_led_state}") |
| 83 | + |
| 84 | +print("Test 12V...") |
| 85 | +if interface.hvcontroller.turn_12v_on(): |
| 86 | + print("12V ON Press enter to TURN OFF:") |
| 87 | + input() # Wait for the user to press Enter |
| 88 | + if interface.hvcontroller.turn_12v_off(): |
| 89 | + print("12V OFF.") |
| 90 | + else: |
| 91 | + print("Failed to turn off 12V") |
| 92 | +else: |
| 93 | + print("Failed to turn on 12V.") |
| 94 | + |
| 95 | +# Set High Voltage Level |
| 96 | +print("Set HV Power to +/- 12V") |
| 97 | +if interface.hvcontroller.set_voltage(voltage=12.0): |
| 98 | + print("Voltage set to 12.0 V.") |
| 99 | +else: |
| 100 | + print("Failed to set voltage.") |
| 101 | + |
| 102 | +# Get Set High Voltage Setting |
| 103 | +print("Get HV Setting") |
| 104 | +read_set_voltage = interface.hvcontroller.get_voltage() |
| 105 | +print(f"Voltage set to {read_set_voltage} V.") |
| 106 | + |
| 107 | + |
| 108 | +print("Test HV Supply...") |
| 109 | +if interface.hvcontroller.turn_hv_on(): |
| 110 | + print("HV ON Press enter to TURN OFF:") |
| 111 | + input() # Wait for the user to press Enter |
| 112 | + if interface.hvcontroller.turn_hv_off(): |
| 113 | + print("HV OFF.") |
| 114 | + else: |
| 115 | + print("Failed to turn off HV") |
| 116 | +else: |
| 117 | + print("Failed to turn on HV.") |
| 118 | + |
| 119 | +print("Reset DevConsoleice:") |
| 120 | +# Ask the user for confirmation |
| 121 | +user_input = input("Do you want to reset the Console? (y/n): ").strip().lower() |
| 122 | + |
| 123 | +if user_input == 'y': |
| 124 | + if interface.hvcontroller.soft_reset(): |
| 125 | + print("Reset Successful.") |
| 126 | +elif user_input == 'n': |
| 127 | + print("Reset canceled.") |
| 128 | +else: |
| 129 | + print("Invalid input. Please enter 'y' or 'n'.") |
0 commit comments