GLOBAL 和 LOCAL 项的区别在于,在解析过程中顺序遇到下一个 MAIN 项时会保留 GLOBAL 项的值,但不保留 LOCAL 项的值。当遇到下一个 MAIN 项时,所有 LOCAL 项的值都将重置为其默认状态。 REPORT_ID 是一个 GLOBAL 项目,这意味着一旦您设置它,它的值将保持不变,直到您将其设置为另一个值。
您发布的示例将被解析为以下结构(使用C语言语法):
//--------------------------------------------------------------------------------
// Generic Desktop Page inputReport 01 (Device --> Host)
//--------------------------------------------------------------------------------
typedef struct
{
uint8_t reportId; // Report ID = 0x01 (1)
// Collection: CA:Joystick
uint8_t pad_1; // Pad
uint8_t BTN_JoystickButton1 : 1; // Usage 0x00090001: Button 1 Primary/trigger, Value = 0 to 1
uint8_t BTN_JoystickButton2 : 1; // Usage 0x00090002: Button 2 Secondary, Value = 0 to 1
uint8_t BTN_JoystickButton3 : 1; // Usage 0x00090003: Button 3 Tertiary, Value = 0 to 1
uint8_t BTN_JoystickButton4 : 1; // Usage 0x00090004: Button 4, Value = 0 to 1
uint8_t BTN_JoystickButton5 : 1; // Usage 0x00090005: Button 5, Value = 0 to 1
uint8_t BTN_JoystickButton6 : 1; // Usage 0x00090006: Button 6, Value = 0 to 1
uint8_t BTN_JoystickButton7 : 1; // Usage 0x00090007: Button 7, Value = 0 to 1
uint8_t BTN_JoystickButton8 : 1; // Usage 0x00090008: Button 8, Value = 0 to 1
uint8_t BTN_JoystickButton9 : 1; // Usage 0x00090009: Button 9, Value = 0 to 1
uint8_t BTN_JoystickButton10 : 1; // Usage 0x0009000A: Button 10, Value = 0 to 1
uint8_t BTN_JoystickButton11 : 1; // Usage 0x0009000B: Button 11, Value = 0 to 1
uint8_t BTN_JoystickButton12 : 1; // Usage 0x0009000C: Button 12, Value = 0 to 1
uint8_t BTN_JoystickButton13 : 1; // Usage 0x0009000D: Button 13, Value = 0 to 1
uint8_t BTN_JoystickButton14 : 1; // Usage 0x0009000E: Button 14, Value = 0 to 1
uint8_t BTN_JoystickButton15 : 1; // Usage 0x0009000F: Button 15, Value = 0 to 1
uint8_t BTN_JoystickButton16 : 1; // Usage 0x00090010: Button 16, Value = 0 to 1
uint8_t BTN_JoystickButton17 : 1; // Usage 0x00090011: Button 17, Value = 0 to 1
uint8_t BTN_JoystickButton18 : 1; // Usage 0x00090012: Button 18, Value = 0 to 1
uint8_t BTN_JoystickButton19 : 1; // Usage 0x00090013: Button 19, Value = 0 to 1
} inputReport01_t;
在内存中如下所示:
Bit: 7 6 5 4 3 2 1 0
.---------------------------------------.
Byte 0 | Report ID (0x01) |
|---------------------------------------|
Byte 1 | Pad |
|---------------------------------------|
Byte 2 | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | Buttons 1 to 8
|---------------------------------------|
Byte 3 | 16 | 15 | 14 | 13 | 12 | 11 | 10 | 9 | Buttons 9 to 16
|---------------------------------------|
Byte 4 | | | | | | 19 | 18 | 17 | Buttons 17 to 19
'---------------------------------------'
换句话说,您看到的是指定报告描述符的正确布局。您可能误解了Input (Cnst,Var,Abs,NWrp,Lin,Pref,NNul,Bit) 81 03 项的意义——它定义了一个“常量”字节——即一个不包含任何信息但在网络上传输的报告中占用空间的字节。