]> sigrok.org Git - libsigrok.git/blobdiff - hardware/hameg-hmo/api.c
hameg-hmo: Fix two compiler warnings on Windows.
[libsigrok.git] / hardware / hameg-hmo / api.c
index ee7c74430b2ceb9ce63a2650b93918daa2cebaf4..2dd3c011a87712dfc184a19d1ea886db1cdd0112 100644 (file)
@@ -189,6 +189,9 @@ skip_device:
 
        return tty_devs;
 #else
+       (void)vendor_id;
+       (void)product_id;
+
        return NULL;
 #endif
 }
@@ -217,7 +220,7 @@ static struct sr_dev_inst *hmo_probe_serial_device(const char *serial_device,
        scpi = NULL;
        hw_info = NULL;
 
-       if (!(scpi = scpi_serial_dev_inst_new(serial_device, serial_options)))
+       if (!(scpi = scpi_dev_inst_new(serial_device, serial_options)))
                goto fail;
 
        sr_info("Probing %s.", serial_device);
@@ -251,6 +254,10 @@ static struct sr_dev_inst *hmo_probe_serial_device(const char *serial_device,
        if (hmo_init_device(sdi) != SR_OK)
                goto fail;
 
+       sr_scpi_close(sdi->conn);
+
+       sdi->status = SR_ST_INACTIVE;
+
        return sdi;
 
 fail:
@@ -411,6 +418,7 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
        unsigned int i;
        struct dev_context *devc;
        struct scope_config *model;
+       struct scope_state *state;
 
        if (!sdi || !(devc = sdi->priv))
                return SR_ERR_ARG;
@@ -420,6 +428,7 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
 
        ret = SR_ERR_NA;
        model = devc->model_config;
+       state = devc->model_state;
 
        switch (key) {
        case SR_CONF_NUM_TIMEBASE:
@@ -443,6 +452,31 @@ static int config_get(int key, GVariant **data, const struct sr_dev_inst *sdi,
                        ret = SR_ERR_NA;
                }
                break;
+       case SR_CONF_TRIGGER_SOURCE:
+               *data = g_variant_new_string((*model->trigger_sources)[state->trigger_source]);
+               ret = SR_OK;
+               break;
+       case SR_CONF_COUPLING:
+               if (pg_type == PG_NONE) {
+                       sr_err("No probe group specified.");
+                       return SR_ERR_PROBE_GROUP;
+               } else if (pg_type == PG_ANALOG) {
+                       for (i = 0; i < model->analog_channels; ++i) {
+                               if (probe_group != &devc->analog_groups[i])
+                                       continue;
+                               *data = g_variant_new_string((*model->coupling_options)[state->analog_channels[i].coupling]);
+                               ret = SR_OK;
+                               break;
+                       }
+
+               } else {
+                       ret = SR_ERR_NA;
+               }
+               break;
+       case SR_CONF_SAMPLERATE:
+               *data = g_variant_new_uint64(state->sample_rate);
+               ret = SR_OK;
+               break;
        default:
                ret = SR_ERR_NA;
        }
@@ -474,13 +508,14 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
 {
        int ret, pg_type;
        unsigned int i, j;
-       char command[MAX_COMMAND_SIZE];
+       char command[MAX_COMMAND_SIZE], float_str[30];
        struct dev_context *devc;
        struct scope_config *model;
        struct scope_state *state;
        const char *tmp;
        uint64_t p, q, tmp_u64;
        double tmp_d;
+       gboolean update_sample_rate;
 
        if (!sdi || !(devc = sdi->priv))
                return SR_ERR_ARG;
@@ -490,6 +525,7 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
 
        model = devc->model_config;
        state = devc->model_state;
+       update_sample_rate = FALSE;
 
        ret = SR_ERR_NA;
 
@@ -527,10 +563,11 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
                        for (j = 1; j <= model->analog_channels; ++j) {
                                if (probe_group != &devc->analog_groups[j - 1])
                                        continue;
-                               state->analog_channels[j - 1].vdiv = (float) p / q;
+                               state->analog_channels[j - 1].vdiv = i;
+                               g_ascii_formatd(float_str, sizeof(float_str), "%E", (float) p / q);
                                g_snprintf(command, sizeof(command),
                                           (*model->scpi_dialect)[SCPI_CMD_SET_VERTICAL_DIV],
-                                          j, state->analog_channels[j-1].vdiv);
+                                          j, float_str);
 
                                if (sr_scpi_send(sdi->conn, command) != SR_OK ||
                                    sr_scpi_get_opc(sdi->conn) != SR_OK)
@@ -550,12 +587,14 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
                        if (p != (*model->timebases)[i][0] ||
                            q != (*model->timebases)[i][1])
                                continue;
-                       state->timebase = (float) p / q;
+                       state->timebase = i;
+                       g_ascii_formatd(float_str, sizeof(float_str), "%E", (float) p / q);
                        g_snprintf(command, sizeof(command),
                                   (*model->scpi_dialect)[SCPI_CMD_SET_TIMEBASE],
-                                  state->timebase);
+                                  float_str);
 
                        ret = sr_scpi_send(sdi->conn, command);
+                       update_sample_rate = TRUE;
                        break;
                }
                break;
@@ -624,6 +663,9 @@ static int config_set(int key, GVariant *data, const struct sr_dev_inst *sdi,
        if (ret == SR_OK)
                ret = sr_scpi_get_opc(sdi->conn);
 
+       if (ret == SR_OK && update_sample_rate)
+               ret = hmo_update_sample_rate(sdi);
+
        return ret;
 }
 
@@ -752,7 +794,7 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi)
 {
        GSList *l;
        unsigned int i;
-       gboolean *pod_enabled;
+       gboolean *pod_enabled, setup_changed;
        char command[MAX_COMMAND_SIZE];
        struct scope_state *state;
        struct scope_config *model;
@@ -764,6 +806,7 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi)
        scpi = sdi->conn;
        state = devc->model_state;
        model = devc->model_config;
