]> sigrok.org Git - libsigrok.git/commitdiff
arachnid-labs-re-load-pro: Add SR_CONF_UNDER_VOLTAGE_THRESHOLD.
authorFrank Stettner <redacted>
Mon, 20 Nov 2017 14:20:58 +0000 (15:20 +0100)
committerUwe Hermann <redacted>
Sat, 3 Mar 2018 18:10:51 +0000 (19:10 +0100)
include/libsigrok/libsigrok.h
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
src/hwdriver.c

index ad01ffc2a42ded4b1447aab8fcdc5a7015f83176..6ab0ea2c6f333e33c76ade4fd401cac9592ff05e 100644 (file)
@@ -983,6 +983,9 @@ enum sr_configkey {
        /** Under-voltage condition active. */
        SR_CONF_UNDER_VOLTAGE_CONDITION_ACTIVE,
 
+       /** Under-voltage condition threshold. */
+       SR_CONF_UNDER_VOLTAGE_CONDITION_THRESHOLD,
+
        /** Trigger level. */
        SR_CONF_TRIGGER_LEVEL,
 
index d24076e566196fe0796099ae7460f5591ffcfa3e..1b7b8698681aff4d865d9de6e34b266bdbee7949 100644 (file)
@@ -54,6 +54,7 @@ static const uint32_t devopts_cg[] = {
        SR_CONF_OVER_TEMPERATURE_PROTECTION_ACTIVE | SR_CONF_GET,
        SR_CONF_UNDER_VOLTAGE_CONDITION | SR_CONF_GET,
        SR_CONF_UNDER_VOLTAGE_CONDITION_ACTIVE | SR_CONF_GET,
+       SR_CONF_UNDER_VOLTAGE_CONDITION_THRESHOLD | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
 };
 
 static GSList *scan(struct sr_dev_driver *di, GSList *options)
@@ -174,6 +175,9 @@ static int config_list(uint32_t key, GVariant **data,
                case SR_CONF_CURRENT_LIMIT:
                        *data = std_gvar_min_max_step(0.0, 6.0, 0.001);
                        break;
+               case SR_CONF_UNDER_VOLTAGE_CONDITION_THRESHOLD:
+                       *data = std_gvar_min_max_step(0.0, 60.0, 0.001);
+                       break;
                default:
                        return SR_ERR_NA;
                }
@@ -235,11 +239,20 @@ static int config_get(uint32_t key, GVariant **data,
                *data = g_variant_new_boolean(devc->otp_active);
                break;
        case SR_CONF_UNDER_VOLTAGE_CONDITION:
-               *data = g_variant_new_boolean(TRUE); /* Always on. */
+               if (reloadpro_get_under_voltage_threshold(sdi, &fvalue) == SR_OK) {
+                       if (fvalue == .0)
+                               *data = g_variant_new_boolean(FALSE);
+                       else
+                               *data = g_variant_new_boolean(TRUE);
+               }
                break;
        case SR_CONF_UNDER_VOLTAGE_CONDITION_ACTIVE:
                *data = g_variant_new_boolean(devc->uvc_active);
                break;
+       case SR_CONF_UNDER_VOLTAGE_CONDITION_THRESHOLD:
+               if (reloadpro_get_under_voltage_threshold(sdi, &fvalue) == SR_OK)
+                       *data = g_variant_new_double(fvalue);
+               break;
        default:
                return SR_ERR_NA;
        }
@@ -264,6 +277,9 @@ static int config_set(uint32_t key, GVariant *data,
                return reloadpro_set_on_off(sdi, g_variant_get_boolean(data));
        case SR_CONF_CURRENT_LIMIT:
                return reloadpro_set_current_limit(sdi, g_variant_get_double(data));
+       case SR_CONF_UNDER_VOLTAGE_CONDITION_THRESHOLD:
+               return reloadpro_set_under_voltage_threshold(sdi,
+                       g_variant_get_double(data));
        default:
                return SR_ERR_NA;
        }
index e704b16f95b3b2f8cd1c9854ba7eefffe217ccf6..31c51581e4c7849551e5198c64bc5dc1222b6fbd 100644 (file)
@@ -80,7 +80,7 @@ SR_PRIV int reloadpro_set_current_limit(const struct sr_dev_inst *sdi,
        /* Hardware expects current in mA, integer (0..6000). */
        ma = (int)round(current * 1000);
 
-       sr_err("Setting current limit to %f A (%d mA).", current, ma);
+       sr_spew("Setting current limit to %f A (%d mA).", current, ma);
 
        cmd = g_strdup_printf("set %d\n", ma);
        if ((ret = send_cmd(sdi, cmd, (char *)&buf, sizeof(buf))) < 0) {
@@ -108,6 +108,35 @@ SR_PRIV int reloadpro_set_on_off(const struct sr_dev_inst *sdi, gboolean on)
        return SR_OK;
 }
 
+SR_PRIV int reloadpro_set_under_voltage_threshold(const struct sr_dev_inst *sdi,
+                                       float voltage)
+{
+       int ret, mv;
+       char buf[100];
+       char *cmd;
+
+       if (voltage < 0 || voltage > 60) {
+               sr_err("The under voltage threshold must be 0-60 V (was %f V).",
+                       voltage);
+               return SR_ERR_ARG;
+       }
+
+       /* Hardware expects voltage in mV, integer (0..60000). */
+       mv = (int)round(voltage * 1000);
+
+       sr_spew("Setting under voltage threshold to %f V (%d mV).", voltage, mv);
+
+       cmd = g_strdup_printf("uvlo %d\n", mv);
+       if ((ret = send_cmd(sdi, cmd, (char *)&buf, sizeof(buf))) < 0) {
+               sr_err("Error sending under voltage threshold command: %d.", ret);
+               g_free(cmd);
+               return SR_ERR;
+       }
+       g_free(cmd);
+
+       return SR_OK;
+}
+
 SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi,
                                        float *current)
 {
@@ -130,6 +159,28 @@ SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi,
        return SR_OK;
 }
 
+SR_PRIV int reloadpro_get_under_voltage_threshold(const struct sr_dev_inst *sdi,
+                                       float *voltage)
+{
+       int ret;
+       char buf[100];
+       struct dev_context *devc;
+
+       devc = sdi->priv;
+
+       if ((ret = send_cmd(sdi, "uvlo\n", (char *)&buf, sizeof(buf))) < 0) {
+               sr_err("Error sending under voltage threshold query: %d.", ret);
+               return SR_ERR;
+       }
+
+       if (!devc->acquisition_running) {
+               /* Hardware sends voltage in mV, integer (0..60000). */
+               *voltage = g_ascii_strtod(buf + 5, NULL) / 1000;
+       }
+
+       return SR_OK;
+}
+
 SR_PRIV int reloadpro_get_voltage_current(const struct sr_dev_inst *sdi,
                float *voltage, float *current)
 {
@@ -227,6 +278,23 @@ static void handle_packet(const struct sr_dev_inst *sdi)
                return;
        }
 
+       if (g_str_has_prefix((const char *)devc->buf, "uvlo ")) {
+               tokens = g_strsplit((const char *)devc->buf, " ", 2);
+               voltage = g_ascii_strtod(tokens[1], NULL) / 1000;
+               g_strfreev(tokens);
+               if (voltage == .0) {
+                       send_config_update_key(sdi, SR_CONF_UNDER_VOLTAGE_CONDITION,
+                               g_variant_new_boolean(FALSE));
+               } else {
+                       send_config_update_key(sdi, SR_CONF_UNDER_VOLTAGE_CONDITION,
+                               g_variant_new_boolean(TRUE));
+                       send_config_update_key(sdi,
+                               SR_CONF_UNDER_VOLTAGE_CONDITION_THRESHOLD,
+                               g_variant_new_double(voltage));
+               }
+               return;
+       }
+
        if (!g_str_has_prefix((const char *)devc->buf, "read ")) {
                sr_dbg("Unknown packet: '%s'.", devc->buf);
                return;
index 225ee1c279d6a09493f9ceadbcf9c73d9a664789..ac6061a545abf698737f2e7b197944ba4055cb08 100644 (file)
@@ -41,8 +41,12 @@ 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_set_under_voltage_threshold(const struct sr_dev_inst *sdi,
+               float voltage);
 SR_PRIV int reloadpro_get_current_limit(const struct sr_dev_inst *sdi,
                float *current);
+SR_PRIV int reloadpro_get_under_voltage_threshold(const struct sr_dev_inst *sdi,
+               float *voltage);
 SR_PRIV int reloadpro_get_voltage_current(const struct sr_dev_inst *sdi,
                float *voltage, float *current);
 SR_PRIV int reloadpro_receive_data(int fd, int revents, void *cb_data);
index c81a87a169d0f9e8ef52a1abba87b51c4cb5d63a..f5b5b2574a9f9115863c9f0aeed70ed23e237bdf 100644 (file)
@@ -177,6 +177,8 @@ static struct sr_key_info sr_key_info_config[] = {
                "Under-voltage condition", NULL},
        {SR_CONF_UNDER_VOLTAGE_CONDITION_ACTIVE, SR_T_BOOL, "uvc_active",
                "Under-voltage condition active", NULL},
+       {SR_CONF_UNDER_VOLTAGE_CONDITION_THRESHOLD, SR_T_FLOAT, "uvc_threshold",
+               "Under-voltage condition threshold", NULL},
        {SR_CONF_TRIGGER_LEVEL, SR_T_FLOAT, "triggerlevel",
                "Trigger level", NULL},