Knob/Fader/Button initialization code snippet for HID mappings

The following code from my Traktor Z2 mapping should be universal usable for all HID mappings. It requires a recent Main build (Mixxx 2.4).
To use it, you need to replace the string “TraktorZ2” by your mapping name and adjust the ReportIDs in the first for loop.
The place to call it is direct after registering input and output reports.

// Read and apply initial state for two HID InputReports ( 0x01 and 0x02 )

// Set each InputReport to the bitwise inverted state first,
// and than apply the non-inverted initial state.
// This is done, because the common-hid-packet-parser only triggers
// the callback functions in case of a delta to the previous data.
for (let inputReportIdx = 0x01; inputReportIdx <= 0x02 ; ++inputReportIdx) {        
    let data = new Uint8Array;
    data = controller.getInputReport(inputReportIdx);
    let dataInverted = new Uint8Array(data.length);
    dataInverted[0] = data[0];
    for (let byteIdx = 1; byteIdx < data.length; ++byteIdx) {
        dataInverted[byteIdx] = ~data[byteIdx];
    }
    TraktorZ2.incomingData(dataInverted);
    TraktorZ2.incomingData(data);
}