]> sigrok.org Git - libsigrok.git/commitdiff
atten-pps3xxx: Push configured settings even without acquisition.
authorBert Vermeulen <redacted>
Fri, 10 Jan 2014 01:10:51 +0000 (02:10 +0100)
committerBert Vermeulen <redacted>
Fri, 10 Jan 2014 01:10:51 +0000 (02:10 +0100)
hardware/atten-pps3xxx/api.c
hardware/atten-pps3xxx/protocol.c
hardware/atten-pps3xxx/protocol.h

index 1c7608de019f2e9af0cc391461919c90d6a5efe1..3579d5c8f560276a102983b918369ef14e1f2ce3 100644 (file)
@@ -319,8 +319,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
                                /* Nothing to do. */
                                break;
                        devc->channel_mode_set = ival;
-                       if (devc->acquisition_running)
-                               send_config(sdi);
+                       devc->config_dirty = TRUE;
                        break;
                case SR_CONF_OVER_CURRENT_PROTECTION:
                        bval = g_variant_get_boolean(data);
@@ -328,8 +327,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
                                /* Nothing to do. */
                                break;
                        devc->over_current_protection_set = bval;
-                       if (devc->acquisition_running)
-                               send_config(sdi);
+                       devc->config_dirty = TRUE;
                        break;
                default:
                        return SR_ERR_NA;
@@ -346,16 +344,14 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
                        if (dval < 0 || dval > devc->model->channels[channel].voltage[1])
                                ret = SR_ERR_ARG;
                        devc->config[channel].output_voltage_max = dval;
-                       if (devc->acquisition_running)
-                               send_config(sdi);
+                       devc->config_dirty = TRUE;
                        break;
                case SR_CONF_OUTPUT_CURRENT_MAX:
                        dval = g_variant_get_double(data);
                        if (dval < 0 || dval > devc->model->channels[channel].current[1])
                                ret = SR_ERR_ARG;
                        devc->config[channel].output_current_max = dval;
-                       if (devc->acquisition_running)
-                               send_config(sdi);
+                       devc->config_dirty = TRUE;
                        break;
                case SR_CONF_OUTPUT_ENABLED:
                        bval = g_variant_get_boolean(data);
@@ -363,8 +359,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
                                /* Nothing to do. */
                                break;
                        devc->config[channel].output_enabled_set = bval;
-                       if (devc->acquisition_running)
-                               send_config(sdi);
+                       devc->config_dirty = TRUE;
                        break;
                default:
                        ret = SR_ERR_NA;
@@ -463,6 +458,20 @@ static int config_list(int key, GVariant **data, const struct sr_dev_inst *sdi,
        return ret;
 }
 
+static int dev_close(struct sr_dev_inst *sdi)
+{
+       struct dev_context *devc;
+
+       devc = sdi->priv;
+       if (devc->config_dirty)
+               /* Some configuration changes were queued up but didn't
+                * get sent to the device, likely because we were never
+                * in acquisition mode. Send them out now. */
+               send_config(sdi);
+
+       return std_serial_dev_close(sdi);
+}
+
 static int dev_acquisition_start(const struct sr_dev_inst *sdi,
                void *cb_data)
 {
@@ -522,7 +531,7 @@ SR_PRIV struct sr_dev_driver atten_pps3203_driver_info = {
        .config_set = config_set,
        .config_list = config_list,
        .dev_open = std_serial_dev_open,
-       .dev_close = std_serial_dev_close,
+       .dev_close = dev_close,
        .dev_acquisition_start = dev_acquisition_start,
        .dev_acquisition_stop = dev_acquisition_stop,
        .priv = NULL,
index d1af4457174c3d186e071ac1598c056a12e0b61a..68a3860c18d716deada1f41a5502cc3b9e333fe0 100644 (file)
@@ -122,6 +122,7 @@ SR_PRIV void send_config(const struct sr_dev_inst *sdi)
                value += packet[i];
        packet[i] = value & 0xff;
        send_packet(sdi, packet);
+       devc->config_dirty = FALSE;
 
 }
 
index 45b6fea4463f96709115ecf753c07510d5d027a3..52ee98e91bf14336feb9211309f9850e6146629a 100644 (file)
@@ -81,6 +81,7 @@ struct dev_context {
        gboolean acquisition_running;
 
        /* Operational state */
+       gboolean config_dirty;
        struct per_channel_config *config;
        /* Received from device. */
        int channel_mode;