]> sigrok.org Git - libsigrok.git/blobdiff - src/hardware/hantek-dso/dso.c
fluke-dmm: File naming consistency changes.
[libsigrok.git] / src / hardware / hantek-dso / dso.c
index 814db59839785139211b9347dc5d155a94aec00e..3d799664a530cdb550ab952fcfbc8c16fa9beb05 100644 (file)
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#include "libsigrok.h"
-#include "libsigrok-internal.h"
-#include "dso.h"
+#include <config.h>
 #include <string.h>
 #include <glib.h>
 #include <libusb.h>
+#include <libsigrok/libsigrok.h>
+#include "libsigrok-internal.h"
+#include "dso.h"
 
-extern struct sr_dev_driver hantek_dso_driver_info;
+#define NUM_CHANNELS 2
 
 static int send_begin(const struct sr_dev_inst *sdi)
 {
@@ -73,8 +74,7 @@ static int dso_getmps(libusb_device *dev)
        const struct libusb_interface_descriptor *intf_dsc;
        int mps;
 
-       if (libusb_get_device_descriptor(dev, &des) != 0)
-               return 0;
+       libusb_get_device_descriptor(dev, &des);
 
        if (des.bNumConfigurations != 1)
                return 0;
@@ -109,7 +109,7 @@ err:
 SR_PRIV int dso_open(struct sr_dev_inst *sdi)
 {
        struct dev_context *devc;
-       struct drv_context *drvc = hantek_dso_driver_info.priv;
+       struct drv_context *drvc = sdi->driver->context;
        struct sr_usb_dev_inst *usb;
        struct libusb_device_descriptor des;
        libusb_device **devlist;
@@ -125,11 +125,7 @@ SR_PRIV int dso_open(struct sr_dev_inst *sdi)
 
        libusb_get_device_list(drvc->sr_ctx->libusb_ctx, &devlist);
        for (i = 0; devlist[i]; i++) {
-               if ((err = libusb_get_device_descriptor(devlist[i], &des))) {
-                       sr_err("Failed to get device descriptor: %s.",
-                              libusb_error_name(err));
-                       continue;
-               }
+               libusb_get_device_descriptor(devlist[i], &des);
 
                if (des.idVendor != devc->profile->fw_vid
                    || des.idProduct != devc->profile->fw_pid)
@@ -185,7 +181,7 @@ SR_PRIV void dso_close(struct sr_dev_inst *sdi)
 
        usb = sdi->conn;
 
-       if (usb->devhdl == NULL)
+       if (!usb->devhdl)
                return;
 
        sr_info("Closing device on %d.%d (logical) / %s (physical) interface %d.",
@@ -225,7 +221,7 @@ static int get_channel_offsets(const struct sr_dev_inst *sdi)
         * since that's how voltage offsets are submitted back to the DSO.
         * Convert to host order now, so we can use them natively.
         */
-       for (chan = 0; chan < 2; chan++) {
+       for (chan = 0; chan < NUM_CHANNELS; chan++) {
                for (v = 0; v < 9; v++) {
                        devc->channel_levels[chan][v][0] =
                                g_ntohs(devc->channel_levels[chan][v][0]);
@@ -236,7 +232,7 @@ static int get_channel_offsets(const struct sr_dev_inst *sdi)
 
        if (sr_log_loglevel_get() >= SR_LOG_DBG) {
                gs = g_string_sized_new(128);
-               for (chan = 0; chan < 2; chan++) {
+               for (chan = 0; chan < NUM_CHANNELS; chan++) {
                        g_string_printf(gs, "CH%d:", chan + 1);
                        for (v = 0; v < 9; v++) {
                                g_string_append_printf(gs, " %.4x-%.4x",
@@ -319,8 +315,8 @@ static int dso_set_trigger_samplerate(const struct sr_dev_inst *sdi)
        cmdstring[2] |= (tmp & 0x07) << 5;
 
        /* Enabled channels: 00=CH1 01=CH2 10=both */
-       sr_dbg("Channels CH1=%d CH2=%d", devc->ch1_enabled, devc->ch2_enabled);
-       tmp = (((devc->ch2_enabled ? 1 : 0) << 1) + (devc->ch1_enabled ? 1 : 0)) - 1;
+       sr_dbg("Channels CH1=%d CH2=%d", devc->ch_enabled[0], devc->ch_enabled[1]);
+       tmp = (((devc->ch_enabled[1] ? 1 : 0) << 1) + (devc->ch_enabled[0] ? 1 : 0)) - 1;
        cmdstring[3] = tmp;
 
        /* Fast rates channel */