2 * This file is part of the sigrok project.
4 * Copyright (C) 2010 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 extern struct sigrok_global *global;
26 GSList *devices = NULL;
29 void device_scan(void)
32 struct device_plugin *plugin;
35 plugins = list_hwplugins();
37 /* initialize all plugins first. Since the init() call may involve
38 * a firmware upload and associated delay, we may as well get all
39 * of these out of the way first.
41 for(l = plugins; l; l = l->next)
44 g_message("initializing %s plugin", plugin->name);
45 num_devices = plugin->init(NULL);
46 for(i = 0; i < num_devices; i++)
48 device_new(plugin, i);
55 void device_close_all(void)
57 struct device *device;
61 device = devices->data;
62 device->plugin->close(device->plugin_index);
63 device_destroy(device);
69 GSList *device_list(void)
76 struct device *device_new(struct device_plugin *plugin, int plugin_index)
78 struct device *device;
82 device = g_malloc0(sizeof(struct device));
83 device->plugin = plugin;
84 device->plugin_index = plugin_index;
85 devices = g_slist_append(devices, device);
87 num_probes = (int) device->plugin->get_device_info(device->plugin_index, DI_NUM_PROBES);
88 for(i = 0; i < num_probes; i++)
90 snprintf(probename, 16, "%d", i+1);
91 device_probe_add(device, probename);
98 void device_clear(struct device *device)
102 /* TODO: plugin-specific clear call? */
105 for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
106 device_probe_clear(device, probenum);
111 void device_destroy(struct device *device)
115 /* TODO: plugin-specific destroy call, need to decrease refcount in plugin */
117 devices = g_slist_remove(devices, device);
120 for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
121 device_probe_clear(device, probenum);
122 g_slist_free(device->probes);
129 void device_probe_clear(struct device *device, int probenum)
133 p = probe_find(device, probenum);
152 void device_probe_add(struct device *device, char *name)
156 p = g_malloc0(sizeof(struct probe));
157 p->index = g_slist_length(device->probes) + 1;
159 p->name = g_strdup(name);
161 device->probes = g_slist_append(device->probes, p);
166 struct probe *probe_find(struct device *device, int probenum)
169 struct probe *p, *found_probe;
172 for(l = device->probes; l; l = l->next)
175 if(p->index == probenum)
186 void device_probe_name(struct device *device, int probenum, char *name)
190 p = probe_find(device, probenum);
196 p->name = g_strdup(name);
201 void device_trigger_clear(struct device *device)
207 for(probenum = 1; probenum <= g_slist_length(device->probes); probenum++)
209 p = probe_find(device, probenum);
220 void device_trigger_set(struct device *device, int probenum, char *trigger)
224 p = probe_find(device, probenum);
231 p->trigger = g_strdup(trigger);