]> sigrok.org Git - libsigrok.git/commitdiff
arachnid-labs-re-load-pro: Add support for setting SR_CONF_ENABLED.
authorUwe Hermann <redacted>
Mon, 8 Feb 2016 07:52:23 +0000 (08:52 +0100)
committerUwe Hermann <redacted>
Thu, 11 Feb 2016 13:42:50 +0000 (14:42 +0100)
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.

src/hardware/arachnid-labs-re-load-pro/api.c
src/hardware/arachnid-labs-re-load-pro/protocol.c
src/hardware/arachnid-labs-re-load-pro/protocol.h

index bf6917e78ae240ccd646f075e2505ebebbd14410..dde8166365333c51e3e067933fac377e7b24f2d1 100644 (file)
@@ -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));
index 697f75a0890500dff958bbe79531df3c0dfe01ba..1f2e0dd4ecd212493ff1a2213efec26a8a75d4a5 100644 (file)
@@ -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)
 {
index 25ceff58d8317f026975730c5351af0891a8f490..94b62691c9e179f3a4cf4b259585db360d7b671d 100644 (file)
@@ -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,