X-Git-Url: https://sigrok.org/gitweb/?p=libsigrok.git;a=blobdiff_plain;f=src%2Fhardware%2Fhantek-dso%2Fapi.c;h=c1b18ea9ca660a52ec8b2e4113d637b3b8a1e88c;hp=9b7546292902184d6d4c67679269a3cbf4749d56;hb=755793e991c4d429f99254f23008bfddb89d8e00;hpb=16a1dca4ad817e7f19f7756f6d574c6bbe82cb51 diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index 9b754629..c1b18ea9 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -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), */ }; @@ -314,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++) { @@ -328,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); @@ -441,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; @@ -502,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) { @@ -511,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) @@ -540,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) @@ -775,7 +785,7 @@ static void LIBUSB_CALL receive_transfer(struct libusb_transfer *transfer) 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 { @@ -860,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; @@ -930,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; }