* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "sigrok.h"
-#include "sigrok-internal.h"
+#include "libsigrok.h"
+#include "libsigrok-internal.h"
#include "config.h"
#include "dso.h"
#include <string.h>
#include <libusb.h>
extern libusb_context *usb_context;
-extern GSList *dev_insts;
+extern struct sr_dev_driver hantek_dso_driver_info;
static int send_begin(struct context *ctx)
return mps;
}
-SR_PRIV int dso_open(int dev_index)
+SR_PRIV int dso_open(struct sr_dev_inst *sdi)
{
libusb_device **devlist;
struct libusb_device_descriptor des;
- struct sr_dev_inst *sdi;
struct context *ctx;
int err, skip, i;
- if (!(sdi = sr_dev_inst_get(dev_insts, dev_index)))
- return SR_ERR_ARG;
ctx = sdi->priv;
if (sdi->status == SR_ST_ACTIVE)
continue;
if (sdi->status == SR_ST_INITIALIZING) {
- if (skip != dev_index) {
+ if (skip != sdi->index) {
/* Skip devices of this type that aren't the one we want. */
skip += 1;
continue;
SR_PRIV int dso_get_capturestate(struct context *ctx, uint8_t *capturestate,
uint32_t *trigger_offset)
{
- int ret, tmp;
+ int ret, tmp, i;
+ unsigned int bitvalue, toff;
uint8_t cmdstring[2], inbuf[512];
sr_dbg("hantek-dso: sending CMD_GET_CAPTURESTATE");
return SR_ERR;
}
*capturestate = inbuf[0];
- *trigger_offset = (inbuf[1] << 16) | (inbuf[3] << 8) | inbuf[2];
+ toff = (inbuf[1] << 16) | (inbuf[3] << 8) | inbuf[2];
+
+ /* This conversion comes from the openhantek project.
+ * Each set bit in the 24-bit value inverts all bits with a lower
+ * value. No idea why the device reports the trigger point this way.
+ */
+ bitvalue = 1;
+ for (i = 0; i < 24; i++) {
+ /* Each set bit inverts all bits with a lower value. */
+ if(toff & bitvalue)
+ toff ^= bitvalue - 1;
+ bitvalue <<= 1;
+ }
+ *trigger_offset = toff;
return SR_OK;
}