Victor86B digital multimeter app
[tridge/junkcode.git] / DMM / dmm.py
1 #!/usr/bin/env python
2
3 ###################################
4 # python Digital Multimeter App
5 # (C) Andrew Tridgell 2011
6 # Released under GNU GPLv3 or later
7
8 from dmmui import *
9 from dmmread import *
10 import sys
11
12 def tick():
13     '''update display'''
14     global device
15     global tickcount
16     try:
17         v = device.read()
18         ui.LCD.display(v.lcd)
19         if v.units:
20             ui.units.setText(v.units)
21         else:
22             ui.units.setText("-")
23         if v.mode:
24             ui.mode.setText(v.mode)
25         else:
26             ui.mode.setText("")
27         if tickcount & 1:
28             ui.tick.setText('*')
29         else:
30             ui.tick.setText(' ')
31         tickcount += 1
32     except DMMTimeout:
33         pass
34     except DMMDataError, msg:
35         print("DMM Data Error: %s" % msg)
36     except KeyboardInterrupt:
37         sys.exit(1)
38
39
40 ############################################
41 # main program
42 if __name__ == "__main__":
43     global device, tickcount
44
45     device = DMM_Victor86B()
46     tickcount = 0
47
48     app = QtGui.QApplication(sys.argv)
49     dmm = QtGui.QMainWindow()
50     ui = Ui_DMMUI()
51     ui.setupUi(dmm)
52
53     ctimer = QtCore.QTimer()
54     QtCore.QObject.connect(ctimer, QtCore.SIGNAL("timeout()"), tick)
55     ctimer.start(1)
56
57     dmm.show()
58     sys.exit(app.exec_())