- for (i = 0; i < num_probes; i++) {
- snprintf(probename, 16, "%d", i + 1);
- device_probe_add(device, probename);
+/**
+ * Add a trigger to the specified device (and the specified probe).
+ *
+ * If the specified probe of this device already has a trigger, it will
+ * be silently replaced.
+ *
+ * @param sdi Must not be NULL.
+ * @param probenum The probe number, starting from 0.
+ * @param trigger Trigger string, in the format used by sigrok-cli
+ *
+ * @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
+ */
+SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
+ const char *trigger)
+{
+ GSList *l;
+ struct sr_probe *probe;
+ int ret;
+
+ if (!sdi)
+ return SR_ERR_ARG;
+
+ ret = SR_ERR_ARG;
+ for (l = sdi->probes; l; l = l->next) {
+ probe = l->data;
+ if (probe->index == probenum) {
+ /* If the probe already has a trigger, kill it first. */
+ g_free(probe->trigger);
+ probe->trigger = g_strdup(trigger);
+ ret = SR_OK;
+ break;
+ }