From: Uwe Hermann Date: Mon, 8 Feb 2016 07:52:23 +0000 (+0100) Subject: arachnid-labs-re-load-pro: Add support for setting SR_CONF_ENABLED. X-Git-Tag: libsigrok-0.5.0~563 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8501448cfe508de842c0e2206232a7a832837294;p=libsigrok.git arachnid-labs-re-load-pro: Add support for setting SR_CONF_ENABLED. The firmware has "on\n" and "off\n" commands since 1.10, so use them. Apparently you can only set the state (on/off) of the load, but it's not possible to query the current state. --- diff --git a/src/hardware/arachnid-labs-re-load-pro/api.c b/src/hardware/arachnid-labs-re-load-pro/api.c index bf6917e7..dde81663 100644 --- a/src/hardware/arachnid-labs-re-load-pro/api.c +++ b/src/hardware/arachnid-labs-re-load-pro/api.c @@ -43,7 +43,7 @@ static const uint32_t devopts[] = { }; static const uint32_t devopts_cg[] = { - SR_CONF_ENABLED | SR_CONF_GET, + SR_CONF_ENABLED | SR_CONF_SET, SR_CONF_REGULATION | SR_CONF_GET, SR_CONF_VOLTAGE | SR_CONF_GET, SR_CONF_CURRENT | SR_CONF_GET, @@ -242,6 +242,7 @@ static int config_get(uint32_t key, GVariant **data, * - SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD * - SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE * - SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD + * - SR_CONF_ENABLED (state cannot be queried, only set) */ ret = SR_OK; @@ -252,9 +253,6 @@ static int config_get(uint32_t key, GVariant **data, case SR_CONF_LIMIT_MSEC: *data = g_variant_new_uint64(devc->limit_msec); break; - case SR_CONF_ENABLED: - *data = g_variant_new_boolean(TRUE); /* Always on. */ - break; case SR_CONF_REGULATION: *data = g_variant_new_string("CC"); /* Always CC mode. */ break; @@ -312,6 +310,9 @@ static int config_set(uint32_t key, GVariant *data, case SR_CONF_LIMIT_MSEC: devc->limit_msec = g_variant_get_uint64(data); break; + case SR_CONF_ENABLED: + ret = reloadpro_set_on_off(sdi, g_variant_get_boolean(data)); + break; case SR_CONF_CURRENT_LIMIT: ret = reloadpro_set_current_limit(sdi, g_variant_get_double(data)); diff --git a/src/hardware/arachnid-labs-re-load-pro/protocol.c b/src/hardware/arachnid-labs-re-load-pro/protocol.c index 697f75a0..1f2e0dd4 100644 --- a/src/hardware/arachnid-labs-re-load-pro/protocol.c +++ b/src/hardware/arachnid-labs-re-load-pro/protocol.c @@ -89,6 +89,21 @@ SR_PRIV int reloadpro_set_current_limit(const struct sr_dev_inst *sdi, return SR_OK; } +SR_PRIV int reloadpro_set_on_off(const struct sr_dev_inst *sdi, gboolean on) +{ + int ret; + char buf[100]; + const char *cmd; + + cmd = (on) ? "on\n" : "off\n"; + if ((ret = send_cmd(sdi, cmd, (char *)&buf, sizeof(buf))) < 0) { + sr_err("Error sending on/off command: %d.", ret); + return SR_ERR; + } + + return SR_OK; +} + SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi, float *current) { diff --git a/src/hardware/arachnid-labs-re-load-pro/protocol.h b/src/hardware/arachnid-labs-re-load-pro/protocol.h index 25ceff58..94b62691 100644 --- a/src/hardware/arachnid-labs-re-load-pro/protocol.h +++ b/src/hardware/arachnid-labs-re-load-pro/protocol.h @@ -43,6 +43,7 @@ struct dev_context { SR_PRIV int reloadpro_set_current_limit(const struct sr_dev_inst *sdi, float current); +SR_PRIV int reloadpro_set_on_off(const struct sr_dev_inst *sdi, gboolean on); SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi, float *current); SR_PRIV int reloadpro_get_voltage_current(const struct sr_dev_inst *sdi,