]> sigrok.org Git - libsigrok.git/commitdiff
hantek-dso: dso2250: It's not HORIZ_TRIGGERPOS but CAPTURE_RATIO.
authorPhilipp Marek <redacted>
Sun, 19 Nov 2017 18:44:29 +0000 (19:44 +0100)
committerUwe Hermann <redacted>
Thu, 11 Jan 2018 00:48:57 +0000 (01:48 +0100)
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

src/hardware/hantek-dso/api.c
src/hardware/hantek-dso/protocol.c
src/hardware/hantek-dso/protocol.h

index 5f495a1cf9a549f0850d2a070c9dd1a71cb1d560..857ea0df7e9b9c57c8d59a79cbd5466e1328d4d4 100644 (file)
@@ -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)
index a1413b8f09fe19801ef0c494013e98246f107bcf..ca0bb80481052a95f748a9a8c6844ad6d3cbb896 100644 (file)
@@ -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;
index f210329ddb3dd701185f3c4957f0fcd6760dbcf9..626647163f7a4cffd0fd455fad52a9c594199419 100644 (file)
@@ -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 */