summaryrefslogtreecommitdiffstats
path: root/macos.c
diff options
context:
space:
mode:
Diffstat (limited to 'macos.c')
-rw-r--r--macos.c67
1 files changed, 48 insertions, 19 deletions
diff --git a/macos.c b/macos.c
index 25d6fd73f..b75ddbf6f 100644
--- a/macos.c
+++ b/macos.c
@@ -45,27 +45,54 @@ const char *system_default_filename(void)
return buffer;
}
-int enumerate_devices(device_callback_t callback, void *userdata)
+int enumerate_devices(device_callback_t callback, void *userdata, int dc_type)
{
- int index = -1;
+ int index = -1, entries = 0;
DIR *dp = NULL;
struct dirent *ep = NULL;
size_t i;
- const char *dirname = "/dev";
- const char *patterns[] = {
- "tty.*",
- "usbserial",
- NULL
- };
-
- dp = opendir(dirname);
- if (dp == NULL) {
- return -1;
+ if (dc_type != DC_TYPE_UEMIS) {
+ const char *dirname = "/dev";
+ const char *patterns[] = {
+ "tty.*",
+ "usbserial",
+ NULL
+ };
+
+ dp = opendir(dirname);
+ if (dp == NULL) {
+ return -1;
+ }
+
+ while ((ep = readdir(dp)) != NULL) {
+ for (i = 0; patterns[i] != NULL; ++i) {
+ if (fnmatch(patterns[i], ep->d_name, 0) == 0) {
+ char filename[1024];
+ int n = snprintf(filename, sizeof(filename), "%s/%s", dirname, ep->d_name);
+ if (n >= sizeof(filename)) {
+ closedir(dp);
+ return -1;
+ }
+ callback(filename, userdata);
+ if (is_default_dive_computer_device(filename))
+ index = entries;
+ entries++;
+ break;
+ }
+ }
+ }
+ closedir(dp);
}
+ if (dc_type != DC_TYPE_SERIAL) {
+ const char *dirname = "/Volumes";
+ int num_uemis = 0;
+ dp = opendir(dirname);
+ if (dp == NULL) {
+ return -1;
+ }
- while ((ep = readdir(dp)) != NULL) {
- for (i = 0; patterns[i] != NULL; ++i) {
- if (fnmatch(patterns[i], ep->d_name, 0) == 0) {
+ while ((ep = readdir(dp)) != NULL) {
+ if (fnmatch("UEMISSDA", ep->d_name, 0) == 0) {
char filename[1024];
int n = snprintf(filename, sizeof(filename), "%s/%s", dirname, ep->d_name);
if (n >= sizeof(filename)) {
@@ -74,14 +101,16 @@ int enumerate_devices(device_callback_t callback, void *userdata)
}
callback(filename, userdata);
if (is_default_dive_computer_device(filename))
- index = i;
+ index = entries;
+ entries++;
+ num_uemis++;
break;
}
}
+ closedir(dp);
+ if (num_uemis == 1 && entries == 1) /* if we find exactly one entry and that's a Uemis, select it */
+ index = 0;
}
- // TODO: list UEMIS mount point from /proc/mounts
-
- closedir(dp);
return index;
}