-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_big.py
executable file
·58 lines (43 loc) · 2.42 KB
/
simple_big.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
#!/usr/bin/python
# simple demo for the usage of module OpenMetra
import sys
from openmetra import OpenMetra
def print_big( string ):
'''print numerical data with big character on top of terminal screen'''
dor_matrix = [
[' ### ', ' # ', ' ### ', ' ####', '# ', '#####', ' ###', '#####', ' ### ', ' ### ', ' ', ' ', ' ', ' '],
['# #', ' ## ', '# #', ' #', '# # ', '# ', ' # ', ' #', '# #', '# #', ' # ', ' ', ' ', ' '],
['# #', '# # ', ' #', ' # ', '# # ', '#### ', '# ', ' #', '# #', '# #', ' # ', ' ', ' ', ' '],
['# #', ' # ', ' ## ', ' ###', '#####', ' #', '#### ', ' # ', ' ### ', ' ####', '#####', ' ', '#####', ' '],
['# #', ' # ', ' # ', ' #', ' # ', ' #', '# #', ' # ', '# #', ' #', ' # ', ' ', ' ', ' '],
['# #', ' # ', '# ', '# #', ' # ', '# #', '# #', ' # ', '# #', ' # ', ' # ', ' ## ', ' ', ' ## '],
[' ### ', '#####', '#####', ' ### ', ' # ', ' ### ', ' ### ', ' # ', ' ### ', '### ', ' ', ' ## ', ' ', ' ## '],
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' # ', ' ', ' '],
]
y_size = len( dor_matrix )
x_size = len( dor_matrix[0][0] )
print( chr(27) + '[2J' ) # clear screen
print( chr(27) + '[H' ) # cursor home
if string is None:
return
neg = string[0] == '-'
for line in range( y_size ): # rows
if not neg: # leading space
print( x_size * ' ', end = ' ' )
for c in string: # columns
n = ord( c ) - ord('0')
if n < 0: # correct for '+' ',' '-' '.'
n += 15
print( dor_matrix[ line ][ n ], end = ' ' )
print()
print()
with OpenMetra() as mh: # open connection
if mh is None: # check
print( 'connect error', file=sys.stderr)
sys.exit()
while True: # run forever, stop with ^C
try:
print_big( mh.get_measurement() ) # print numeric value
except KeyboardInterrupt: # ^C pressed, stop measurement
print()
break # exit