]> sigrok.org Git - pulseview.git/blame - pv/prop/binding/hwcap.cpp
samplingbar: Replace sr_info_get(SR_DI_SAMPLERATES) with sr_config_list(SR_CONF_SAMPL...
[pulseview.git] / pv / prop / binding / hwcap.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
cf47ef78
JH
23#include "hwcap.h"
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
34HwCap::HwCap(struct sr_dev_inst *sdi) :
35 _sdi(sdi)
36{
7b3810db
JH
37 const int *hwcaps;
38
39 if ((sr_info_get(sdi->driver, SR_DI_HWCAPS, (const void **)&hwcaps,
40 sdi) != SR_OK) || !hwcaps)
41 /* Driver supports no device instance options. */
42 return;
43
44 for (int cap = 0; hwcaps[cap]; cap++) {
45 const struct sr_hwcap_option *const hwo =
46 sr_devopt_get(hwcaps[cap]);
47
48 if (!hwo)
49 continue;
50
51 switch(hwo->hwcap)
52 {
53 case SR_HWCAP_PATTERN_MODE:
54 bind_stropt(hwo, SR_DI_PATTERNS,
55 SR_HWCAP_PATTERN_MODE);
56 break;
57
58 case SR_HWCAP_BUFFERSIZE:
59 bind_buffer_size(hwo);
60 break;
61
62 case SR_HWCAP_TIMEBASE:
63 bind_time_base(hwo);
64 break;
65
66 case SR_HWCAP_TRIGGER_SOURCE:
67 bind_stropt(hwo, SR_DI_TRIGGER_SOURCES,
68 SR_HWCAP_TRIGGER_SOURCE);
69 break;
70
71 case SR_HWCAP_FILTER:
72 bind_stropt(hwo, SR_DI_FILTERS, SR_HWCAP_FILTER);
73 break;
74
75 case SR_HWCAP_VDIV:
76 bind_vdiv(hwo);
77 break;
78
79 case SR_HWCAP_COUPLING:
80 bind_stropt(hwo, SR_DI_COUPLING, SR_HWCAP_FILTER);
81 break;
82 }
83 }
84}
85
86void HwCap::expose_enum(const struct sr_hwcap_option *hwo,
87 const vector< pair<const void*, QString> > &values, int opt)
88{
89 _properties.push_back(shared_ptr<Property>(
90 new Enum(QString(hwo->shortname), values,
91 function<const void* ()>(),
92 bind(sr_dev_config_set, _sdi, opt, _1))));
93}
94
95void HwCap::bind_stropt(const struct sr_hwcap_option *hwo, int id, int opt)
96{
97 const char **stropts;
98 if (sr_info_get(_sdi->driver, id,
99 (const void **)&stropts, _sdi) != SR_OK)
100 return;
101
102 vector< pair<const void*, QString> > values;
103 for (int i = 0; stropts[i]; i++)
104 values.push_back(make_pair(stropts[i], stropts[i]));
105
106 expose_enum(hwo, values, opt);
107}
108
109void HwCap::bind_buffer_size(const struct sr_hwcap_option *hwo)
110{
111 const uint64_t *sizes;
112 if (sr_info_get(_sdi->driver, SR_DI_BUFFERSIZES,
113 (const void **)&sizes, _sdi) != SR_OK)
114 return;
115
116 vector< pair<const void*, QString> > values;
117 for (int i = 0; sizes[i]; i++)
118 values.push_back(make_pair(sizes + i,
119 QString("%1").arg(sizes[i])));
120
121 expose_enum(hwo, values, SR_HWCAP_BUFFERSIZE);
122}
123
124void HwCap::bind_time_base(const struct sr_hwcap_option *hwo)
125{
126 struct sr_rational *timebases;
127 if (sr_info_get(_sdi->driver, SR_DI_TIMEBASES,
128 (const void **)&timebases, _sdi) != SR_OK)
129 return;
130
131 vector< pair<const void*, QString> > values;
132 for (int i = 0; timebases[i].p && timebases[i].q; i++)
133 values.push_back(make_pair(timebases + i,
134 QString(sr_period_string(
135 timebases[i].p * timebases[i].q))));
136
137 expose_enum(hwo, values, SR_HWCAP_TIMEBASE);
138}
139
140void HwCap::bind_vdiv(const struct sr_hwcap_option *hwo)
141{
142 struct sr_rational *vdivs;
143 if (sr_info_get(_sdi->driver, SR_DI_VDIVS,
144 (const void **)&vdivs, _sdi) != SR_OK)
145 return;
146
147 vector< pair<const void*, QString> > values;
148 for (int i = 0; vdivs[i].p && vdivs[i].q; i++)
149 values.push_back(make_pair(vdivs + i,
150 QString(sr_voltage_string(vdivs + i))));
151
152 expose_enum(hwo, values, SR_HWCAP_VDIV);
cf47ef78
JH
153}
154
155} // binding
156} // prop
157} // pv
158