X-Git-Url: https://sigrok.org/gitweb/?a=blobdiff_plain;f=src%2Fhardware%2Fhantek-dso%2Fprotocol.c;h=34a3935b9fd4fa6e36f3ceab8197652f2629e625;hb=HEAD;hp=465f925b46c986d83181e422869c776a8692c1a5;hpb=6deb361bbf5b62109cdb5c4bede227cd56f9fcc5;p=libsigrok.git diff --git a/src/hardware/hantek-dso/protocol.c b/src/hardware/hantek-dso/protocol.c index 465f925b..34a3935b 100644 --- a/src/hardware/hantek-dso/protocol.c +++ b/src/hardware/hantek-dso/protocol.c @@ -130,7 +130,9 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi) /* * Check device by its physical USB bus/port address. */ - 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; + if (strcmp(sdi->connection_id, connection_id)) /* This is not the one. */ continue; @@ -273,8 +275,10 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi) memset(cmdstring, 0, sizeof(cmdstring)); /* Command */ cmdstring[0] = CMD_2250_SET_TRIGGERSOURCE; - sr_dbg("Trigger source %s.", devc->triggersource); - if (!strcmp("CH2", devc->triggersource)) + sr_dbg("Trigger source %s.", devc->triggersource ? : ""); + if (!devc->triggersource) + tmp = 0; + else if (!strcmp("CH2", devc->triggersource)) tmp = 3; else if (!strcmp("CH1", devc->triggersource)) tmp = 2; @@ -324,7 +328,8 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi) } tmp = base / devc->samplerate; - if (tmp) { + /* Downsample only if really necessary */ + if (tmp > 1) { /* Downsampling on */ cmdstring[2] |= 2; /* Downsampler = 1comp((Base / Samplerate) - 2) @@ -373,7 +378,7 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi) memset(cmdstring, 0, sizeof(cmdstring)); cmdstring[0] = CMD_2250_SET_TRIGGERPOS_AND_BUFFER; - sr_dbg("Capture ratio: %d.", devc->capture_ratio); + sr_dbg("Capture ratio: %" PRIu64 ".", devc->capture_ratio); trig = devc->capture_ratio; dso2250_set_triggerpos(trig, devc->framesize != FRAMESIZE_SMALL, cmdstring, 2); @@ -394,7 +399,7 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi) return SR_OK; } -int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi) +SR_PRIV int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi) { struct dev_context *devc; struct sr_usb_dev_inst *usb; @@ -418,8 +423,10 @@ int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi) cmdstring[0] = CMD_SET_TRIGGER_SAMPLERATE; /* Trigger source */ - sr_dbg("Trigger source %s.", devc->triggersource); - if (!strcmp("CH2", devc->triggersource)) + sr_dbg("Trigger source %s.", devc->triggersource ? : ""); + if (!devc->triggersource) + tmp = 2; + else if (!strcmp("CH2", devc->triggersource)) tmp = 0; else if (!strcmp("CH1", devc->triggersource)) tmp = 1; @@ -494,7 +501,7 @@ int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi) cmdstring[5] = (tmp >> 8) & 0xff; /* Horizontal trigger position */ - sr_dbg("Capture ratio: %d.", devc->capture_ratio); + sr_dbg("Capture ratio: %" PRIu64 ".", devc->capture_ratio); tmp = 0x77fff + 0x8000 * devc->capture_ratio / 100; cmdstring[6] = tmp & 0xff; cmdstring[7] = (tmp >> 8) & 0xff; @@ -665,7 +672,7 @@ static int dso_set_relays(const struct sr_dev_inst *sdi) if (devc->coupling[1] != COUPLING_AC) relays[6] = ~relays[6]; - if (!strcmp(devc->triggersource, "EXT")) + if (devc->triggersource && strcmp(devc->triggersource, "EXT") == 0) relays[7] = ~relays[7]; if (sr_log_loglevel_get() >= SR_LOG_DBG) { @@ -688,7 +695,7 @@ static int dso_set_relays(const struct sr_dev_inst *sdi) return SR_OK; } -int dso_set_voffsets(const struct sr_dev_inst *sdi) +SR_PRIV int dso_set_voffsets(const struct sr_dev_inst *sdi) { struct dev_context *devc; struct sr_usb_dev_inst *usb;