hantek-dso: support for SR_HWCAP_COUPLING

This commit is contained in:
Bert Vermeulen 2012-05-17 03:17:09 +02:00
parent e1c8b2abfb
commit b58fbd99c8
3 changed files with 29 additions and 4 deletions

View File

@ -125,6 +125,13 @@ static char *filter_targets[] = {
NULL NULL
}; };
static char *coupling[] = {
"AC",
"DC",
"GND",
NULL
};
SR_PRIV libusb_context *usb_context = NULL; SR_PRIV libusb_context *usb_context = NULL;
SR_PRIV GSList *dev_insts = NULL; SR_PRIV GSList *dev_insts = NULL;
@ -516,6 +523,19 @@ static int hw_dev_config_set(int dev_index, int hwcap, void *value)
if (vdivs[i].p == 0 && vdivs[i].q == 0) if (vdivs[i].p == 0 && vdivs[i].q == 0)
ret = SR_ERR_ARG; ret = SR_ERR_ARG;
break; break;
case SR_HWCAP_COUPLING:
/* TODO not supporting coupling per channel yet */
tmp_str = value;
for (i = 0; coupling[i]; i++) {
if (!strcmp(tmp_str, coupling[i])) {
ctx->coupling_ch1 = i;
ctx->coupling_ch2 = i;
break;
}
}
if (coupling[i] == 0)
ret = SR_ERR_ARG;
break;
default: default:
ret = SR_ERR_ARG; ret = SR_ERR_ARG;
} }

View File

@ -445,17 +445,18 @@ SR_PRIV int dso_set_relays(struct context *ctx)
uint8_t relays[] = { 0x00, 0x04, 0x08, 0x02, 0x20, 0x40, 0x10, 0x01, uint8_t relays[] = { 0x00, 0x04, 0x08, 0x02, 0x20, 0x40, 0x10, 0x01,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
sr_dbg("hantek-dso: sending CTRL_SETRELAYS"); sr_dbg("hantek-dso: preparing CTRL_SETRELAYS");
cv1 = ctx->voltage_ch1 / 3; cv1 = ctx->voltage_ch1 / 3;
cv2 = ctx->voltage_ch2 / 3; cv2 = ctx->voltage_ch2 / 3;
relays[0] = 0x01;
if (cv1 > 0) if (cv1 > 0)
relays[1] = ~relays[1]; relays[1] = ~relays[1];
if (cv1 > 1) if (cv1 > 1)
relays[2] = ~relays[2]; relays[2] = ~relays[2];
sr_dbg("hantek-dso: CH1 coupling %d", ctx->coupling_ch1);
if (ctx->coupling_ch1 != COUPLING_AC) if (ctx->coupling_ch1 != COUPLING_AC)
relays[3] = ~relays[3]; relays[3] = ~relays[3];
@ -465,6 +466,7 @@ relays[0] = 0x01;
if (cv2 > 1) if (cv2 > 1)
relays[5] = ~relays[5]; relays[5] = ~relays[5];
sr_dbg("hantek-dso: CH2 coupling %d", ctx->coupling_ch1);
if (ctx->coupling_ch2 != COUPLING_AC) if (ctx->coupling_ch2 != COUPLING_AC)
relays[6] = ~relays[6]; relays[6] = ~relays[6];
@ -477,6 +479,7 @@ relays[0] = 0x01;
sr_err("failed to set relays: %d", ret); sr_err("failed to set relays: %d", ret);
return SR_ERR; return SR_ERR;
} }
sr_dbg("hantek-dso: sent CTRL_SETRELAYS");
return SR_OK; return SR_OK;
} }

View File

@ -72,12 +72,14 @@ enum dso_commands {
cmdGetLogicalData cmdGetLogicalData
}; };
/* Must match the coupling table. */
enum couplings { enum couplings {
COUPLING_AC = 0, COUPLING_AC = 0,
COUPLING_DC, COUPLING_DC,
COUPLING_OFF COUPLING_GND
}; };
/* Must match the timebases table. */
enum time_bases { enum time_bases {
TIME_10us = 0, TIME_10us = 0,
TIME_20us, TIME_20us,
@ -96,7 +98,7 @@ enum time_bases {
TIME_400ms TIME_400ms
}; };
/* Must match the vdivs table, these are just handy indexes into it. */ /* Must match the vdivs table. */
enum { enum {
VDIV_10MV, VDIV_10MV,
VDIV_20MV, VDIV_20MV,