]> sigrok.org Git - libsigrok.git/blobdiff - hardware/hantek-dso/dso.c
sr/drivers: change driver dev_open/dev_close calls to use sdi
[libsigrok.git] / hardware / hantek-dso / dso.c
index 1ad30f097c36eb83bd65b5822c0451584104e49e..98a326c0cb4fe363a62e51afdfed5652a41477aa 100644 (file)
@@ -19,8 +19,8 @@
  * 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>
@@ -28,7 +28,7 @@
 #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)
@@ -104,16 +104,13 @@ err:
        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)
@@ -133,7 +130,7 @@ SR_PRIV int dso_open(int dev_index)
                        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;
@@ -643,7 +640,8 @@ SR_PRIV int dso_init(struct context *ctx)
 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");
@@ -663,7 +661,20 @@ SR_PRIV int dso_get_capturestate(struct context *ctx, uint8_t *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;
 }