]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hantek-dso/api.c
scpi-pps: Add a missing "break" in config_get().
[libsigrok.git] / src / hardware / hantek-dso / api.c
index 857ea0df7e9b9c57c8d59a79cbd5466e1328d4d4..c1b18ea9ca660a52ec8b2e4113d637b3b8a1e88c 100644 (file)
@@ -64,6 +64,7 @@ static const uint32_t devopts[] = {
        SR_CONF_BUFFERSIZE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_SAMPLERATE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
        SR_CONF_NUM_VDIV | SR_CONF_GET,
+       SR_CONF_TRIGGER_LEVEL | SR_CONF_GET | SR_CONF_SET,
 };
 
 static const uint32_t devopts_cg[] = {
@@ -147,7 +148,7 @@ static const uint64_t samplerates[] = {
        SR_MHZ(50),
        SR_MHZ(100),
        SR_MHZ(125),
-       /* fast mode not supported yet 
+       /* Fast mode not supported yet.
        SR_MHZ(200),
        SR_MHZ(250), */
 };
@@ -237,6 +238,7 @@ static int configure_channels(const struct sr_dev_inst *sdi)
        devc = sdi->priv;
 
        g_slist_free(devc->enabled_channels);
+       devc->enabled_channels = NULL;
        devc->ch_enabled[0] = devc->ch_enabled[1] = FALSE;
        for (l = sdi->channels, p = 0; l; l = l->next, p++) {
                ch = l->data;
@@ -313,7 +315,8 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
 
                libusb_get_device_descriptor(devlist[i], &des);
 
-               usb_get_port_path(devlist[i], connection_id, sizeof(connection_id));
+               if (usb_get_port_path(devlist[i], connection_id, sizeof(connection_id)) < 0)
+                       continue;
 
                prof = NULL;
                for (j = 0; dev_profiles[j].orig_vid; j++) {
@@ -327,11 +330,12 @@ static GSList *scan(struct sr_dev_driver *di, GSList *options)
                                devices = g_slist_append(devices, sdi);
                                devc = sdi->priv;
                                if (ezusb_upload_firmware(drvc->sr_ctx, devlist[i],
-                                               USB_CONFIGURATION, prof->firmware) == SR_OK)
+                                               USB_CONFIGURATION, prof->firmware) == SR_OK) {
                                        /* Remember when the firmware on this device was updated */
                                        devc->fw_updated = g_get_monotonic_time();
-                               else
-                                       sr_err("Firmware upload failed");
+                               } else {
+                                       sr_err("Firmware upload failed, name %s", prof->firmware);
+                               }
                                /* Dummy USB address of 0xff will get overwritten later. */
                                sdi->conn = sr_usb_dev_inst_new(
                                                libusb_get_bus_number(devlist[i]), 0xff, NULL);
@@ -440,6 +444,9 @@ static int config_get(uint32_t key, GVariant **data,
        devc = sdi->priv;
        if (!cg) {
                switch (key) {
+               case SR_CONF_TRIGGER_LEVEL:
+                       *data = g_variant_new_double(devc->voffset_trigger);
+                       break;
                case SR_CONF_CONN:
                        if (!sdi->conn)
                                return SR_ERR_ARG;
@@ -501,8 +508,8 @@ static int config_set(uint32_t key, GVariant *data,
        const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
 {
        struct dev_context *devc;
-       int rat;
        int ch_idx, idx;
+       float flt;
 
        devc = sdi->priv;
        if (!cg) {
@@ -510,18 +517,23 @@ static int config_set(uint32_t key, GVariant *data,
                case SR_CONF_LIMIT_FRAMES:
                        devc->limit_frames = g_variant_get_uint64(data);
                        break;
+               case SR_CONF_TRIGGER_LEVEL:
+                       flt = g_variant_get_double(data);
+                       if (flt < 0.0 || flt > 1.0) {
+                               sr_err("Trigger level must be in [0.0,1.0].");
+                               return SR_ERR_ARG;
+                       }
+                       devc->voffset_trigger = flt;
+                       if (dso_set_voffsets(sdi) != SR_OK)
+                               return SR_ERR;
+                       break;
                case SR_CONF_TRIGGER_SLOPE:
                        if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_slopes))) < 0)
                                return SR_ERR_ARG;
                        devc->triggerslope = idx;
                        break;
                case SR_CONF_CAPTURE_RATIO:
-                       rat = g_variant_get_uint64(data);
-                       if (rat < 0 || rat > 100) {
-                               sr_err("Capture ratio must be in [0,100].");
-                               return SR_ERR_ARG;
-                       } else
-                               devc->capture_ratio = rat;
+                       devc->capture_ratio = g_variant_get_uint64(data);
                        break;
                case SR_CONF_BUFFERSIZE:
                        if ((idx = std_u64_idx(data, devc->profile->buffersizes, NUM_BUFFER_SIZES)) < 0)
@@ -539,7 +551,6 @@ static int config_set(uint32_t key, GVariant *data,
                        devc->samplerate = samplerates[idx];
                        if (dso_set_trigger_samplerate(sdi) != SR_OK)
                                return SR_ERR;
-                       sr_dbg("got new sample rate %d, idx %d", devc->samplerate, idx);
                        break;
                case SR_CONF_TRIGGER_SOURCE:
                        if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_sources))) < 0)
@@ -767,12 +778,14 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer)
                sr_dbg("End of frame, sending %d pre-trigger buffered samples.",
                        devc->samp_buffered);
                send_chunk(sdi, devc->framebuf, devc->samp_buffered);
+               g_free(devc->framebuf);
+               devc->framebuf = NULL;
 
                /* Mark the end of this frame. */
                packet.type = SR_DF_FRAME_END;
                sr_session_send(sdi, &packet);
 
-               if (devc->limit_frames && ++devc->num_frames == devc->limit_frames) {
+               if (devc->limit_frames && ++devc->num_frames >= devc->limit_frames) {
                        /* Terminate session */
                        devc->dev_state = STOPPING;
                } else {
@@ -857,7 +870,7 @@ static int handle_event(int fd, int revents, void *cb_data)
                /* No data yet. */
                break;
        case CAPTURE_READY_8BIT:
-       case CAPTURE_READY2250:
+       case CAPTURE_READY_2250:
                /* Remember where in the captured frame the trigger is. */
                devc->trigger_offset = trigger_offset;
 
@@ -927,6 +940,7 @@ static int dev_acquisition_stop(struct sr_dev_inst *sdi)
 
        devc = sdi->priv;
        devc->dev_state = STOPPING;
+       devc->num_frames = 0;
 
        return SR_OK;
 }