-
Notifications
You must be signed in to change notification settings - Fork 8
/
alextune_cli.py
executable file
·58 lines (48 loc) · 1.14 KB
/
alextune_cli.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/python
#
# Tool to help tune a magnetic loop.
# Usage:
#
# Just run it, and turn the knob a bit back and forth over the right area.
#
# A new line means a new maximum was found.
#
# Try to get meter as high as possible after it's stopped finding new
# maximums.
#
import alextune
import time
import shutil
import os
import sys
def get_terminal_width():
_, columns = os.popen('stty size', 'r').read().split()
return int(columns)
def p(s):
sys.stdout.write(s)
sys.stdout.flush()
def main():
tb = alextune.alextune()
tb.start()
mx = 0.0
screenmax = 0.75
try:
print('Press ^C to quit\n')
while True:
time.sleep(0.1)
v = tb.strength
if v > mx:
p('\n')
mx = max(mx, v)
w = get_terminal_width()
l = int(screenmax * w * v / mx)
tl = int(screenmax * w)
p('\r' + ' ' * (int(w * screenmax) + 2))
p('\r[' + '#' * l + ' ' * (tl - l) + ']')
except KeyboardInterrupt:
pass
tb.stop()
tb.wait()
print('\n')
if __name__ == '__main__':
main()