+       setup_changed = FALSE;
 
        pod_enabled = g_try_malloc0(sizeof(gboolean) * model->digital_pods);
 
@@ -780,6 +823,7 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi)
                        if (sr_scpi_send(scpi, command) != SR_OK)
                                return SR_ERR;
                        state->analog_channels[probe->index].state = probe->enabled;
+                       setup_changed = TRUE;
                        break;
                case SR_PROBE_LOGIC:
                        /*
@@ -799,6 +843,7 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi)
                                return SR_ERR;
 
                        state->digital_channels[probe->index] = probe->enabled;
+                       setup_changed = TRUE;
                        break;
                default:
                        return SR_ERR;
@@ -814,10 +859,14 @@ static int hmo_setup_probes(const struct sr_dev_inst *sdi)
                if (sr_scpi_send(scpi, command) != SR_OK)
                        return SR_ERR;
                state->digital_pods[i - 1] = pod_enabled[i - 1];
+               setup_changed = TRUE;
        }
 
        g_free(pod_enabled);
 
+       if (setup_changed && hmo_update_sample_rate(sdi) != SR_OK)
+               return SR_ERR;
+
        return SR_OK;
 }
 
@@ -876,14 +925,20 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi, void *cb_data)
 {
        struct dev_context *devc;
        struct sr_scpi_dev_inst *scpi;
+       struct sr_datafeed_packet packet;
 
        (void)cb_data;
 
+       packet.type = SR_DF_END;
+       packet.payload = NULL;
+       sr_session_send(sdi, &packet);
+
        if (sdi->status != SR_ST_ACTIVE)
                return SR_ERR_DEV_CLOSED;
 
        devc = sdi->priv;
 
+       devc->num_frames = 0;
        g_slist_free(devc->enabled_probes);
        devc->enabled_probes = NULL;
        scpi = sdi->conn;