-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetParam.py
executable file
·44 lines (37 loc) · 1.21 KB
/
setParam.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python3
import click
import sys
import time
from purpledrop.messages import SetParameterMsg
from purpledrop.purpledrop import PurpleDropDevice, list_purpledrop_devices
@click.command()
@click.argument("id", type=int)
@click.argument("value")
@click.option('--float', is_flag=True)
def main(id, value, float):
msg = SetParameterMsg()
msg.set_param_idx(id)
if float:
msg.set_param_value_float(float(value))
else:
msg.set_param_value_int(int(value))
msg.set_write_flag(True)
devices = list_purpledrop_devices()
if(len(devices) == 0):
print("No PurpleDrop USB device found")
sys.exit(1)
elif len(devices) > 1:
print("Multiple PurpleDrop devices found. Please ammend software to allow selection by serial number")
for d in devices:
print(f"{d.device}: Serial {d.serial_number}")
sys.exit(1)
dev = PurpleDropDevice(devices[0].device)
with dev.get_sync_listener(msg_filter=SetParameterMsg) as listener:
dev.send_message(msg)
ack = listener.next(timeout=1.0)
if ack is None:
print("No ACK message received")
else:
print("Got ACK: " + str(ack))
if __name__ == '__main__':
main()