-
Notifications
You must be signed in to change notification settings - Fork 0
/
owon-gui.vala
174 lines (148 loc) · 4.72 KB
/
owon-gui.vala
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/**********************************************************************
owon-tools - Copyright (C) 2017 - Andreas Kemnade
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
***********************************************************************/
public class OwonDisplay : Gtk.Window {
Gtk.Button connectbutton;
bool searching;
Gtk.Label measurementlabel;
Gtk.Label buttonstatuslabel;
OwonDevice owon_dev;
OwonManager owon_manager;
Gtk.Button owon_select;
Gtk.Button owon_range;
Gtk.Button owon_hold;
Gtk.Button owon_delta;
Gtk.Button owon_hz_duty;
Gtk.Button owon_maxmin;
Gtk.Button search;
void display_measurement(MeasurementResult res) {
measurementlabel.set_text(res.print_value());
string [] status = {};
if (res.autorange)
status += "AUTO";
if (res.max)
status += "MAX";
if (res.min)
status += "MIN";
if (res.hold)
status += "H";
if (res.delta)
status += "delta";
if (res.beepmode)
status += "beep";
if (res.diode)
status += "diode";
StringBuilder b = new StringBuilder();
if (status.length > 0)
b.assign(status[0]);
for(int i = 1; i < status.length; i++) {
b.append_c(' ');
b.append(status[i]);
}
buttonstatuslabel.set_text(b.str);
}
void get_connected() {
try {
owon_manager.discover();
owon_dev = owon_manager.get_known();
if (owon_dev != null) {
owon_dev.got_measurement.connect(display_measurement);
owon_dev.start_measure();
}
} catch (IOError e) {
measurementlabel.set_text("error getting device:\n%s".printf(e.message));
}
}
void select_clicked() {
if (owon_dev != null)
owon_dev.press_button(OwonDevice.Button.SELECT, 1);
}
void range_clicked() {
if (owon_dev != null)
owon_dev.press_button(OwonDevice.Button.RANGE, 1);
}
void hold_clicked() {
if (owon_dev != null)
owon_dev.press_button(OwonDevice.Button.HOLD_LIGHT, 1);
}
void delta_clicked() {
if (owon_dev != null)
owon_dev.press_button(OwonDevice.Button.DELTA_BT, 1);
}
void hz_duty_clicked() {
if (owon_dev != null)
owon_dev.press_button(OwonDevice.Button.HZ_DUTY, 1);
}
void max_min_clicked() {
if (owon_dev != null)
owon_dev.press_button(OwonDevice.Button.MAX_MIN, 1);
}
void search_and_connect() {
search.set_sensitive(false);
owon_manager.search_and_connect((obj, res) => {
owon_dev = null;
if (owon_manager.search_and_connect.end(res)) {
get_connected();
}
search.set_sensitive(true);
});
}
public OwonDisplay() {
// base(Gtk.WindowType.TOPLEVEL);
var vbox = new Gtk.VBox(false, 0);
var hboxtop = new Gtk.HBox(false, 0);
base.add(vbox);
vbox.pack_start(hboxtop, false, true,0);
owon_select = new Gtk.Button.with_label("Select");
hboxtop.pack_start(owon_select, true, true, 0);
owon_select.clicked.connect(select_clicked);
owon_range = new Gtk.Button.with_label("Range");
hboxtop.pack_start(owon_range, true, true, 0);
owon_range.clicked.connect(range_clicked);
owon_hold = new Gtk.Button.with_label("Hold");
hboxtop.pack_start(owon_hold, true, true, 0);
owon_hold.clicked.connect(hold_clicked);
owon_delta = new Gtk.Button.with_label("Delta");
hboxtop.pack_start(owon_delta, true, true, 0);
owon_delta.clicked.connect(delta_clicked);
owon_hz_duty = new Gtk.Button.with_label("Hz/Duty");
hboxtop.pack_start(owon_hz_duty, true, true, 0);
owon_hz_duty.clicked.connect(hz_duty_clicked);
owon_maxmin = new Gtk.Button.with_label("Max/Min");
hboxtop.pack_start(owon_maxmin, true, true, 0);
owon_maxmin.clicked.connect(max_min_clicked);
measurementlabel = new Gtk.Label("not connected");
vbox.pack_start(measurementlabel, true ,true, 0);
buttonstatuslabel = new Gtk.Label("");
vbox.pack_start(buttonstatuslabel, false, true, 0);
var hboxbottom = new Gtk.HBox(false, 0);
vbox.pack_start(hboxbottom, false, false, 0);
search = new Gtk.Button.with_label("Search");
search.clicked.connect(search_and_connect);
hboxbottom.pack_start(search, false, false, 0);
owon_manager = new OwonManager();
get_connected();
}
}
public int main(string [] args) {
Gtk.init(ref args);
DBusConnection conn = Bus.get_sync(BusType.SYSTEM);
register_profile(conn, OwonDevice.uuid);
OwonDisplay owon = new OwonDisplay();
MainLoop ml = new MainLoop();
owon.delete_event.connect( () => {
ml.quit();
return true;
});
owon.show_all();
ml.run();
return 0;
}