How applications on macOS receive APP path data from Norwii wireless presenter.

2024-12-18 13:43:13 诺为

Norwii wireless presenter is a USB HID device (Human Interface Device) for computers, just like a mouse and keyboard. The technology used is the same as wireless keyboard and wireless mouse. 

Currently, if you want to get the key information of the wireless presenter on your computer, or if you want to use the wireless presenter to control the software on your computer, there are two ways. One is to customize the key functions of the wireless presenter as the shortcut keys of the application software in the computer, and the application software triggers the corresponding functions by getting the shortcut keys from the USB HID channel. For this method, please refer to the manual of Norwii Presenter software on the Norwii official website for a more detailed introduction. The other is to customize the data of the APP path of the wireless presenter keys first, and the application software accepts the control by getting the data of the APP path. This article is about how to customize and read the APP path data of the keys of Norwii wireless presenter by the application software on Windows, which is mainly about the program implementation. 

The APP path here refers to a Norwii defined HID channel used to communicate with the APP.

It is possible to customize the short press, long press, and double press of a key as data for the APP path. The short press described in this article is triggered when the key is lifted, if no key is lifted beyond the long press timer, it is a short press. A long press is triggered when a key is held down continuously for more than the long press timer. The long press timer is generally 1 second and may vary for different products or keys. 

I. Using Norwii Presenter software to customize the data of the APP path of the Norwii wireless presenter keys

1. On the [Customize] tab of the Norwii Presenter software, click on the wireless presenter button icon or the blue text corresponding to this icon displayed on the software interface, and the button customization window will open. There are 3 or 4 button modes for the wireless presenter, which can be switched by pressing and holding the page up and page down buttons of the wireless presenter at the same time, and there are 4 modes in the figure below. Users can choose one of the key modes to customize, and the customized result is only valid in this mode. 

Norwii Wireless Presenter

2. Click "drop-down arrow" - "APP Path" in "Short Press Function" to enter the APP Path window, enter one of the decimal number 1~255 as the value of APP Path in the edit box, click "OK" and then click "Save" in the previous window.

Norwii Wireless Presenter

Norwii Wireless Presenter

Norwii Wireless Presenter

Norwii Wireless Presenter

3. How can I be sure that customizing the value of the wireless presenter key to the data of the APP path is successful. 

In the "Pair" tab, short press the key whose short press function has been customized as "APP Path", and "APP Path + number" and the key value will appear in the right window, which means that the customization of the APP path of the wireless presenter key has been successfully set. According to this method, you can also customize the long press function of the key. 

Norwii Wireless Presenter

4. How to get the VID and PID of Norwii Wireless presenter. 

On the [About] tab, find the line that shows "Firmware Information", the right side shows the VID and PID of the wireless presenter, these two values will be used in the USB HID communication. The two values shown on the page are hexadecimal values with 0x omitted, remember to add 0x in front of them when you use them in the program, the VID is hexadecimal value 0x3243 and the PID is hexadecimal value 0x0341 in the following figure, the VID of Norwii wireless presenter is the same, and the PIDs of different product models are different, and the PIDs of the same model are generally the same. The same model and different main control chip will usually have different PID.

Norwii Wireless Presenter

II. Second, USB HID communication.

1. Frameworks: IOKit.framework.

2. Import header files.

#import <IOKit/hid/IOHIDLib.h>

3. Creates an IOHIDManager object.

IOHIDManagerRef managerRef = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);

4. Sets matching criteria for device enumeration.

1)Passing a NULL dictionary will result in all devices being enumerated.

IOHIDManagerSetDeviceMatching(managerRef, NULL);

2)Passing a device matching criteria dictionary will result in specific device class being enumerated.

NSMutableDictionary* dict= [NSMutableDictionary dictionary]; [dict setValue:[NSNumber numberWithLong:pid] forKey:[NSString stringWithCString:kIOHIDProductIDKey encoding:NSUTF8StringEncoding]];] 

[dict setValue:[NSNumber numberWithLong:vid] forKey:[NSString stringWithCString:kIOHIDVendorIDKey encoding:NSUTF8StringEncoding]];] 

IOHIDManagerSetDeviceMatching(managerRef, (__bridge CFMutableDictionaryRef)dict); 

3)If interested in multiple, specific device classes, please defer to using IOHIDManagerSetDeviceMatchingMultiple .

NSMutableArray *arr = [NSMutableArray array]; [arr addObject:dict]. 

IOHIDManagerSetDeviceMatchingMultiple(managerRef, (__bridge CFMutableArrayRef)arr); 

5. Registers a callback to be used a device is enumerated and registers a callback to be used when any enumerated device is removed.

IOHIDManagerRegisterDeviceMatchingCallback(managerRef, &HandleDeviceMatchingCallback, NULL); 

IOHIDManagerRegisterDeviceRemovalCallback(managerRef, &HandleDeviceRemovalCallback, NULL); 

6. Schedules HID manager with run loop.

IOHIDManagerScheduleWithRunLoop(managerRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); 

