From: Aurelien Jacobs Date: Sat, 25 Jun 2016 15:21:20 +0000 (+0200) Subject: rigol-ds: split out vertical config reading in its own function for re-use. X-Git-Tag: libsigrok-0.5.0~302 X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=8719638f5ad434684331ca2bd0f18fb759e4f97a;p=libsigrok.git rigol-ds: split out vertical config reading in its own function for re-use. --- diff --git a/src/hardware/rigol-ds/protocol.c b/src/hardware/rigol-ds/protocol.c index 0ce3a11c..140963a8 100644 --- a/src/hardware/rigol-ds/protocol.c +++ b/src/hardware/rigol-ds/protocol.c @@ -813,29 +813,9 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) return SR_ERR; sr_dbg("Current timebase %g", devc->timebase); - /* Vertical gain. */ - for (i = 0; i < devc->model->analog_channels; i++) { - cmd = g_strdup_printf(":CHAN%d:SCAL?", i + 1); - res = sr_scpi_get_float(sdi->conn, cmd, &devc->vdiv[i]); - g_free(cmd); - if (res != SR_OK) - return SR_ERR; - } - sr_dbg("Current vertical gain:"); - for (i = 0; i < devc->model->analog_channels; i++) - sr_dbg("CH%d %g", i + 1, devc->vdiv[i]); - - /* Vertical offset. */ - for (i = 0; i < devc->model->analog_channels; i++) { - cmd = g_strdup_printf(":CHAN%d:OFFS?", i + 1); - res = sr_scpi_get_float(sdi->conn, cmd, &devc->vert_offset[i]); - g_free(cmd); - if (res != SR_OK) - return SR_ERR; - } - sr_dbg("Current vertical offset:"); - for (i = 0; i < devc->model->analog_channels; i++) - sr_dbg("CH%d %g", i + 1, devc->vert_offset[i]); + /* Vertical gain and offset. */ + if (rigol_ds_get_dev_cfg_vertical(sdi) != SR_OK) + return SR_ERR; /* Coupling. */ for (i = 0; i < devc->model->analog_channels; i++) { @@ -866,3 +846,39 @@ SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi) return SR_OK; } + +SR_PRIV int rigol_ds_get_dev_cfg_vertical(const struct sr_dev_inst *sdi) +{ + struct dev_context *devc; + char *cmd; + unsigned int i; + int res; + + devc = sdi->priv; + + /* Vertical gain. */ + for (i = 0; i < devc->model->analog_channels; i++) { + cmd = g_strdup_printf(":CHAN%d:SCAL?", i + 1); + res = sr_scpi_get_float(sdi->conn, cmd, &devc->vdiv[i]); + g_free(cmd); + if (res != SR_OK) + return SR_ERR; + } + sr_dbg("Current vertical gain:"); + for (i = 0; i < devc->model->analog_channels; i++) + sr_dbg("CH%d %g", i + 1, devc->vdiv[i]); + + /* Vertical offset. */ + for (i = 0; i < devc->model->analog_channels; i++) { + cmd = g_strdup_printf(":CHAN%d:OFFS?", i + 1); + res = sr_scpi_get_float(sdi->conn, cmd, &devc->vert_offset[i]); + g_free(cmd); + if (res != SR_OK) + return SR_ERR; + } + sr_dbg("Current vertical offset:"); + for (i = 0; i < devc->model->analog_channels; i++) + sr_dbg("CH%d %g", i + 1, devc->vert_offset[i]); + + return SR_OK; +} diff --git a/src/hardware/rigol-ds/protocol.h b/src/hardware/rigol-ds/protocol.h index a0859361..787adffb 100644 --- a/src/hardware/rigol-ds/protocol.h +++ b/src/hardware/rigol-ds/protocol.h @@ -153,5 +153,6 @@ SR_PRIV int rigol_ds_capture_start(const struct sr_dev_inst *sdi); SR_PRIV int rigol_ds_channel_start(const struct sr_dev_inst *sdi); SR_PRIV int rigol_ds_receive(int fd, int revents, void *cb_data); SR_PRIV int rigol_ds_get_dev_cfg(const struct sr_dev_inst *sdi); +SR_PRIV int rigol_ds_get_dev_cfg_vertical(const struct sr_dev_inst *sdi); #endif