]>
Commit | Line | Data |
---|---|---|
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 | * | |
bb7ef793 | 31 | * @param dev TODO |
94799bc4 UH |
32 | * @param probenum The number of the probe whose name to set. |
33 | * Note that the probe numbers start at 1 (not 0!). | |
34 | * @param name The new name that the specified probe should get. | |
0e3b1439 UH |
35 | * |
36 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments, or SR_ERR | |
37 | * upon other errors. | |
bb7ef793 | 38 | * If something other than SR_OK is returned, 'dev' is unchanged. |
94799bc4 | 39 | */ |
2f8cf274 UH |
40 | SR_API int sr_dev_probe_name_set(struct sr_dev *dev, int probenum, |
41 | const char *name) | |
a1bb33af | 42 | { |
1afe8989 | 43 | struct sr_probe *p; |
a1bb33af | 44 | |
bb7ef793 UH |
45 | if (!dev) { |
46 | sr_err("dev: %s: dev was NULL", __func__); | |
0e3b1439 | 47 | return SR_ERR_ARG; |
94799bc4 UH |
48 | } |
49 | ||
bb7ef793 | 50 | p = sr_dev_probe_find(dev, probenum); |
94799bc4 UH |
51 | if (!p) { |
52 | sr_err("dev: %s: probe %d not found", __func__, probenum); | |
0e3b1439 | 53 | return SR_ERR; /* TODO: More specific error? */ |
94799bc4 UH |
54 | } |
55 | ||
56 | /* TODO: Sanity check on 'name'. */ | |
a1bb33af | 57 | |
94799bc4 | 58 | /* If the probe already has a name, kill it first. */ |
66410a86 | 59 | g_free(p->name); |
94799bc4 | 60 | |
a1bb33af | 61 | p->name = g_strdup(name); |
0e3b1439 UH |
62 | |
63 | return SR_OK; | |
a1bb33af UH |
64 | } |
65 | ||
be5bf44d BV |
66 | /** |
67 | * Enable or disable a probe on the specified device. | |
68 | * | |
69 | * @param sdi The device instance the probe is connected to. | |
70 | * @param probenum The probe number, starting from 0. | |
71 | * @param state TRUE to enable the probe, FALSE to disable. | |
72 | * | |
73 | * @return SR_OK on success, or SR_ERR_ARG on invalid arguments. | |
74 | */ | |
75 | SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum, | |
76 | gboolean state) | |
77 | { | |
78 | GSList *l; | |
79 | struct sr_probe *probe; | |
80 | int ret; | |
81 | ||
82 | if (!sdi) | |
83 | return SR_ERR_ARG; | |
84 | ||
85 | ret = SR_ERR_ARG; | |
86 | for (l = sdi->probes; l; l = l->next) { | |
87 | probe = l->data; | |
88 | if (probe->index == probenum) { | |
89 | probe->enabled = state; | |
90 | ret = SR_OK; | |
91 | break; | |
92 | } | |
93 | } | |
94 | ||
95 | return ret; | |
96 | } | |
97 | ||
94799bc4 | 98 | /** |
01c3e9db UH |
99 | * Add a trigger to the specified device (and the specified probe). |
100 | * | |
101 | * If the specified probe of this device already has a trigger, it will | |
102 | * be silently replaced. | |
94799bc4 | 103 | * |
c7ee3ddb BV |
104 | * @param sdi Must not be NULL. |
105 | * @param probenum The number of the probe. | |
94799bc4 | 106 | * Note that the probe numbers start at 1 (not 0!). |
c7ee3ddb | 107 | * @param trigger trigger string, in the format used by sigrok-cli |
0e3b1439 | 108 | * |
c7ee3ddb | 109 | * @return SR_OK upon success, SR_ERR_ARG upon invalid arguments. |
94799bc4 | 110 | */ |
58453e58 BV |
111 | SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum, |
112 | const char *trigger) | |
a1bb33af | 113 | { |
58453e58 BV |
114 | GSList *l; |
115 | struct sr_probe *probe; | |
116 | int ret; | |
a1bb33af | 117 | |
58453e58 | 118 | if (!sdi) |
0e3b1439 | 119 | return SR_ERR_ARG; |
94799bc4 | 120 | |
58453e58 BV |
121 | ret = SR_ERR_ARG; |
122 | for (l = sdi->probes; l; l = l->next) { | |
123 | probe = l->data; | |
124 | if (probe->index == probenum) { | |
125 | /* If the probe already has a trigger, kill it first. */ | |
126 | g_free(probe->trigger); | |
127 | probe->trigger = g_strdup(trigger); | |
128 | ret = SR_OK; | |
129 | break; | |
130 | } | |
94799bc4 | 131 | } |
a1bb33af | 132 | |
58453e58 | 133 | return ret; |
7d658874 BV |
134 | } |
135 | ||
94799bc4 UH |
136 | /** |
137 | * Determine whether the specified device has the specified capability. | |
138 | * | |
a5b35a16 | 139 | * @param dev Pointer to the device instance to be checked. Must not be NULL. |
8ec95d22 UH |
140 | * If the device's 'driver' field is NULL (virtual device), this |
141 | * function will always return FALSE (virtual devices don't have | |
142 | * a hardware capabilities list). | |
94799bc4 UH |
143 | * @param hwcap The capability that should be checked (whether it's supported |
144 | * by the specified device). | |
145 | * | |
146 | * @return TRUE, if the device has the specified capability, FALSE otherwise. | |
147 | * FALSE is also returned upon invalid input parameters or other | |
148 | * error conditions. | |
149 | */ | |
a5b35a16 | 150 | SR_API gboolean sr_dev_has_hwcap(const struct sr_dev_inst *sdi, int hwcap) |
7d658874 | 151 | { |
915f7cc8 JH |
152 | const int *hwcaps; |
153 | int i; | |
7d658874 | 154 | |
a5b35a16 | 155 | if (!sdi || !sdi->driver) |
8ec95d22 | 156 | return FALSE; |
94799bc4 | 157 | |
a5b35a16 BV |
158 | if (sdi->driver->info_get(SR_DI_HWCAPS, |
159 | (const void **)&hwcaps, NULL) != SR_OK) | |
8ec95d22 | 160 | return FALSE; |
94799bc4 | 161 | |
ffedd0bf | 162 | for (i = 0; hwcaps[i]; i++) { |
a5b35a16 BV |
163 | if (hwcaps[i] == hwcap) |
164 | return TRUE; | |
94799bc4 | 165 | } |
218557b8 | 166 | |
7d658874 | 167 | return FALSE; |
a1bb33af | 168 | } |
fd9836bf | 169 |