int ret, tmp;
uint8_t cmdstring[8];
- sr_dbg("hantek-dso: sending CMD_SET_VOLTAGE");
+ sr_dbg("hantek-dso: preparing CMD_SET_VOLTAGE");
memset(cmdstring, 0, sizeof(cmdstring));
cmdstring[0] = CMD_SET_VOLTAGE;
cmdstring[1] = 0x0f;
- cmdstring[2] = 0x03;
- cmdstring[2] |= ((2 - ctx->voltage_ch1 % 3) << 6);
- cmdstring[2] |= ((2 - ctx->voltage_ch2 % 3) << 4);
-cmdstring[2] = 0x30;
+ cmdstring[2] = 0x30;
+
+ /* CH1 volts/div is encoded in bits 0-1 */
+ sr_dbg("hantek-dso: CH1 vdiv index %d", ctx->voltage_ch1);
+ switch (ctx->voltage_ch1) {
+ case VDIV_1V:
+ case VDIV_100MV:
+ case VDIV_10MV:
+ cmdstring[2] |= 0x00;
+ break;
+ case VDIV_2V:
+ case VDIV_200MV:
+ case VDIV_20MV:
+ cmdstring[2] |= 0x01;
+ break;
+ case VDIV_5V:
+ case VDIV_500MV:
+ case VDIV_50MV:
+ cmdstring[2] |= 0x02;
+ break;
+ }
+
+ /* CH2 volts/div is encoded in bits 2-3 */
+ sr_dbg("hantek-dso: CH2 vdiv index %d", ctx->voltage_ch2);
+ switch (ctx->voltage_ch2) {
+ case VDIV_1V:
+ case VDIV_100MV:
+ case VDIV_10MV:
+ cmdstring[2] |= 0x00;
+ break;
+ case VDIV_2V:
+ case VDIV_200MV:
+ case VDIV_20MV:
+ cmdstring[2] |= 0x08;
+ break;
+ case VDIV_5V:
+ case VDIV_500MV:
+ case VDIV_50MV:
+ cmdstring[2] |= 0x04;
+ break;
+ }
if (send_begin(ctx) != SR_OK)
return SR_ERR;
sr_err("Failed to set voltage: %d", ret);
return SR_ERR;
}
+ sr_dbg("hantek-dso: sent CMD_SET_VOLTAGE");
return SR_OK;
}
uint8_t relays[] = { 0x00, 0x04, 0x08, 0x02, 0x20, 0x40, 0x10, 0x01,
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;
cv2 = ctx->voltage_ch2 / 3;
-relays[0] = 0x01;
+
if (cv1 > 0)
relays[1] = ~relays[1];
if (cv1 > 1)
relays[2] = ~relays[2];
+ sr_dbg("hantek-dso: CH1 coupling %d", ctx->coupling_ch1);
if (ctx->coupling_ch1 != COUPLING_AC)
relays[3] = ~relays[3];
if (cv2 > 1)
relays[5] = ~relays[5];
+ sr_dbg("hantek-dso: CH2 coupling %d", ctx->coupling_ch1);
if (ctx->coupling_ch2 != COUPLING_AC)
relays[6] = ~relays[6];
sr_err("failed to set relays: %d", ret);
return SR_ERR;
}
+ sr_dbg("hantek-dso: sent CTRL_SETRELAYS");
return SR_OK;
}
if (dso_enable_trigger(ctx) != SR_OK)
return SR_ERR;
- if (dso_force_trigger(ctx) != SR_OK)
- return SR_ERR;
-
return SR_OK;
}