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