* @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.
+ * @return SR_OK on success or SR_ERR on failure. In case of invalid
+ * arguments, SR_ERR_ARG is returned and the probe enabled state
+ * remains unchanged.
*
* @since 0.2.0
*/
GSList *l;
struct sr_probe *probe;
int ret;
+ gboolean was_enabled;
if (!sdi)
return SR_ERR_ARG;
for (l = sdi->probes; l; l = l->next) {
probe = l->data;
if (probe->index == probenum) {
+ was_enabled = probe->enabled;
probe->enabled = state;
ret = SR_OK;
+ if (!state != !was_enabled && sdi->driver
+ && sdi->driver->config_probe_set) {
+ ret = sdi->driver->config_probe_set(
+ sdi, probe, SR_PROBE_SET_ENABLED);
+ /* Roll back change if it wasn't applicable. */
+ if (ret == SR_ERR_ARG)
+ probe->enabled = was_enabled;
+ }
break;
}
}
* @param[in] probenum Number of probe, starting at 0.
* @param[in] trigger Trigger string, in the format used by sigrok-cli
*
- * @return SR_OK on success, or SR_ERR_ARG on invalid arguments.
+ * @return SR_OK on success or SR_ERR on failure. In case of invalid
+ * arguments, SR_ERR_ARG is returned and the trigger settings
+ * remain unchanged.
*
* @since 0.2.0
*/
{
GSList *l;
struct sr_probe *probe;
+ char *old_trigger;
int ret;
if (!sdi)
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);
+ old_trigger = probe->trigger;
ret = SR_OK;
+ if (g_strcmp0(trigger, old_trigger) == 0)
+ break;
+ /* Set new trigger if it has changed. */
+ probe->trigger = g_strdup(trigger);
+
+ if (sdi->driver && sdi->driver->config_probe_set) {
+ ret = sdi->driver->config_probe_set(
+ sdi, probe, SR_PROBE_SET_TRIGGER);
+ /* Roll back change if it wasn't applicable. */
+ if (ret == SR_ERR_ARG) {
+ g_free(probe->trigger);
+ probe->trigger = old_trigger;
+ break;
+ }
+ }
+ g_free(old_trigger);
break;
}
}
return ret;
}
+/**
+ * Apply configuration settings to the device hardware.
+ *
+ * @param sdi The device instance.
+ *
+ * @return SR_OK upon success or SR_ERR in case of error.
+ */
+SR_API int sr_config_commit(const struct sr_dev_inst *sdi)
+{
+ int ret;
+
+ if (!sdi || !sdi->driver)
+ ret = SR_ERR;
+ else if (!sdi->driver->config_commit)
+ ret = SR_OK;
+ else
+ ret = sdi->driver->config_commit(sdi);
+
+ return ret;
+}
+
/**
* List all possible values for a configuration key.
*
/*--- device.c --------------------------------------------------------------*/
+/** Values for the changes argument of sr_dev_driver.config_probe_set. */
+enum {
+ /** The enabled state of the probe has been changed. */
+ SR_PROBE_SET_ENABLED = 1 << 0,
+ /** The trigger setup of the probe has been changed. */
+ SR_PROBE_SET_TRIGGER = 1 << 1,
+};
+
SR_PRIV struct sr_probe *sr_probe_new(int index, int type,
gboolean enabled, const char *name);
int (*config_set) (int id, GVariant *data,
const struct sr_dev_inst *sdi,
const struct sr_probe_group *probe_group);
+ int (*config_probe_set) (const struct sr_dev_inst *sdi,
+ struct sr_probe *probe, unsigned int changes);
+ int (*config_commit) (const struct sr_dev_inst *sdi);
int (*config_list) (int info_id, GVariant **data,
const struct sr_dev_inst *sdi,
const struct sr_probe_group *probe_group);
SR_API int sr_config_set(const struct sr_dev_inst *sdi,
const struct sr_probe_group *probe_group,
int key, GVariant *data);
+SR_API int sr_config_commit(const struct sr_dev_inst *sdi);
SR_API int sr_config_list(const struct sr_dev_driver *driver,
const struct sr_dev_inst *sdi,
const struct sr_probe_group *probe_group,