]>
Commit | Line | Data |
---|---|---|
19adbc2c JH |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2014 Joel Holdsworth <joel@airwebreathe.org.uk> | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify | |
7 | * it under the terms of the GNU General Public License as published by | |
8 | * the Free Software Foundation; either version 2 of the License, or | |
9 | * (at your option) any later version. | |
10 | * | |
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
20 | ||
21 | #include <cassert> | |
22 | #include <sstream> | |
23 | ||
8dd44190 JH |
24 | #include <QDebug> |
25 | ||
19adbc2c JH |
26 | #include <libsigrok/libsigrok.h> |
27 | ||
28 | #include "devinst.h" | |
29 | ||
30 | using std::ostringstream; | |
31 | using std::string; | |
32 | ||
33 | namespace pv { | |
34 | ||
35 | DevInst::DevInst(sr_dev_inst *sdi) : | |
36 | _sdi(sdi) | |
37 | { | |
38 | assert(_sdi); | |
39 | } | |
40 | ||
41 | sr_dev_inst* DevInst::dev_inst() const | |
42 | { | |
43 | return _sdi; | |
44 | } | |
45 | ||
46 | string DevInst::format_device_title() const | |
47 | { | |
48 | ostringstream s; | |
49 | ||
50 | assert(_sdi); | |
51 | ||
52 | if (_sdi->vendor && _sdi->vendor[0]) { | |
53 | s << _sdi->vendor; | |
54 | if ((_sdi->model && _sdi->model[0]) || | |
55 | (_sdi->version && _sdi->version[0])) | |
56 | s << ' '; | |
57 | } | |
58 | ||
59 | if (_sdi->model && _sdi->model[0]) { | |
60 | s << _sdi->model; | |
61 | if (_sdi->version && _sdi->version[0]) | |
62 | s << ' '; | |
63 | } | |
64 | ||
65 | if (_sdi->version && _sdi->version[0]) | |
66 | s << _sdi->version; | |
67 | ||
68 | return s.str(); | |
69 | } | |
70 | ||
8dd44190 JH |
71 | GVariant* DevInst::get_config(const sr_probe_group *group, int key) |
72 | { | |
73 | GVariant *data = NULL; | |
74 | if (sr_config_get(_sdi->driver, _sdi, group, key, &data) != SR_OK) | |
75 | return NULL; | |
76 | return data; | |
77 | } | |
78 | ||
79 | bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data) | |
80 | { | |
42e634cf JH |
81 | if(sr_config_set(_sdi, group, key, data) == SR_OK) { |
82 | config_changed(); | |
83 | return true; | |
84 | } | |
85 | return false; | |
8dd44190 JH |
86 | } |
87 | ||
88 | GVariant* DevInst::list_config(const sr_probe_group *group, int key) | |
89 | { | |
90 | GVariant *data = NULL; | |
91 | if (sr_config_list(_sdi->driver, _sdi, group, key, &data) != SR_OK) | |
92 | return NULL; | |
93 | return data; | |
94 | } | |
95 | ||
e183f4e3 JH |
96 | void DevInst::enable_probe(const sr_probe *probe, bool enable) |
97 | { | |
98 | for (const GSList *p = _sdi->probes; p; p = p->next) | |
99 | if (probe == p->data) { | |
100 | const_cast<sr_probe*>(probe)->enabled = enable; | |
8283c116 | 101 | config_changed(); |
e183f4e3 JH |
102 | return; |
103 | } | |
104 | ||
105 | // Probe was not found in the device | |
106 | assert(0); | |
107 | } | |
108 | ||
27d7c96b DK |
109 | uint64_t DevInst::get_sample_limit() |
110 | { | |
111 | uint64_t sample_limit; | |
112 | GVariant* gvar = get_config(NULL, SR_CONF_LIMIT_SAMPLES); | |
113 | if (gvar != NULL) { | |
114 | sample_limit = g_variant_get_uint64(gvar); | |
115 | g_variant_unref(gvar); | |
116 | } else { | |
117 | sample_limit = 0U; | |
118 | } | |
119 | return sample_limit; | |
120 | } | |
121 | ||
19adbc2c | 122 | } // pv |