Skip to content

Commit 3a60674

Browse files
authored
add support for duo (#55)
1 parent 0b3cd8b commit 3a60674

4 files changed

Lines changed: 201 additions & 172 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ Or you can run commands in an interactive shell like this:
361361

362362
```
363363
$ onlykey-cli
364-
OnlyKey CLI v1.2.7
364+
OnlyKey CLI v1.2.8
365365
Press the right arrow to insert the suggestion.
366366
Press Control-C to retry. Control-D to exit.
367367

onlykey/cli.py

Lines changed: 54 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,14 +114,29 @@ def prompt_pin():
114114
print(only_key.read_string())
115115
print ()
116116
elif sys.argv[1] == 'getlabels':
117-
tmp = {}
118-
for slot in only_key.getlabels():
119-
tmp[slot.name] = slot
120-
slots = iter(['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b'])
121-
for slot_name in slots:
122-
print(tmp[slot_name].to_str().replace('ÿ'," "))
123-
print(tmp[next(slots)].to_str().replace('ÿ'," "))
124-
print()
117+
tmp = {}
118+
only_key.set_time(time.time())
119+
okversion = only_key.read_string()
120+
if okversion[19] == 'c':
121+
for slot in only_key.getlabels():
122+
tmp[slot.name] = slot
123+
slots = iter(['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b'])
124+
for slot_name in slots:
125+
print(tmp[slot_name].to_str().replace('ÿ'," "))
126+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
127+
print()
128+
else:
129+
for slot in only_key.getduolabels():
130+
tmp[slot.name] = slot
131+
slots = iter(['Green 1a', 'Green 2a', 'Green 3a', 'Green 1b', 'Green 2b', 'Green 3b', 'Blue 1a', 'Blue 2a', 'Blue 3a', 'Blue 1b', 'Blue 2b', 'Blue 3b', 'Yellow 1a', 'Yellow 2a', 'Yellow 3a', 'Yellow 1b', 'Yellow 2b', 'Yellow 3b', 'Purple 1a', 'Purple 2a', 'Purple 3a', 'Purple 1b', 'Purple 2b', 'Purple 3b'])
132+
for slot_name in slots:
133+
print(tmp[slot_name].to_str().replace('ÿ'," "))
134+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
135+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
136+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
137+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
138+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
139+
print()
125140
elif sys.argv[1] == 'getkeylabels':
126141
tmp = {}
127142
for slot in only_key.getkeylabels():
@@ -155,6 +170,8 @@ def prompt_pin():
155170
slot_id = 11
156171
elif sys.argv[2] == '6b':
157172
slot_id = 12
173+
else:
174+
slot_id = int(sys.argv[2])
158175
except:
159176
print("setslot [id] [type] [value]")
160177
print("[id] must be slot number 1a - 6b")
@@ -357,7 +374,7 @@ def prompt_pin():
357374
elif sys.argv[1] == 'wipemode':
358375
only_key.setslot(1, MessageField.WIPEMODE, int(sys.argv[2]))
359376
elif sys.argv[1] == 'keytypespeed':
360-
only_key.setslot(1, MessageField.KEYTYPESPEED, int(sys.argv[2]))
377+
only_key.setslot(int(sys.argv[2]), MessageField.KEYTYPESPEED, int(sys.argv[3]))
361378
elif sys.argv[1] == 'ledbrightness':
362379
only_key.setslot(1, MessageField.LEDBRIGHTNESS, int(sys.argv[2]))
363380
elif sys.argv[1] == 'touchsense':
@@ -379,7 +396,7 @@ def prompt_pin():
379396
elif sys.argv[1] == 'hmackeymode':
380397
only_key.setslot(1, MessageField.HMACMODE, int(sys.argv[2]))
381398
elif sys.argv[1] == 'version':
382-
print('OnlyKey CLI v1.2.7')
399+
print('OnlyKey CLI v1.2.8')
383400
elif sys.argv[1] == 'fwversion':
384401
only_key.set_time(time.time())
385402
okversion = only_key.read_string()
@@ -456,7 +473,7 @@ def prompt_pin():
456473
else:
457474

458475
# Print help.
459-
print('OnlyKey CLI v1.2.7')
476+
print('OnlyKey CLI v1.2.8')
460477
print('Control-D to exit.')
461478
print()
462479

@@ -527,14 +544,29 @@ def mprompt():
527544
print(only_key.read_string())
528545
print()
529546
elif data[0] == 'getlabels':
530-
tmp = {}
531-
for slot in only_key.getlabels():
532-
tmp[slot.name] = slot
533-
slots = iter(['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b'])
534-
for slot_name in slots:
535-
print(tmp[slot_name].to_str().replace('ÿ'," "))
536-
print(tmp[next(slots)].to_str().replace('ÿ'," "))
537-
print()
547+
tmp = {}
548+
only_key.set_time(time.time())
549+
okversion = only_key.read_string()
550+
if okversion[19] == 'c':
551+
for slot in only_key.getlabels():
552+
tmp[slot.name] = slot
553+
slots = iter(['1a', '1b', '2a', '2b', '3a', '3b', '4a', '4b', '5a', '5b', '6a', '6b'])
554+
for slot_name in slots:
555+
print(tmp[slot_name].to_str().replace('ÿ'," "))
556+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
557+
print()
558+
else:
559+
for slot in only_key.getduolabels():
560+
tmp[slot.name] = slot
561+
slots = iter(['Green 1a', 'Green 2a', 'Green 3a', 'Green 1b', 'Green 2b', 'Green 3b', 'Blue 1a', 'Blue 2a', 'Blue 3a', 'Blue 1b', 'Blue 2b', 'Blue 3b', 'Yellow 1a', 'Yellow 2a', 'Yellow 3a', 'Yellow 1b', 'Yellow 2b', 'Yellow 3b', 'Purple 1a', 'Purple 2a', 'Purple 3a', 'Purple 1b', 'Purple 2b', 'Purple 3b'])
562+
for slot_name in slots:
563+
print(tmp[slot_name].to_str().replace('ÿ'," "))
564+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
565+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
566+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
567+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
568+
print(tmp[next(slots)].to_str().replace('ÿ'," "))
569+
print()
538570
elif data[0] == 'getkeylabels':
539571
tmp = {}
540572
for slot in only_key.getkeylabels():
@@ -568,6 +600,8 @@ def mprompt():
568600
slot_id = 11
569601
elif data[1] == '6b':
570602
slot_id = 12
603+
else:
604+
slot_id = int(data[1])
571605
except:
572606
print("setslot [id] [type] [value]")
573607
print("[id] must be slot number 1a - 6b")
@@ -839,7 +873,7 @@ def mprompt():
839873
continue
840874
elif data[0] == 'version':
841875
try:
842-
print('OnlyKey CLI v1.2.7')
876+
print('OnlyKey CLI v1.2.8')
843877
except:
844878
continue
845879
elif data[0] == 'fwversion':

0 commit comments

Comments
 (0)