fix syntax
This commit is contained in:
35
hidapi.c
35
hidapi.c
@@ -21,8 +21,9 @@ static const char *bus_type_to_string(SDL_hid_bus_type type) {
|
||||
|
||||
// Helper to convert device info to JS object
|
||||
static JSValue device_info_to_js(JSContext *js, SDL_hid_device_info *info) {
|
||||
JSValue obj = JS_NewObject(js);
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(obj, JS_NewObject(js));
|
||||
|
||||
if (info->path)
|
||||
JS_SetPropertyStr(js, obj, "path", JS_NewString(js, info->path));
|
||||
JS_SetPropertyStr(js, obj, "vendor_id", JS_NewUint32(js, info->vendor_id));
|
||||
@@ -35,8 +36,7 @@ static JSValue device_info_to_js(JSContext *js, SDL_hid_device_info *info) {
|
||||
JS_SetPropertyStr(js, obj, "interface_subclass", JS_NewInt32(js, info->interface_subclass));
|
||||
JS_SetPropertyStr(js, obj, "interface_protocol", JS_NewInt32(js, info->interface_protocol));
|
||||
JS_SetPropertyStr(js, obj, "bus_type", JS_NewString(js, bus_type_to_string(info->bus_type)));
|
||||
|
||||
// Convert wide strings to UTF-8
|
||||
|
||||
if (info->serial_number) {
|
||||
char buf[256];
|
||||
wcstombs(buf, info->serial_number, sizeof(buf) - 1);
|
||||
@@ -55,8 +55,8 @@ static JSValue device_info_to_js(JSContext *js, SDL_hid_device_info *info) {
|
||||
buf[sizeof(buf) - 1] = 0;
|
||||
JS_SetPropertyStr(js, obj, "product", JS_NewString(js, buf));
|
||||
}
|
||||
|
||||
return obj;
|
||||
|
||||
JS_RETURN(obj);
|
||||
}
|
||||
|
||||
// SDL_hid_init() -> int
|
||||
@@ -82,15 +82,16 @@ JSC_CCALL(hidapi_enumerate,
|
||||
|
||||
SDL_hid_device_info *devs = SDL_hid_enumerate(vendor_id, product_id);
|
||||
if (!devs) return JS_NewArray(js);
|
||||
|
||||
JSValue arr = JS_NewArray(js);
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(arr, JS_NewArray(js));
|
||||
int i = 0;
|
||||
for (SDL_hid_device_info *cur = devs; cur; cur = cur->next) {
|
||||
JS_SetPropertyUint32(js, arr, i++, device_info_to_js(js, cur));
|
||||
JS_SetPropertyNumber(js, arr, i++, device_info_to_js(js, cur));
|
||||
}
|
||||
|
||||
|
||||
SDL_hid_free_enumeration(devs);
|
||||
return arr;
|
||||
JS_RETURN(arr);
|
||||
)
|
||||
|
||||
// SDL_hid_open(vendor_id, product_id) -> device
|
||||
@@ -265,16 +266,16 @@ static const JSCFunctionListEntry js_hidapi_funcs[] = {
|
||||
|
||||
CELL_USE_INIT(
|
||||
QJSCLASSPREP_FUNCS(SDL_hid_device);
|
||||
|
||||
JSValue ret = JS_NewObject(js);
|
||||
|
||||
JS_FRAME(js);
|
||||
JS_LOCAL(ret, JS_NewObject(js));
|
||||
JS_SetPropertyFunctionList(js, ret, js_hidapi_funcs, countof(js_hidapi_funcs));
|
||||
|
||||
// Export bus type constants
|
||||
|
||||
JS_SetPropertyStr(js, ret, "BUS_UNKNOWN", JS_NewInt32(js, SDL_HID_API_BUS_UNKNOWN));
|
||||
JS_SetPropertyStr(js, ret, "BUS_USB", JS_NewInt32(js, SDL_HID_API_BUS_USB));
|
||||
JS_SetPropertyStr(js, ret, "BUS_BLUETOOTH", JS_NewInt32(js, SDL_HID_API_BUS_BLUETOOTH));
|
||||
JS_SetPropertyStr(js, ret, "BUS_I2C", JS_NewInt32(js, SDL_HID_API_BUS_I2C));
|
||||
JS_SetPropertyStr(js, ret, "BUS_SPI", JS_NewInt32(js, SDL_HID_API_BUS_SPI));
|
||||
|
||||
return ret;
|
||||
|
||||
JS_RETURN(ret);
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user