-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdemo_bargraph
More file actions
executable file
·56 lines (47 loc) · 1.7 KB
/
demo_bargraph
File metadata and controls
executable file
·56 lines (47 loc) · 1.7 KB
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/python3
import argparse
import pylcdproc
import getch
import sys
default_host = 'localhost'
default_port = 13666
def main():
parser = argparse.ArgumentParser(description="Demonstrate the HBargraphLCD widget")
parser.add_argument("initial", type=int, default=0, nargs='?', help="initial value")
parser.add_argument("-H", "--host", default=default_host,
help="host to connect to (default: " + default_host + ")")
parser.add_argument("-p", "--port", type=int, default=default_port,
help="port to connect to (default: " + str(default_port) + ")")
parser.add_argument("-d", "--debug", action="store_true",
help="enable debugging")
args = parser.parse_args()
lcd = pylcdproc.HBargraphLCD("demo_bargraph", host=args.host, port=args.port, debug=args.debug)
val = args.initial
lcd.display(val)
print("use left and right arrows to set bargraph value, currently", val)
print("use 'x' or 'q' to quit")
control = None
while True:
change = None
key = getch.getch()
if key == 'x' or key == 'q':
print("exiting...")
sys.exit(1)
elif key == '[' or ord(key) == 27:
control = True
next
elif key == 'C':
change = 1
elif key == 'D':
change = -1
else:
ctrl = "ctrl" if control else ""
print("unknown key:", ord(key), "'" + key + "'", ctrl)
if control: # reset control
control = None
if change:
val += change
print("new value:", val)
lcd.display(val)
if __name__ == "__main__":
main()