hp-59306a: Enable/disable all outputs at once.
authorFrank Stettner <frank-stettner@gmx.net>
Sun, 25 Jul 2021 09:54:58 +0000 (11:54 +0200)
committerFrank Stettner <frank-stettner@gmx.net>
Sat, 14 Aug 2021 18:24:55 +0000 (20:24 +0200)
src/hardware/hp-59306a/api.c
src/hardware/hp-59306a/protocol.c

index 289274323e580009941f6a3cb0d30e57ac35f260..0d90781cb095f0a9d0a64839b10ca11a44c732d1 100644 (file)
@@ -30,10 +30,7 @@ static const uint32_t drvopts[] = {
 };
 
 static const uint32_t devopts[] = {
-       /*
-        * TODO Enable/disable multiple channel groups at once.
-        * SR_CONF_ENABLED | SR_CONF_SET,
-        */
+       SR_CONF_ENABLED | SR_CONF_SET,
 };
 
 static const uint32_t devopts_cg[] = {
@@ -115,8 +112,10 @@ static int config_set(uint32_t key, GVariant *data,
 
        if (!cg) {
                switch (key) {
-               /* TODO: Enable/disbale multiple channel groups at once. */
                case SR_CONF_ENABLED:
+                       /* Enable/disable all channels at the same time. */
+                       on = g_variant_get_boolean(data);
+                       return hp_59306a_switch_cg(sdi, cg, on);
                default:
                        return SR_ERR_NA;
                }
index 3628f98d458e339f05b6913120b48f57546b7fc9..69af3610d590f5c89d0f72600ee97ba175d5c7f0 100644 (file)
 SR_PRIV int hp_59306a_switch_cg(const struct sr_dev_inst *sdi,
        const struct sr_channel_group *cg, gboolean enabled)
 {
-       int ret;
-       struct sr_scpi_dev_inst *scpi;
+       char *cmd;
        struct channel_group_context *cgc;
+       struct sr_scpi_dev_inst *scpi;
+       int ret;
 
-       scpi = sdi->conn;
-       cgc = cg->priv;
+       if (!cg) {
+               if (enabled)
+                       cmd = g_strdup("A123456");
+               else
+                       cmd = g_strdup("B123456");
+       } else {
+               cgc = cg->priv;
+               if (enabled)
+                       cmd = g_strdup_printf("A%zu", cgc->number);
+               else
+                       cmd = g_strdup_printf("B%zu", cgc->number);
+       }
 
-       if (enabled)
-               ret = sr_scpi_send(scpi, "A%zu", cgc->number);
-       else
-               ret = sr_scpi_send(scpi, "B%zu", cgc->number);
+       scpi = sdi->conn;
+       ret = sr_scpi_send(scpi, cmd);
+       g_free(cmd);
 
        return ret;
 }