]> sigrok.org Git - libsigrok.git/blobdiff - device.c
Don't close/reset the FTDI device too often.
[libsigrok.git] / device.c
index dd3a4000bcc6b9f9405ba673aca5035eedb8acfe..6e9a30086b610a590ac9c3190ff5698751758166 100644 (file)
--- a/device.c
+++ b/device.c
@@ -20,6 +20,7 @@
 #include <stdio.h>
 #include <glib.h>
 #include <sigrok.h>
+#include <sigrok-internal.h>
 
 extern struct sr_global *global;
 
@@ -30,7 +31,7 @@ void sr_device_scan(void)
        GSList *plugins, *l;
        struct sr_device_plugin *plugin;
 
-       plugins = list_hwplugins();
+       plugins = sr_list_hwplugins();
 
        /*
         * Initialize all plugins first. Since the init() call may involve
@@ -48,7 +49,7 @@ int sr_device_plugin_init(struct sr_device_plugin *plugin)
 {
        int num_devices, num_probes, i;
 
-       g_message("initializing %s plugin", plugin->name);
+       sr_info("initializing %s plugin", plugin->name);
        num_devices = plugin->init(NULL);
        for (i = 0; i < num_devices; i++) {
                num_probes = (int)plugin->get_device_info(i, SR_DI_NUM_PROBES);
@@ -131,7 +132,7 @@ void sr_device_probe_clear(struct sr_device *device, int probenum)
 {
        struct sr_probe *p;
 
-       p = probe_find(device, probenum);
+       p = sr_device_probe_find(device, probenum);
        if (!p)
                return;
 
@@ -146,7 +147,7 @@ void sr_device_probe_clear(struct sr_device *device, int probenum)
        }
 }
 
-void sr_device_probe_add(struct sr_device *device, char *name)
+void sr_device_probe_add(struct sr_device *device, const char *name)
 {
        struct sr_probe *p;
        char probename[16];
@@ -166,7 +167,7 @@ void sr_device_probe_add(struct sr_device *device, char *name)
        device->probes = g_slist_append(device->probes, p);
 }
 
-struct sr_probe *probe_find(struct sr_device *device, int probenum)
+struct sr_probe *sr_device_probe_find(struct sr_device *device, int probenum)
 {
        GSList *l;
        struct sr_probe *p, *found_probe;
@@ -184,11 +185,12 @@ struct sr_probe *probe_find(struct sr_device *device, int probenum)
 }
 
 /* TODO: return SIGROK_ERR if probenum not found */
-void sr_device_probe_name(struct sr_device *device, int probenum, char *name)
+void sr_device_probe_name(struct sr_device *device, int probenum,
+                         const char *name)
 {
        struct sr_probe *p;
 
-       p = probe_find(device, probenum);
+       p = sr_device_probe_find(device, probenum);
        if (!p)
                return;
 
@@ -207,7 +209,7 @@ void sr_device_trigger_clear(struct sr_device *device)
                return;
 
        for (pnum = 1; pnum <= g_slist_length(device->probes); pnum++) {
-               p = probe_find(device, pnum);
+               p = sr_device_probe_find(device, pnum);
                if (p && p->trigger) {
                        g_free(p->trigger);
                        p->trigger = NULL;
@@ -216,11 +218,12 @@ void sr_device_trigger_clear(struct sr_device *device)
 }
 
 /* TODO: return SIGROK_ERR if probenum not found */
-void sr_device_trigger_set(struct sr_device *device, int probenum, char *trigger)
+void sr_device_trigger_set(struct sr_device *device, int probenum,
+                          const char *trigger)
 {
        struct sr_probe *p;
 
-       p = probe_find(device, probenum);
+       p = sr_device_probe_find(device, probenum);
        if (!p)
                return;
 
@@ -235,6 +238,9 @@ gboolean sr_device_has_hwcap(struct sr_device *device, int hwcap)
 {
        int *capabilities, i;
 
+       if (!device || !device->plugin)
+               return FALSE;
+
        if ((capabilities = device->plugin->get_capabilities()))
                for (i = 0; capabilities[i]; i++)
                        if (capabilities[i] == hwcap)