]> sigrok.org Git - libsigrok.git/blame - device.c
sr: remove obsolete driver API call dev_info_get()
[libsigrok.git] / device.c
CommitLineData
a1bb33af
UH
1/*
2 * This file is part of the sigrok project.
3 *
c73d2ea4 4 * Copyright (C) 2010-2012 Bert Vermeulen <bert@biot.com>
a1bb33af
UH
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 3 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, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <stdio.h>
21#include <glib.h>
45c59c8b
BV
22#include "libsigrok.h"
23#include "libsigrok-internal.h"
a1bb33af 24
94799bc4
UH
25/**
26 * Set the name of the specified probe in the specified device.
27 *
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.
30 *
37e8b4c4 31 * @param sdi The device instance the probe is connected to.
94799bc4 32 * @param probenum The number of the probe whose name to set.
37e8b4c4
BV
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.
0e3b1439 36 *
37e8b4c4 37 * @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
94799bc4 38 */
37e8b4c4
BV
39SR_API int sr_dev_probe_name_set(const struct sr_dev_inst *sdi,
40 int probenum, const char *name)
a1bb33af 41{
37e8b4c4
BV
42 GSList *l;
43 struct sr_probe *probe;
44 int ret;
a1bb33af 45
37e8b4c4
BV
46 if (!sdi) {
47 sr_err("%s: sdi was NULL", __func__);
0e3b1439 48 return SR_ERR_ARG;
94799bc4
UH
49 }
50
37e8b4c4
BV
51 ret = SR_ERR_ARG;
52 for (l = sdi->probes; l; l = l->next) {
53 probe = l->data;
54 if (probe->index == probenum) {
55 g_free(probe->name);
56 probe->name = g_strdup(name);
57 ret = SR_OK;
58 break;
59 }
94799bc4
UH
60 }
61
37e8b4c4 62 return ret;
a1bb33af
UH
63}
64
be5bf44d
BV
65/**
66 * Enable or disable a probe on the specified device.
67 *
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.
71 *
72 * @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
73 */
74SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum,
75 gboolean state)
76{
77 GSList *l;
78 struct sr_probe *probe;
79 int ret;
80
81 if (!sdi)
82 return SR_ERR_ARG;
83
84 ret = SR_ERR_ARG;
85 for (l = sdi->probes; l; l = l->next) {
86 probe = l->data;
87 if (probe->index == probenum) {
88 probe->enabled = state;
89 ret = SR_OK;
90 break;
91 }
92 }
93
94 return ret;
95}
96
94799bc4 97/**
01c3e9db
UH
98 * Add a trigger to the specified device (and the specified probe).
99 *
100 * If the specified probe of this device already has a trigger, it will
101 * be silently replaced.
94799bc4 102 *
c7ee3ddb 103 * @param sdi Must not be NULL.
a5f2e707
BV
104 * @param probenum The probe number, starting from 0.
105 * @param trigger Trigger string, in the format used by sigrok-cli
0e3b1439 106 *
a5f2e707 107 * @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
94799bc4 108 */
58453e58
BV
109SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
110 const char *trigger)
a1bb33af 111{
58453e58
BV
112 GSList *l;
113 struct sr_probe *probe;
114 int ret;
a1bb33af 115
58453e58 116 if (!sdi)
0e3b1439 117 return SR_ERR_ARG;
94799bc4 118
58453e58
BV
119 ret = SR_ERR_ARG;
120 for (l = sdi->probes; l; l = l->next) {
121 probe = l->data;
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);
126 ret = SR_OK;
127 break;
128 }
94799bc4 129 }
a1bb33af 130
58453e58 131 return ret;
7d658874
BV
132}
133
94799bc4
UH
134/**
135 * Determine whether the specified device has the specified capability.
136 *
a5b35a16 137 * @param dev Pointer to the device instance to be checked. Must not be NULL.
8ec95d22
UH
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).
94799bc4
UH
141 * @param hwcap The capability that should be checked (whether it's supported
142 * by the specified device).
143 *
a5f2e707 144 * @return TRUE if the device has the specified capability, FALSE otherwise.
94799bc4
UH
145 * FALSE is also returned upon invalid input parameters or other
146 * error conditions.
147 */
a5b35a16 148SR_API gboolean sr_dev_has_hwcap(const struct sr_dev_inst *sdi, int hwcap)
7d658874 149{
915f7cc8
JH
150 const int *hwcaps;
151 int i;
7d658874 152
a5b35a16 153 if (!sdi || !sdi->driver)
8ec95d22 154 return FALSE;
94799bc4 155
a5b35a16
BV
156 if (sdi->driver->info_get(SR_DI_HWCAPS,
157 (const void **)&hwcaps, NULL) != SR_OK)
8ec95d22 158 return FALSE;
94799bc4 159
ffedd0bf 160 for (i = 0; hwcaps[i]; i++) {
a5b35a16
BV
161 if (hwcaps[i] == hwcap)
162 return TRUE;
94799bc4 163 }
218557b8 164
7d658874 165 return FALSE;
a1bb33af 166}
fd9836bf 167