Loading...
 

Arduino USB HID

; USAGE_PAGE (Generic Desktop)
    retlw  0x05
    retlw  0x01

    ; USAGE (Joystick - 0x04  Gamepad - 0x05; Multi-axis Controller - 0x08)
    retlw  0x09
    retlw  joystickType

    ; COLLECTION (Application)
    retlw  0xa1
    retlw  0x01

    ; REPORT_ID (Default: 3)
    retlw  0x85
    retlw  _hidReportId

    if (_buttonCount > 0) {

        ; USAGE_PAGE (Button)
        retlw  0x05
        retlw  0x09

        ; USAGE_MINIMUM (Button 1)
        retlw  0x19
        retlw  0x01

        ; USAGE_MAXIMUM (Button 32)
        retlw  0x29
        retlw  _buttonCount

        ; LOGICAL_MINIMUM (0)
        retlw  0x15
        retlw  0x00

        ; LOGICAL_MAXIMUM (1)
        retlw  0x25
        retlw  0x01

        ; REPORT_SIZE (1)
        retlw  0x75
        retlw  0x01

        ; REPORT_COUNT (# of buttons)
        retlw  0x95
        retlw  _buttonCount

        ; UNIT_EXPONENT (0)
        retlw  0x55
        retlw  0x00

        ; UNIT (None)
        retlw  0x65
        retlw  0x00

        ; INPUT (Data,Var,Abs)
        retlw  0x81
        retlw  0x02

        if (buttonPaddingBits > 0) {

            ; REPORT_SIZE (1)
            retlw  0x75
            retlw  0x01

            ; REPORT_COUNT (# of padding bits)
            retlw  0x95
            retlw  buttonPaddingBits

            ; INPUT (Const,Var,Abs)
            retlw  0x81
            retlw  0x03

        } ; Padding Bits Needed

    } ; Buttons

    if ((axisCount > 0) || (_hatSwitchCount > 0)) {

        ; USAGE_PAGE (Generic Desktop)
        retlw  0x05
        retlw  0x01

    }

    if (_hatSwitchCount > 0) {

        ; USAGE (Hat Switch)
        retlw  0x09
        retlw  0x39

        ; LOGICAL_MINIMUM (0)
        retlw  0x15
        retlw  0x00

        ; LOGICAL_MAXIMUM (7)
        retlw  0x25
        retlw  0x07

        ; PHYSICAL_MINIMUM (0)
        retlw  0x35
        retlw  0x00

        ; PHYSICAL_MAXIMUM (315)
        retlw  0x46
        retlw  0x3B
        retlw  0x01

        ; UNIT (Eng Rot:Angular Pos)
        retlw  0x65
        retlw  0x14

        ; REPORT_SIZE (4)
        retlw  0x75
        retlw  0x04

        ; REPORT_COUNT (1)
        retlw  0x95
        retlw  0x01

        ; INPUT (Data,Var,Abs)
        retlw  0x81
        retlw  0x02

        if (_hatSwitchCount > 1) {

            ; USAGE (Hat Switch)
            retlw  0x09
            retlw  0x39

            ; LOGICAL_MINIMUM (0)
            retlw  0x15
            retlw  0x00

            ; LOGICAL_MAXIMUM (7)
            retlw  0x25
            retlw  0x07

            ; PHYSICAL_MINIMUM (0)
            retlw  0x35
            retlw  0x00

            ; PHYSICAL_MAXIMUM (315)
            retlw  0x46
            retlw  0x3B
            retlw  0x01

            ; UNIT (Eng Rot:Angular Pos)
            retlw  0x65
            retlw  0x14

            ; REPORT_SIZE (4)
            retlw  0x75
            retlw  0x04

            ; REPORT_COUNT (1)
            retlw  0x95
            retlw  0x01

            ; INPUT (Data,Var,Abs)
            retlw  0x81
            retlw  0x02

        } else {

            ; Use Padding Bits

            ; REPORT_SIZE (1)
            retlw  0x75
            retlw  0x01

            ; REPORT_COUNT (4)
            retlw  0x95
            retlw  0x04

            ; INPUT (Const,Var,Abs)
            retlw  0x81
            retlw  0x03

        } ; One or Two Hat Switches?

    } ; Hat Switches

    if (axisCount > 0) {

        ; USAGE (Pointer)
        retlw  0x09
        retlw  0x01

        ; LOGICAL_MINIMUM (-32767)
        retlw  0x16
        retlw  0x01
        retlw  0x80

        ; LOGICAL_MAXIMUM (+32767)
        retlw  0x26
        retlw  0xFF
        retlw  0x7F

        ; REPORT_SIZE (16)
        retlw  0x75
        retlw  0x10

        ; REPORT_COUNT (axisCount)
        retlw  0x95
        retlw  axisCount

        ; COLLECTION (Physical)
        retlw  0xA1
        retlw  0x00

        if (includeXAxis == true) {
            ; USAGE (X)
            retlw  0x09
            retlw  0x30
        }

        if (includeYAxis == true) {
            ; USAGE (Y)
            retlw  0x09
            retlw  0x31
        }

        if (includeZAxis == true) {
            ; USAGE (Z)
            retlw  0x09
            retlw  0x32
        }

        if (includeRxAxis == true) {
            ; USAGE (Rx)
            retlw  0x09
            retlw  0x33
        }

        if (includeRyAxis == true) {
            ; USAGE (Ry)
            retlw  0x09
            retlw  0x34
        }

        if (includeRzAxis == true) {
            ; USAGE (Rz)
            retlw  0x09
            retlw  0x35
        }

        ; INPUT (Data,Var,Abs)
        retlw  0x81
        retlw  0x02

        ; END_COLLECTION (Physical)
        retlw  0xc0

    } ; X, Y, Z, Rx, Ry, and Rz Axis

    if (simulationCount > 0) {

        ; USAGE_PAGE (Simulation Controls)
        retlw  0x05
        retlw  0x02

        ; LOGICAL_MINIMUM (-32767)
        retlw  0x16
        retlw  0x01
        retlw  0x80

        ; LOGICAL_MAXIMUM (+32767)
        retlw  0x26
        retlw  0xFF
        retlw  0x7F

        ; REPORT_SIZE (16)
        retlw  0x75
        retlw  0x10

        ; REPORT_COUNT (simulationCount)
        retlw  0x95
        retlw  simulationCount

        ; COLLECTION (Physical)
        retlw  0xA1
        retlw  0x00

        if (includeRudder == true) {
            ; USAGE (Rudder)
            retlw  0x09
            retlw  0xBA
        }

        if (includeThrottle == true) {
            ; USAGE (Throttle)
            retlw  0x09
            retlw  0xBB
        }

        if (includeAccelerator == true) {
            ; USAGE (Accelerator)
            retlw  0x09
            retlw  0xC4
        }

        if (includeBrake == true) {
            ; USAGE (Brake)
            retlw  0x09
            retlw  0xC5
        }

        if (includeSteering == true) {
            ; USAGE (Steering)
            retlw  0x09
            retlw  0xC8
        }

        ; INPUT (Data,Var,Abs)
        retlw  0x81
        retlw  0x02

        ; END_COLLECTION (Physical)
        retlw  0xc0

    } ; Simulation Controls

    ; END_COLLECTION
    retlw  0xc0