]> sigrok.org Git - libsigrok.git/commitdiff
Over voltage and current protection support
authorHannu Vuolasaho <redacted>
Wed, 21 Oct 2015 22:05:37 +0000 (01:05 +0300)
committerUwe Hermann <redacted>
Thu, 29 Oct 2015 17:43:09 +0000 (18:43 +0100)
Developed against Velleman LABPS3005D and seems to work.

src/hardware/korad-kdxxxxp/api.c
src/hardware/korad-kdxxxxp/protocol.c
src/hardware/korad-kdxxxxp/protocol.h

index 4a6c8179ca4924d49fdedfdccbba6e1cc109c3a4..6cbde4d02b4a23a24333bf59da06e52518db9cb6 100644 (file)
@@ -44,6 +44,8 @@ static const uint32_t devopts[] = {
        SR_CONF_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_ENABLED | SR_CONF_GET | SR_CONF_SET,
        SR_CONF_REGULATION | SR_CONF_GET,
+       SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
+       SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
 };
 
 static const struct korad_kdxxxxp_model models[] = {
@@ -225,6 +227,12 @@ static int config_get(uint32_t key, GVariant **data,
                else
                        *data = g_variant_new_string("CV");
                break;
+       case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
+               *data = g_variant_new_boolean(devc->OCP_enabled);
+               break;
+       case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
+               *data = g_variant_new_boolean(devc->OVP_enabled);
+               break;
        default:
                return SR_ERR_NA;
        }
@@ -283,6 +291,20 @@ static int config_set(uint32_t key, GVariant *data,
                if (korad_kdxxxxp_set_value(sdi->conn, devc) < 0)
                        return SR_ERR;
                break;
+       case SR_CONF_OVER_CURRENT_PROTECTION_ENABLED:
+               bval = g_variant_get_boolean(data);
+               devc->OCP_enabled = bval;
+               devc->target = KDXXXXP_OCP;
+               if (korad_kdxxxxp_set_value(sdi->conn, devc) < 0)
+                       return SR_ERR;
+               break;
+       case SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED:
+               bval = g_variant_get_boolean(data);
+               devc->OVP_enabled = bval;
+               devc->target = KDXXXXP_OVP;
+               if (korad_kdxxxxp_set_value(sdi->conn, devc) < 0)
+                       return SR_ERR;
+               break;
        default:
                return SR_ERR_NA;
        }
index eb5281037b7d6c939a7e39b143007074ad5fc926..bee02d9d5324c4bd164859c5facb409490def777 100644 (file)
@@ -109,6 +109,14 @@ SR_PRIV int korad_kdxxxxp_set_value(struct sr_serial_dev_inst *serial,
                cmd = "BEEP%01.0f";
                value = (devc->beep_enabled) ? 1 : 0;
                break;
+       case KDXXXXP_OCP:
+               cmd = "OCP%01.0f";
+               value = (devc->OCP_enabled) ? 1 : 0;
+               break;
+       case KDXXXXP_OVP:
+               cmd = "OVP%01.0f";
+               value = (devc->OVP_enabled) ? 1 : 0;
+               break;
        case KDXXXXP_SAVE:
                cmd = "SAV%01.0f";
                if (devc->program < 1 || devc->program > 5) {
@@ -266,18 +274,24 @@ SR_PRIV int korad_kdxxxxp_get_reply(struct sr_serial_dev_inst *serial,
                 * 00 independent 01 series 11 parallel
                 */
                devc->beep_enabled = (1 << 4);
-               /* status_byte & (1 << 5) Unlocked */
-
+               devc->OCP_enabled = (status_byte & (1 << 5));
                devc->output_enabled = (status_byte & (1 << 6));
+               /* Velleman LABPS3005 quirk */
+               if (devc->output_enabled)
+                       devc->OVP_enabled = (status_byte & (1 << 7));
                sr_dbg("Status: 0x%02x", status_byte);
-               sr_spew("Status: CH1: constant %s CH2: constant %s. Device is "
-                       "%s and %s. Buttons are %s. Output is %s ",
+               sr_spew("Status: CH1: constant %s CH2: constant %s. "
+                       "Tracking would be %s. Device is "
+                       "%s and %s. Buttons are %s. Output is %s "
+                       "and extra byte is %s.",
                        (status_byte & (1 << 0)) ? "voltage" : "current",
                        (status_byte & (1 << 1)) ? "voltage" : "current",
+                       (status_byte & (1 << 2)) ? "parallel" : "series",
                        (status_byte & (1 << 3)) ? "tracking" : "independent",
                        (status_byte & (1 << 4)) ? "beeping" : "silent",
                        (status_byte & (1 << 5)) ? "locked" : "unlocked",
-                       (status_byte & (1 << 6)) ? "enabled" : "disabled");
+                       (status_byte & (1 << 6)) ? "enabled" : "disabled",
+                       (status_byte & (1 << 7)) ? "true" : "false");
        }
 
        devc->reply_pending = FALSE;
@@ -300,6 +314,10 @@ static void next_measurement(struct dev_context *devc)
        case KDXXXXP_VOLTAGE_MAX:
                devc->target = KDXXXXP_CURRENT;
                break;
+       /* Read back what was set */
+       case KDXXXXP_BEEP:
+       case KDXXXXP_OCP:
+       case KDXXXXP_OVP:
        case KDXXXXP_OUTPUT:
                devc->target = KDXXXXP_STATUS;
                break;
index 3b5c2b177ea77e646e08eb558861b0d7c6bb4a23..c292dab5cc221d0f56a292cd78894c972842d71a 100644 (file)
@@ -61,6 +61,8 @@ enum {
        KDXXXXP_STATUS,
        KDXXXXP_OUTPUT,
        KDXXXXP_BEEP,
+       KDXXXXP_OCP,
+       KDXXXXP_OVP,
        KDXXXXP_SAVE,
        KDXXXXP_RECALL,
 };
@@ -89,6 +91,8 @@ struct dev_context {
 
        gboolean output_enabled; /**< Is the output enabled? */
        gboolean beep_enabled;   /**< Enable beeper. */
+       gboolean OCP_enabled;    /**< Output current protection enabled */
+       gboolean OVP_enabled;    /**< Output voltage protection enabled */
 
        /* Temporary state across callbacks */
        int target;              /**< What reply to expect */