]> sigrok.org Git - libsigrok.git/commitdiff
sr: add sr_dev_probe_enable(), abstraction wrapper around device probes
authorBert Vermeulen <redacted>
Sun, 22 Jul 2012 10:23:59 +0000 (12:23 +0200)
committerBert Vermeulen <redacted>
Fri, 3 Aug 2012 09:27:31 +0000 (11:27 +0200)
device.c
proto.h
session_file.c

index e6372ff22cdcbbeb34f01a832c12b1556cd01cf3..be647fb248e7be173810a439fe543d41fb10d59a 100644 (file)
--- a/device.c
+++ b/device.c
@@ -273,6 +273,38 @@ SR_API int sr_dev_probe_name_set(struct sr_dev *dev, int probenum,
        return SR_OK;
 }
 
+/**
+ * Enable or disable a probe on the specified device.
+ *
+ * @param sdi The device instance the probe is connected to.
+ * @param probenum The probe number, starting from 0.
+ * @param state TRUE to enable the probe, FALSE to disable.
+ *
+ * @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
+ */
+SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum,
+               gboolean state)
+{
+       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) {
+                       probe->enabled = state;
+                       ret = SR_OK;
+                       break;
+               }
+       }
+
+       return ret;
+}
+
 /**
  * Remove all triggers set up for the specified device.
  *
diff --git a/proto.h b/proto.h
index d25ce2ec86700ebaf7551bf536bf1a2c2a1846ea..3b69c3480b1e04739315f8049eef5bf2dccc8283 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -56,6 +56,8 @@ SR_API struct sr_probe *sr_dev_probe_find(const struct sr_dev *dev,
                                          int probenum);
 SR_API int sr_dev_probe_name_set(struct sr_dev *dev, int probenum,
                                 const char *name);
+SR_API int sr_dev_probe_enable(const struct sr_dev_inst *sdi, int probenum,
+               gboolean state);
 SR_API int sr_dev_trigger_remove_all(struct sr_dev *dev);
 SR_API int sr_dev_trigger_set(const struct sr_dev_inst *sdi, int probenum,
                const char *trigger);
index 91890d31a9c6ea7b83390a7772ba64eed385107b..d90595eb4d31fe9aa5e899e906ad893a6bebd5c3 100644 (file)
@@ -151,10 +151,8 @@ SR_API int sr_session_load(const char *filename)
                                }
                        }
                        g_strfreev(keys);
-                       for (p = enabled_probes; p < total_probes; p++) {
-                               probe = g_slist_nth_data(dev->probes, p);
-                               probe->enabled = FALSE;
-                       }
+                       for (p = enabled_probes; p < total_probes; p++)
+                               sr_dev_probe_enable(sdi, p, FALSE);
                }
                devcnt++;
        }