]>
Commit | Line | Data |
---|---|---|
cf47ef78 JH |
1 | /* |
2 | * This file is part of the PulseView project. | |
3 | * | |
4 | * Copyright (C) 2012 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 | ||
7b3810db JH |
21 | #include <boost/bind.hpp> |
22 | ||
d71bca8b JH |
23 | #include <QDebug> |
24 | ||
3820592a | 25 | #include "deviceoptions.h" |
cf47ef78 | 26 | |
7b3810db JH |
27 | #include <pv/prop/enum.h> |
28 | ||
29 | using namespace boost; | |
30 | using namespace std; | |
31 | ||
cf47ef78 JH |
32 | namespace pv { |
33 | namespace prop { | |
34 | namespace binding { | |
35 | ||
3820592a | 36 | DeviceOptions::DeviceOptions(struct sr_dev_inst *sdi) : |
cf47ef78 JH |
37 | _sdi(sdi) |
38 | { | |
10b1be92 | 39 | const int *options; |
7b3810db | 40 | |
10b1be92 JH |
41 | if ((sr_config_list(sdi->driver, SR_CONF_DEVICE_OPTIONS, |
42 | (const void **)&options, sdi) != SR_OK) || !options) | |
7b3810db JH |
43 | /* Driver supports no device instance options. */ |
44 | return; | |
45 | ||
10b1be92 JH |
46 | for (int cap = 0; options[cap]; cap++) { |
47 | const struct sr_config_info *const info = | |
48 | sr_config_info_get(options[cap]); | |
7b3810db | 49 | |
10b1be92 | 50 | if (!info) |
7b3810db JH |
51 | continue; |
52 | ||
10b1be92 | 53 | switch(info->key) |
7b3810db | 54 | { |
10b1be92 JH |
55 | case SR_CONF_PATTERN_MODE: |
56 | bind_stropt(info, SR_CONF_PATTERN_MODE); | |
7b3810db JH |
57 | break; |
58 | ||
10b1be92 JH |
59 | case SR_CONF_BUFFERSIZE: |
60 | bind_buffer_size(info); | |
7b3810db JH |
61 | break; |
62 | ||
10b1be92 JH |
63 | case SR_CONF_TIMEBASE: |
64 | bind_time_base(info); | |
7b3810db JH |
65 | break; |
66 | ||
10b1be92 JH |
67 | case SR_CONF_TRIGGER_SOURCE: |
68 | bind_stropt(info, SR_CONF_TRIGGER_SOURCE); | |
7b3810db JH |
69 | break; |
70 | ||
10b1be92 JH |
71 | case SR_CONF_FILTER: |
72 | bind_stropt(info, SR_CONF_FILTER); | |
7b3810db JH |
73 | break; |
74 | ||
10b1be92 JH |
75 | case SR_CONF_VDIV: |
76 | bind_vdiv(info); | |
7b3810db JH |
77 | break; |
78 | ||
10b1be92 JH |
79 | case SR_CONF_COUPLING: |
80 | bind_stropt(info, SR_CONF_FILTER); | |
7b3810db JH |
81 | break; |
82 | } | |
83 | } | |
84 | } | |
85 | ||
3820592a | 86 | void DeviceOptions::expose_enum(const struct sr_config_info *info, |
10b1be92 | 87 | const vector< pair<const void*, QString> > &values, int key) |
7b3810db JH |
88 | { |
89 | _properties.push_back(shared_ptr<Property>( | |
10b1be92 | 90 | new Enum(QString(info->name), values, |
d71bca8b | 91 | bind(getter, _sdi, key), |
10b1be92 | 92 | bind(sr_config_set, _sdi, key, _1)))); |
7b3810db JH |
93 | } |
94 | ||
3820592a JH |
95 | void DeviceOptions::bind_stropt( |
96 | const struct sr_config_info *info, int key) | |
7b3810db JH |
97 | { |
98 | const char **stropts; | |
10b1be92 | 99 | if (sr_config_list(_sdi->driver, key, |
7b3810db JH |
100 | (const void **)&stropts, _sdi) != SR_OK) |
101 | return; | |
102 | ||
103 | vector< pair<const void*, QString> > values; | |
104 | for (int i = 0; stropts[i]; i++) | |
105 | values.push_back(make_pair(stropts[i], stropts[i])); | |
106 | ||
10b1be92 | 107 | expose_enum(info, values, key); |
7b3810db JH |
108 | } |
109 | ||
3820592a | 110 | void DeviceOptions::bind_buffer_size(const struct sr_config_info *info) |
7b3810db JH |
111 | { |
112 | const uint64_t *sizes; | |
10b1be92 | 113 | if (sr_config_list(_sdi->driver, SR_CONF_BUFFERSIZE, |
7b3810db JH |
114 | (const void **)&sizes, _sdi) != SR_OK) |
115 | return; | |
116 | ||
117 | vector< pair<const void*, QString> > values; | |
118 | for (int i = 0; sizes[i]; i++) | |
119 | values.push_back(make_pair(sizes + i, | |
120 | QString("%1").arg(sizes[i]))); | |
121 | ||
10b1be92 | 122 | expose_enum(info, values, SR_CONF_BUFFERSIZE); |
7b3810db JH |
123 | } |
124 | ||
3820592a | 125 | void DeviceOptions::bind_time_base(const struct sr_config_info *info) |
7b3810db JH |
126 | { |
127 | struct sr_rational *timebases; | |
10b1be92 | 128 | if (sr_config_list(_sdi->driver, SR_CONF_TIMEBASE, |
7b3810db JH |
129 | (const void **)&timebases, _sdi) != SR_OK) |
130 | return; | |
131 | ||
132 | vector< pair<const void*, QString> > values; | |
133 | for (int i = 0; timebases[i].p && timebases[i].q; i++) | |
134 | values.push_back(make_pair(timebases + i, | |
135 | QString(sr_period_string( | |
136 | timebases[i].p * timebases[i].q)))); | |
137 | ||
10b1be92 | 138 | expose_enum(info, values, SR_CONF_TIMEBASE); |
7b3810db JH |
139 | } |
140 | ||
3820592a | 141 | void DeviceOptions::bind_vdiv(const struct sr_config_info *info) |
7b3810db JH |
142 | { |
143 | struct sr_rational *vdivs; | |
10b1be92 | 144 | if (sr_config_list(_sdi->driver, SR_CONF_VDIV, |
7b3810db JH |
145 | (const void **)&vdivs, _sdi) != SR_OK) |
146 | return; | |
147 | ||
148 | vector< pair<const void*, QString> > values; | |
149 | for (int i = 0; vdivs[i].p && vdivs[i].q; i++) | |
150 | values.push_back(make_pair(vdivs + i, | |
151 | QString(sr_voltage_string(vdivs + i)))); | |
152 | ||
10b1be92 | 153 | expose_enum(info, values, SR_CONF_VDIV); |
cf47ef78 JH |
154 | } |
155 | ||
d71bca8b JH |
156 | const void* DeviceOptions::enum_getter( |
157 | const struct sr_dev_inst *sdi, int key) | |
158 | { | |
159 | const void *data = NULL; | |
160 | if(sr_config_get(sdi->driver, key, &data, sdi) != SR_OK) { | |
161 | qDebug() << | |
162 | "WARNING: Failed to get value of config id" << key; | |
163 | return NULL; | |
164 | } | |
165 | return data; | |
166 | } | |
167 | ||
cf47ef78 JH |
168 | } // binding |
169 | } // prop | |
170 | } // pv | |
171 |