7. Opens the IOHIDManager.

IOReturn IOReturn = IOHIDManagerOpen(managerRef, kIOHIDOptionsTypeNone); if(kIOReturnSuccess ! = IOReturn) puts("IOHIDManagerOpen failed."); 

8. Pointer to a callback method of type IOHIDDeviceCallback when device is enumerated and enumerated device is removed.

void Handle_DeviceMatchingCallback(void *inContext, IOReturn inResult, void *inSender, IOHIDDeviceRef inIOHIDDeviceRef) { 

    CFTypeRef ref; ref 

    int32_t nVendorID, nProductID;     ref = IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey));     if (CFGetTypeID(ref) == CFNumberGetTypeID()) { 

        CFNumberGetValue((CFNumberRef) ref, kCFNumberSInt32Type, 

&nVendorID);     }     ref = IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDProductIDKey));     if (CFGetTypeID(ref) == CFNumberGetTypeID()) { 

        CFNumberGetValue((CFNumberRef) ref, kCFNumberSInt32Type, 

&nProductID); 

    } 

    NSLog(@"insert hid, vid is:%d, pid is:%d",nVendorID, nProductID);

    CFRelease(ref). 

}  void Handle_DeviceRemovalCallback(void *inContext, IOReturn inResult, void *inSender, IOHIDDeviceRef inIOHIDDeviceRef) 

    CFTypeRef ref; ref     int32_t nVendorID, nProductID;     ref = IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey));     if (CFGetTypeID(ref) == CFNumberGetTypeID()) { 

        CFNumberGetValue((CFNumberRef) ref, kCFNumberSInt32Type, 

&nVendorID);     }     ref = IOHIDDeviceGetProperty(inIOHIDDeviceRef, CFSTR(kIOHIDProductIDKey));     if (CFGetTypeID(ref) == CFNumberGetTypeID()) { 

        CFNumberGetValue((CFNumberRef) ref, kCFNumberSInt32Type, 

&nProductID); 

    } 

    NSLog(@"remove hid, vid is:%d, pid is:%d",nVendorID, nProductID);     CFRelease(ref). 

9. After inserting the USB dongle to get the IOHIDDeviceRef inIOHIDDeviceRef, Opens a HID device for communication.

IOReturn ret = IOHIDDeviceOpen(inIOHIDDeviceRef,options); if (ret ! = kIOReturnSuccess) 

{     printf("Open device failed!\n"); return; return 

10. Registers a callback to be used when an input report is issued by the device , you can receive data. 

unsigned char InputBuffer[64]; 

IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), MyInputCallback, NULL); 

11. Pointer to a callback method of type IOHIDReportCallback , when the operation is defined as "APP path" data key will receive the data sent by the device. 

int appPath = 0; void MyInputCallback(void* context, IOReturn result, void* sender, IOHIDReportType type, uint32_t reportID, uint8_t *report,CFIndex reportLength) 

   memcpy(ReceiveData,report,sizeof(ReceiveData)); 

if (report[0] == 0x03 && report[1] == 0x31 && report[2] == 0x00 

&& report[3] == 0x00 && report[4] == 0x02) { appPath = report[5]; 

 }

12. Sends a report to the device.

IOReturn ret = IOHIDDeviceSetReport(inIOHIDDeviceRef, kIOHIDReportTypeOutput, 0, (uint8_t*)outbuffer, size); if (ret ! = kIOReturnSuccess) { 

    PRINTMSG("Failed to send hid data, error number: %x\r\n",ret);     return ret; 

}

13. Closes communication with a HID device .

IOReturn ret = IOHIDDeviceClose(inIOHIDDeviceRef,0L); if (ret == kIOReturnSuccess) { 

  NSLog(@"Disconnect successful");; 

}

14. Possible problems .

1)TCC deny IOHIDDeviceOpen Open device failed!

Input monitoring permission need to be granted as Norwii Presenter in the following figure. Go to “Launchpad - System settings – Privacy & Security –Input Monitoring” to turn on the switch of your App as Norwii Presenter as shown in the figure.

Norwii Wireless Presenter

2)Still can't open hid after granting permissions.

On APP sandbox page, give hardware rights to read USB.

Here are the steps to check the "USB" option under "TARGETS > Signing & Capabilities > App Sandbox > Hardware" in Xcode:

  • Open Xcode.

  • Open your project (PROJECT).

  • In the project navigation panel, select your target (TARGETS).

  • Click on the "Signing & Capabilities" tab.

  • If "App Sandbox" is not added to your project, you need to click the "Add Capability" button to add it.

  • Within "App Sandbox," locate the "Hardware" section.

  • Check the "USB" option.

Please note that starting from Xcode 13, Apple introduced new App Sandbox features, which might affect how you configure the App Sandbox. If you are using Xcode 13 or later and cannot find the "USB" option, it might be because this option has been moved or changed. In this case, you may need to refer to Apple's official documentation or Xcode's release notes for the most up-to-date configuration methods.

Norwii Wireless Presenter


客服软件