From: Philipp Marek Date: Sun, 19 Nov 2017 18:44:29 +0000 (+0100) Subject: hantek-dso: dso2250: It's not HORIZ_TRIGGERPOS but CAPTURE_RATIO. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=95983cc3fe3e354b698fb6133e6d196334cd9f2f;p=libsigrok.git hantek-dso: dso2250: It's not HORIZ_TRIGGERPOS but CAPTURE_RATIO. Seems a bit unfortunately named; if my current guess is right, perhaps it should be :%s/SR_CONF_HORIZ_TRIGGERPOS/SR_CONF_HORIZ_DISPLAYOFFSET/g --- diff --git a/src/hardware/hantek-dso/api.c b/src/hardware/hantek-dso/api.c index 5f495a1c..857ea0df 100644 --- a/src/hardware/hantek-dso/api.c +++ b/src/hardware/hantek-dso/api.c @@ -58,7 +58,7 @@ static const uint32_t devopts[] = { SR_CONF_LIMIT_FRAMES | SR_CONF_SET, SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_NUM_HDIV | SR_CONF_GET, - SR_CONF_HORIZ_TRIGGERPOS | SR_CONF_GET | SR_CONF_SET, + SR_CONF_CAPTURE_RATIO | SR_CONF_GET | SR_CONF_SET, SR_CONF_TRIGGER_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET, SR_CONF_BUFFERSIZE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, @@ -221,7 +221,7 @@ static struct sr_dev_inst *dso_dev_new(const struct dso_profile *prof) devc->framesize = DEFAULT_FRAMESIZE; devc->triggerslope = SLOPE_POSITIVE; devc->triggersource = g_strdup(DEFAULT_TRIGGER_SOURCE); - devc->triggerposition = DEFAULT_HORIZ_TRIGGERPOS; + devc->capture_ratio = DEFAULT_CAPTURE_RATIO; sdi->priv = devc; return sdi; @@ -467,8 +467,8 @@ static int config_get(uint32_t key, GVariant **data, s = (devc->triggerslope == SLOPE_POSITIVE) ? "r" : "f"; *data = g_variant_new_string(s); break; - case SR_CONF_HORIZ_TRIGGERPOS: - *data = g_variant_new_double(devc->triggerposition); + case SR_CONF_CAPTURE_RATIO: + *data = g_variant_new_uint64(devc->capture_ratio); break; default: return SR_ERR_NA; @@ -501,7 +501,7 @@ 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; - double tmp_double; + int rat; int ch_idx, idx; devc = sdi->priv; @@ -515,13 +515,13 @@ static int config_set(uint32_t key, GVariant *data, return SR_ERR_ARG; devc->triggerslope = idx; break; - case SR_CONF_HORIZ_TRIGGERPOS: - tmp_double = g_variant_get_double(data); - if (tmp_double < 0.0 || tmp_double > 1.0) { - sr_err("Trigger position should be between 0.0 and 1.0."); + 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->triggerposition = tmp_double; + devc->capture_ratio = rat; break; case SR_CONF_BUFFERSIZE: if ((idx = std_u64_idx(data, devc->profile->buffersizes, NUM_BUFFER_SIZES)) < 0) @@ -539,6 +539,7 @@ 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) diff --git a/src/hardware/hantek-dso/protocol.c b/src/hardware/hantek-dso/protocol.c index a1413b8f..ca0bb804 100644 --- a/src/hardware/hantek-dso/protocol.c +++ b/src/hardware/hantek-dso/protocol.c @@ -241,6 +241,25 @@ static int get_channel_offsets(const struct sr_dev_inst *sdi) return SR_OK; } + +static void dso2250_set_triggerpos(int value, int long_buffer, uint8_t dest[], int offset) +{ + uint32_t min, max; + uint32_t tmp, diff; + + min = long_buffer ? 0 : 0x7d7ff; + max = 0x7ffff; + + diff = max - min; + tmp = min + diff * value / 100; + sr_dbg("2250 trigger pos: %3d%% * [0x%x,0x%x] == 0x%x", value, min, max, tmp); + + dest[offset + 0] = tmp & 0xff; + dest[offset + 1] = (tmp >> 8) & 0xff; + dest[offset + 2] = (tmp >> 16) & 0x7; +} + + /* See http://openhantek.sourceforge.net/doc/namespaceHantek.html#ac1cd181814cf3da74771c29800b39028 */ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi) { @@ -249,6 +268,7 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi) int ret, tmp; int base; uint8_t cmdstring[12]; + int trig; devc = sdi->priv; @@ -365,20 +385,12 @@ 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; - /* TODO for big buffer */ - sr_dbg("Trigger position: %3.2f.", devc->triggerposition); -// tmp = 0x77fff + 0x8000 * devc->triggerposition; -// cmdstring[6] = tmp & 0xff; -// cmdstring[7] = (tmp >> 8) & 0xff; -// cmdstring[10] = (tmp >> 16) & 0xff; - - cmdstring[2]=0xff; - cmdstring[3]=0xff; - cmdstring[4]=0x07; - - cmdstring[6]=0xff; - cmdstring[7]=0xd7; - cmdstring[8]=0x07; + sr_dbg("Capture ratio: %d.", devc->capture_ratio); + trig = devc->capture_ratio; + dso2250_set_triggerpos(trig, + devc->framesize != FRAMESIZE_SMALL, cmdstring, 2); + dso2250_set_triggerpos(100 - trig, + devc->framesize != FRAMESIZE_SMALL, cmdstring, 6); if (send_begin(sdi) != SR_OK) return SR_ERR; @@ -494,8 +506,8 @@ int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi) cmdstring[5] = (tmp >> 8) & 0xff; /* Horizontal trigger position */ - sr_dbg("Trigger position: %3.2f.", devc->triggerposition); - tmp = 0x77fff + 0x8000 * devc->triggerposition; + sr_dbg("Capture ratio: %d.", devc->capture_ratio); + tmp = 0x77fff + 0x8000 * devc->capture_ratio / 100; cmdstring[6] = tmp & 0xff; cmdstring[7] = (tmp >> 8) & 0xff; cmdstring[10] = (tmp >> 16) & 0xff; diff --git a/src/hardware/hantek-dso/protocol.h b/src/hardware/hantek-dso/protocol.h index f210329d..62664716 100644 --- a/src/hardware/hantek-dso/protocol.h +++ b/src/hardware/hantek-dso/protocol.h @@ -40,7 +40,7 @@ #define DEFAULT_SAMPLERATE SR_KHZ(10) #define DEFAULT_TRIGGER_SOURCE "CH1" #define DEFAULT_COUPLING COUPLING_DC -#define DEFAULT_HORIZ_TRIGGERPOS 0.5 +#define DEFAULT_CAPTURE_RATIO 100 #define DEFAULT_VERT_OFFSET 0.5 #define DEFAULT_VERT_TRIGGERPOS 0.5 @@ -202,7 +202,7 @@ struct dev_context { gboolean filter[2]; int triggerslope; char *triggersource; - float triggerposition; + int capture_ratio; int triggermode; /* Frame transfer */