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
This commit is contained in:
Philipp Marek 2017-11-19 19:44:29 +01:00 committed by Uwe Hermann
parent 11e3319656
commit 95983cc3fe
3 changed files with 41 additions and 28 deletions

View File

@ -58,7 +58,7 @@ static const uint32_t devopts[] = {
SR_CONF_LIMIT_FRAMES | SR_CONF_SET, SR_CONF_LIMIT_FRAMES | SR_CONF_SET,
SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, SR_CONF_TIMEBASE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
SR_CONF_NUM_HDIV | SR_CONF_GET, 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_SOURCE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET, SR_CONF_TRIGGER_SLOPE | SR_CONF_GET | SR_CONF_SET,
SR_CONF_BUFFERSIZE | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST, 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->framesize = DEFAULT_FRAMESIZE;
devc->triggerslope = SLOPE_POSITIVE; devc->triggerslope = SLOPE_POSITIVE;
devc->triggersource = g_strdup(DEFAULT_TRIGGER_SOURCE); devc->triggersource = g_strdup(DEFAULT_TRIGGER_SOURCE);
devc->triggerposition = DEFAULT_HORIZ_TRIGGERPOS; devc->capture_ratio = DEFAULT_CAPTURE_RATIO;
sdi->priv = devc; sdi->priv = devc;
return sdi; return sdi;
@ -467,8 +467,8 @@ static int config_get(uint32_t key, GVariant **data,
s = (devc->triggerslope == SLOPE_POSITIVE) ? "r" : "f"; s = (devc->triggerslope == SLOPE_POSITIVE) ? "r" : "f";
*data = g_variant_new_string(s); *data = g_variant_new_string(s);
break; break;
case SR_CONF_HORIZ_TRIGGERPOS: case SR_CONF_CAPTURE_RATIO:
*data = g_variant_new_double(devc->triggerposition); *data = g_variant_new_uint64(devc->capture_ratio);
break; break;
default: default:
return SR_ERR_NA; 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) const struct sr_dev_inst *sdi, const struct sr_channel_group *cg)
{ {
struct dev_context *devc; struct dev_context *devc;
double tmp_double; int rat;
int ch_idx, idx; int ch_idx, idx;
devc = sdi->priv; devc = sdi->priv;
@ -515,13 +515,13 @@ static int config_set(uint32_t key, GVariant *data,
return SR_ERR_ARG; return SR_ERR_ARG;
devc->triggerslope = idx; devc->triggerslope = idx;
break; break;
case SR_CONF_HORIZ_TRIGGERPOS: case SR_CONF_CAPTURE_RATIO:
tmp_double = g_variant_get_double(data); rat = g_variant_get_uint64(data);
if (tmp_double < 0.0 || tmp_double > 1.0) { if (rat < 0 || rat > 100) {
sr_err("Trigger position should be between 0.0 and 1.0."); sr_err("Capture ratio must be in [0,100].");
return SR_ERR_ARG; return SR_ERR_ARG;
} else } else
devc->triggerposition = tmp_double; devc->capture_ratio = rat;
break; break;
case SR_CONF_BUFFERSIZE: case SR_CONF_BUFFERSIZE:
if ((idx = std_u64_idx(data, devc->profile->buffersizes, NUM_BUFFER_SIZES)) < 0) 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]; devc->samplerate = samplerates[idx];
if (dso_set_trigger_samplerate(sdi) != SR_OK) if (dso_set_trigger_samplerate(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
sr_dbg("got new sample rate %d, idx %d", devc->samplerate, idx);
break; break;
case SR_CONF_TRIGGER_SOURCE: case SR_CONF_TRIGGER_SOURCE:
if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_sources))) < 0) if ((idx = std_str_idx(data, ARRAY_AND_SIZE(trigger_sources))) < 0)

View File

@ -241,6 +241,25 @@ static int get_channel_offsets(const struct sr_dev_inst *sdi)
return SR_OK; 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 */ /* See http://openhantek.sourceforge.net/doc/namespaceHantek.html#ac1cd181814cf3da74771c29800b39028 */
static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi) 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 ret, tmp;
int base; int base;
uint8_t cmdstring[12]; uint8_t cmdstring[12];
int trig;
devc = sdi->priv; devc = sdi->priv;
@ -365,20 +385,12 @@ static int dso2250_set_trigger_samplerate(const struct sr_dev_inst *sdi)
memset(cmdstring, 0, sizeof(cmdstring)); memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_2250_SET_TRIGGERPOS_AND_BUFFER; cmdstring[0] = CMD_2250_SET_TRIGGERPOS_AND_BUFFER;
/* TODO for big buffer */ sr_dbg("Capture ratio: %d.", devc->capture_ratio);
sr_dbg("Trigger position: %3.2f.", devc->triggerposition); trig = devc->capture_ratio;
// tmp = 0x77fff + 0x8000 * devc->triggerposition; dso2250_set_triggerpos(trig,
// cmdstring[6] = tmp & 0xff; devc->framesize != FRAMESIZE_SMALL, cmdstring, 2);
// cmdstring[7] = (tmp >> 8) & 0xff; dso2250_set_triggerpos(100 - trig,
// cmdstring[10] = (tmp >> 16) & 0xff; devc->framesize != FRAMESIZE_SMALL, cmdstring, 6);
cmdstring[2]=0xff;
cmdstring[3]=0xff;
cmdstring[4]=0x07;
cmdstring[6]=0xff;
cmdstring[7]=0xd7;
cmdstring[8]=0x07;
if (send_begin(sdi) != SR_OK) if (send_begin(sdi) != SR_OK)
return SR_ERR; return SR_ERR;
@ -494,8 +506,8 @@ int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi)
cmdstring[5] = (tmp >> 8) & 0xff; cmdstring[5] = (tmp >> 8) & 0xff;
/* Horizontal trigger position */ /* Horizontal trigger position */
sr_dbg("Trigger position: %3.2f.", devc->triggerposition); sr_dbg("Capture ratio: %d.", devc->capture_ratio);
tmp = 0x77fff + 0x8000 * devc->triggerposition; tmp = 0x77fff + 0x8000 * devc->capture_ratio / 100;
cmdstring[6] = tmp & 0xff; cmdstring[6] = tmp & 0xff;
cmdstring[7] = (tmp >> 8) & 0xff; cmdstring[7] = (tmp >> 8) & 0xff;
cmdstring[10] = (tmp >> 16) & 0xff; cmdstring[10] = (tmp >> 16) & 0xff;

View File

@ -40,7 +40,7 @@
#define DEFAULT_SAMPLERATE SR_KHZ(10) #define DEFAULT_SAMPLERATE SR_KHZ(10)
#define DEFAULT_TRIGGER_SOURCE "CH1" #define DEFAULT_TRIGGER_SOURCE "CH1"
#define DEFAULT_COUPLING COUPLING_DC #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_OFFSET 0.5
#define DEFAULT_VERT_TRIGGERPOS 0.5 #define DEFAULT_VERT_TRIGGERPOS 0.5
@ -202,7 +202,7 @@ struct dev_context {
gboolean filter[2]; gboolean filter[2];
int triggerslope; int triggerslope;
char *triggersource; char *triggersource;
float triggerposition; int capture_ratio;
int triggermode; int triggermode;
/* Frame transfer */ /* Frame transfer */