From: Bert Vermeulen Date: Fri, 10 Jan 2014 01:10:51 +0000 (+0100) Subject: atten-pps3xxx: Push configured settings even without acquisition. X-Git-Tag: libsigrok-0.3.0~317 X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=commitdiff_plain;h=ab988ecb237c6aa8510eaa4a53e4e3d1ba78fd9b atten-pps3xxx: Push configured settings even without acquisition. --- diff --git a/hardware/atten-pps3xxx/api.c b/hardware/atten-pps3xxx/api.c index 1c7608de..3579d5c8 100644 --- a/hardware/atten-pps3xxx/api.c +++ b/hardware/atten-pps3xxx/api.c @@ -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, diff --git a/hardware/atten-pps3xxx/protocol.c b/hardware/atten-pps3xxx/protocol.c index d1af4457..68a3860c 100644 --- a/hardware/atten-pps3xxx/protocol.c +++ b/hardware/atten-pps3xxx/protocol.c @@ -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; } diff --git a/hardware/atten-pps3xxx/protocol.h b/hardware/atten-pps3xxx/protocol.h index 45b6fea4..52ee98e9 100644 --- a/hardware/atten-pps3xxx/protocol.h +++ b/hardware/atten-pps3xxx/protocol.h @@ -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;