]> sigrok.org Git - sigrok-meter.git/blame_incremental - sigrok-meter
Use the new Log class from the bindings.
[sigrok-meter.git] / sigrok-meter
... / ...
CommitLineData
1#!/usr/bin/python3
2##
3## This file is part of the sigrok-meter project.
4##
5## Copyright (C) 2013 Uwe Hermann <uwe@hermann-uwe.de>
6##
7## This program is free software; you can redistribute it and/or modify
8## it under the terms of the GNU General Public License as published by
9## the Free Software Foundation; either version 2 of the License, or
10## (at your option) any later version.
11##
12## This program is distributed in the hope that it will be useful,
13## but WITHOUT ANY WARRANTY; without even the implied warranty of
14## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15## GNU General Public License for more details.
16##
17## You should have received a copy of the GNU General Public License
18## along with this program; if not, write to the Free Software
19## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20##
21
22from multiprocessing import Process, Queue
23from gi.repository import Gtk, GObject
24from sigrok.core import Context, Driver, Device, Session, Packet, Log
25from sigrok.core import lowlevel as ll
26
27def init_and_run(queue):
28 def datafeed_in(device, packet):
29 if packet.type == Packet.ANALOG:
30 data = packet.payload.data
31 unit, unit_str = packet.payload.unit, ""
32 if unit == ll.SR_UNIT_VOLT:
33 unit_str = " V"
34 elif unit == ll.SR_UNIT_OHM:
35 unit_str = " Ohm"
36 elif unit == ll.SR_UNIT_AMPERE:
37 unit_str = " A"
38 mqflags, mqflags_str = packet.payload.unit, ""
39 if mqflags & ll.SR_MQFLAG_AC:
40 mqflags_str = " AC"
41 elif mqflags & ll.SR_MQFLAG_DC:
42 mqflags_str = " DC"
43 for i in range(packet.payload.num_samples):
44 queue.put("%f%s%s" % (data[i], unit_str, mqflags_str))
45
46 # log = Log()
47 # log.level = Log.SPEW
48 context = Context()
49 driver = context.drivers['voltcraft-vc820']
50 device = driver.scan()[0]
51 device.limit_samples = 1000
52 session = Session(context)
53 session.add_device(device)
54 session.add_callback(datafeed_in)
55 session.start()
56 session.run()
57 session.stop()
58
59class SigrokMeter:
60 def __init__(self):
61 self.builder = Gtk.Builder()
62 self.builder.add_from_file("sigrok-meter.glade")
63 self.builder.connect_signals(self)
64 self.value_label = self.builder.get_object("value_label")
65 self.win = self.builder.get_object("mainwindow")
66 self.win.show_all()
67 self.queue = Queue()
68 GObject.timeout_add(100, self.update_label_if_needed)
69
70 def update_label_if_needed(self):
71 try:
72 t = self.queue.get_nowait()
73 self.value_label.set_text(t)
74 except:
75 pass
76 GObject.timeout_add(100, self.update_label_if_needed)
77
78 def on_quit(self, *args):
79 Gtk.main_quit(*args)
80
81 def on_about(self, action):
82 about = self.builder.get_object("aboutdialog")
83 sr_pkg = ll.sr_package_version_string_get()
84 sr_lib = ll.sr_lib_version_string_get()
85 s = "Using libsigrok %s (lib version %s)." % (sr_pkg, sr_lib)
86 about.set_comments(s)
87 about.run()
88 about.hide()
89
90if __name__ == '__main__':
91 s = SigrokMeter()
92 process = Process(target=init_and_run, args=(s.queue,))
93 process.start()
94 Gtk.main()
95 process.terminate()
96