]> sigrok.org Git - pulseview.git/blame - pv/device/devinst.cpp
Added pv::device::Device
[pulseview.git] / pv / device / devinst.cpp
CommitLineData
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>
19adbc2c 22
8dd44190
JH
23#include <QDebug>
24
19adbc2c
JH
25#include <libsigrok/libsigrok.h>
26
27#include "devinst.h"
28
19adbc2c 29namespace pv {
94574501 30namespace device {
19adbc2c
JH
31
32DevInst::DevInst(sr_dev_inst *sdi) :
33 _sdi(sdi)
34{
35 assert(_sdi);
36}
37
38sr_dev_inst* DevInst::dev_inst() const
39{
40 return _sdi;
41}
42
8dd44190
JH
43GVariant* DevInst::get_config(const sr_probe_group *group, int key)
44{
45 GVariant *data = NULL;
46 if (sr_config_get(_sdi->driver, _sdi, group, key, &data) != SR_OK)
47 return NULL;
48 return data;
49}
50
51bool DevInst::set_config(const sr_probe_group *group, int key, GVariant *data)
52{
42e634cf
JH
53 if(sr_config_set(_sdi, group, key, data) == SR_OK) {
54 config_changed();
55 return true;
56 }
57 return false;
8dd44190
JH
58}
59
60GVariant* DevInst::list_config(const sr_probe_group *group, int key)
61{
62 GVariant *data = NULL;
63 if (sr_config_list(_sdi->driver, _sdi, group, key, &data) != SR_OK)
64 return NULL;
65 return data;
66}
67
e183f4e3
JH
68void DevInst::enable_probe(const sr_probe *probe, bool enable)
69{
70 for (const GSList *p = _sdi->probes; p; p = p->next)
71 if (probe == p->data) {
72 const_cast<sr_probe*>(probe)->enabled = enable;
8283c116 73 config_changed();
e183f4e3
JH
74 return;
75 }
76
77 // Probe was not found in the device
78 assert(0);
79}
80
27d7c96b
DK
81uint64_t DevInst::get_sample_limit()
82{
83 uint64_t sample_limit;
84 GVariant* gvar = get_config(NULL, SR_CONF_LIMIT_SAMPLES);
85 if (gvar != NULL) {
86 sample_limit = g_variant_get_uint64(gvar);
87 g_variant_unref(gvar);
88 } else {
89 sample_limit = 0U;
90 }
91 return sample_limit;
92}
93
94574501 94} // device
19adbc2c 95} // pv