]>
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> | |
19adbc2c | 22 | |
8dd44190 JH |
23 | #include <QDebug> |
24 | ||
19adbc2c JH |
25 | #include <libsigrok/libsigrok.h> |
26 | ||
27 | #include "devinst.h" | |
28 | ||
996b7c9d JH |
29 | #include <pv/sigsession.h> |
30 | ||
19adbc2c | 31 | namespace pv { |
94574501 | 32 | namespace device { |
19adbc2c | 33 | |
29efe92a | 34 | DevInst::DevInst() : |
996b7c9d | 35 | _owner(NULL) |
19adbc2c | 36 | { |
19adbc2c JH |
37 | } |
38 | ||
ae2d1bc5 | 39 | void DevInst::use(SigSession *owner) throw(QString) |
996b7c9d JH |
40 | { |
41 | assert(owner); | |
42 | assert(!_owner); | |
43 | _owner = owner; | |
996b7c9d JH |
44 | } |
45 | ||
46 | void DevInst::release() | |
47 | { | |
48 | if (_owner) { | |
49 | _owner->release_device(this); | |
50 | _owner = NULL; | |
996b7c9d JH |
51 | } |
52 | } | |
53 | ||
54 | SigSession* DevInst::owner() const | |
55 | { | |
56 | return _owner; | |
57 | } | |
58 | ||
2445160a | 59 | GVariant* DevInst::get_config(const sr_channel_group *group, int key) |
8dd44190 JH |
60 | { |
61 | GVariant *data = NULL; | |
ae2d1bc5 | 62 | assert(_owner); |
29efe92a JH |
63 | sr_dev_inst *const sdi = dev_inst(); |
64 | assert(sdi); | |
65 | if (sr_config_get(sdi->driver, sdi, group, key, &data) != SR_OK) | |
8dd44190 JH |
66 | return NULL; |
67 | return data; | |
68 | } | |
69 | ||
2445160a | 70 | bool DevInst::set_config(const sr_channel_group *group, int key, GVariant *data) |
8dd44190 | 71 | { |
ae2d1bc5 | 72 | assert(_owner); |
29efe92a JH |
73 | sr_dev_inst *const sdi = dev_inst(); |
74 | assert(sdi); | |
75 | if(sr_config_set(sdi, group, key, data) == SR_OK) { | |
42e634cf JH |
76 | config_changed(); |
77 | return true; | |
78 | } | |
79 | return false; | |
8dd44190 JH |
80 | } |
81 | ||
2445160a | 82 | GVariant* DevInst::list_config(const sr_channel_group *group, int key) |
8dd44190 JH |
83 | { |
84 | GVariant *data = NULL; | |
ae2d1bc5 | 85 | assert(_owner); |
29efe92a JH |
86 | sr_dev_inst *const sdi = dev_inst(); |
87 | assert(sdi); | |
88 | if (sr_config_list(sdi->driver, sdi, group, key, &data) != SR_OK) | |
8dd44190 JH |
89 | return NULL; |
90 | return data; | |
91 | } | |
92 | ||
4871ed92 | 93 | void DevInst::enable_probe(const sr_channel *probe, bool enable) |
e183f4e3 | 94 | { |
ae2d1bc5 | 95 | assert(_owner); |
29efe92a JH |
96 | sr_dev_inst *const sdi = dev_inst(); |
97 | assert(sdi); | |
4871ed92 | 98 | for (const GSList *p = sdi->channels; p; p = p->next) |
e183f4e3 | 99 | if (probe == p->data) { |
4871ed92 | 100 | const_cast<sr_channel*>(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 | ||
07dcf561 JH |
122 | bool DevInst::is_trigger_enabled() const |
123 | { | |
124 | return false; | |
125 | } | |
126 | ||
ae2d1bc5 JH |
127 | void DevInst::start() |
128 | { | |
129 | if (sr_session_start() != SR_OK) | |
130 | throw tr("Failed to start session."); | |
131 | } | |
132 | ||
133 | void DevInst::run() | |
134 | { | |
135 | sr_session_run(); | |
136 | } | |
137 | ||
94574501 | 138 | } // device |
19adbc2c | 139 | } // pv |