Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit d5fc8103 authored by Simon Chan's avatar Simon Chan
Browse files

feat(hid): reuse report buffer

parent b5245db7
Loading
Loading
Loading
Loading
+35 −35
Original line number Diff line number Diff line
@@ -267,10 +267,12 @@ export class HidKeyboard {
            0x75, 0x08, //   Report Size (8)
            0x95, 0x06, //   Report Count (6)
            0x81, 0x00, //   Input (Data, Array)
            0xc0        // End Collection
        ]
            0xc0,       // End Collection
        ],
    );

    static readonly REPORT_SIZE = 8;

    #modifiers = 0;
    #keys: Set<HidKeyCode> = new Set();

@@ -295,17 +297,15 @@ export class HidKeyboard {
        this.#keys.clear();
    }

    serializeInputReport() {
        const buffer = new Uint8Array(8);
        buffer[0] = this.#modifiers;
    updateReport(report: Uint8Array) {
        report[0] = this.#modifiers;
        let i = 2;
        for (const key of this.#keys) {
            buffer[i] = key;
            report[i] = key;
            i += 1;
            if (i >= 8) {
                break;
            }
        }
        return buffer;
    }
}