2 * This file is part of the sigrok project.
4 * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
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 3 of the License, or
9 * (at your option) any later version.
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.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 #include "libsigrok.h"
23 #include "libsigrok-internal.h"
26 * Set the name of the specified probe in the specified device.
28 * If the probe already has a different name assigned to it, it will be
29 * removed, and the new name will be saved instead.
31 * @param sdi The device instance the probe is connected to.
32 * @param probenum The number of the probe whose name to set.
33 * Note that the probe numbers start at 0.
34 * @param name The new name that the specified probe should get. A copy
35 * of the string is made.
37 * @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
39 SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi,
40 int probenum, const char *name)
43 struct sr_probe *probe;
47 sr_err("%s: sdi was NULL", __func__);
52 for (l = sdi->probes; l; l = l->next) {
54 if (probe->index == probenum) {
56 probe->name = g_strdup(name);
66 * Enable or disable a probe on the specified device.
68 * @param sdi The device instance the probe is connected to.
69 * @param probenum The probe number, starting from 0.
70 * @param state TRUE to enable the probe, FALSE to disable.
72 * @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
74 SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum,
78 struct sr_probe *probe;
85 for (l = sdi->probes; l; l = l->next) {
87 if (probe->index == probenum) {
88 probe->enabled = state;
98 * Add a trigger to the specified device (and the specified probe).
100 * If the specified probe of this device already has a trigger, it will
101 * be silently replaced.
103 * @param sdi Must not be NULL.
104 * @param probenum The probe number, starting from 0.
105 * @param trigger Trigger string, in the format used by sigrok-cli
107 * @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
109 SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
113 struct sr_probe *probe;
120 for (l = sdi->probes; l; l = l->next) {
122 if (probe->index == probenum) {
123 /* If the probe already has a trigger, kill it first. */
124 g_free(probe->trigger);
125 probe->trigger = g_strdup(trigger);
135 * Determine whether the specified device has the specified capability.
137 * @param dev Pointer to the device instance to be checked. Must not be NULL.
138 * If the device's 'driver' field is NULL (virtual device), this
139 * function will always return FALSE (virtual devices don't have
140 * a hardware capabilities list).
141 * @param hwcap The capability that should be checked (whether it's supported
142 * by the specified device).
144 * @return TRUE if the device has the specified capability, FALSE otherwise.
145 * FALSE is also returned upon invalid input parameters or other
148 SR_API gboolean sr_dev_has_hwcap(const struct sr_dev_inst *sdi, int hwcap)
153 if (!sdi || !sdi->driver)
156 if (sdi->driver->info_get(SR_DI_HWCAPS,
157 (const void **)&hwcaps, NULL) != SR_OK)
160 for (i = 0; hwcaps[i]; i++) {
161 if (hwcaps[i] == hwcap)