Skip to content

Commit d7a1806

Browse files
committed
refactor: implement fnusb_get_device_attributes()
Signed-off-by: Benn Snyder <[email protected]>
1 parent 2bbf9e0 commit d7a1806

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/usb_libusb10.c

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,39 @@ FN_INTERNAL char* usb_get_serial(freenect_context* ctx, libusb_device* device, l
204204
return NULL;
205205
}
206206

207+
const char* const K4W_1473_SERIAL = "0000000000000000";
208+
if (strncmp((const char*)serial, K4W_1473_SERIAL, 16) == 0) {
209+
return NULL; // K4W and 1473 provide an empty serial; more easily handled as NULL.
210+
}
211+
207212
return strndup((const char*)serial, sizeof(serial));
208213
}
209214

215+
FN_INTERNAL int fnusb_get_device_attributes(freenect_device* dev, struct freenect_device_attributes* attributes)
216+
{
217+
freenect_context* ctx = dev->parent;
218+
219+
int res = 0;
220+
221+
char* serial = usb_get_serial(ctx, NULL, dev->usb_cam.dev, NULL);
222+
if (serial == NULL)
223+
{
224+
char* audio_serial = usb_get_serial(ctx, NULL, dev->usb_audio.dev, NULL);
225+
if (audio_serial) {
226+
free(serial);
227+
serial = audio_serial;
228+
}
229+
}
230+
231+
if (serial == NULL) {
232+
return -1;
233+
}
234+
235+
attributes->next = NULL;
236+
attributes->camera_serial = serial;
237+
return res;
238+
}
239+
210240
FN_INTERNAL int fnusb_list_device_attributes(freenect_context *ctx, struct freenect_device_attributes** attribute_list)
211241
{
212242
*attribute_list = NULL; // initialize some return value in case the user is careless.
@@ -240,10 +270,7 @@ FN_INTERNAL int fnusb_list_device_attributes(freenect_context *ctx, struct freen
240270
}
241271

242272
char* serial = usb_get_serial(ctx, camera_device, NULL, &desc);
243-
244-
// K4W and 1473 don't provide a camera serial; use audio serial instead.
245-
const char* const K4W_1473_SERIAL = "0000000000000000";
246-
if (serial == NULL || strncmp((const char*)serial, K4W_1473_SERIAL, 16) == 0)
273+
if (serial == NULL)
247274
{
248275
libusb_device* audio_device = fnusb_find_sibling_device(ctx, camera_device, devs, count, &fnusb_is_audio);
249276
if (audio_device != NULL)

src/usb_libusb10.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ typedef struct {
7575
} fnusb_isoc_stream;
7676

7777
int fnusb_num_devices(freenect_context *ctx);
78+
int fnusb_get_device_attributes(freenect_device* dev, struct freenect_device_attributes* attributes);
7879
int fnusb_list_device_attributes(freenect_context *ctx, struct freenect_device_attributes** attribute_list);
7980

8081
int fnusb_init(fnusb_ctx *ctx, freenect_usb_context *usb_ctx);

0 commit comments

Comments
 (0)