Skip to content

Commit

Permalink
Implement HIDDevice.receiveFeatureReport
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Oct 15, 2024
1 parent 4b84ceb commit 1d71539
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
18 changes: 16 additions & 2 deletions client/WebHID-for-Firefox.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@
{
dev.oninputreport(evt);
}
break;
}
break;

case 1: // input report with reportId
{
Expand All @@ -149,6 +149,14 @@
}
}
break;

case 2: // feature report
{
const hash = view.getUint32(1);
const dev = hash_to_dev[hash];
dev._featureReportResolve(new DataView(event.data.slice(6)));
}
break;
}
}
else
Expand Down Expand Up @@ -225,7 +233,13 @@
msg.set(data, 6); // data
ws.send(msg);
};
dev.receiveFeatureReport = () => { console.log("TODO: HIDDevice.receiveFeatureReport"); };
dev.receiveFeatureReport = function(reportId)
{
console.assert(this.opened);

ws.send("rcfr" + this._hash);
return new Promise(resolve => this._featureReportResolve = resolve);
};

const collection = new HIDCollectionInfo();
collection.usage = parseInt(msg[6]);
Expand Down
24 changes: 24 additions & 0 deletions server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,30 @@ SOEKVYljbu9o5nFbg1zU0Ck=
sub->unsubscribe();
}
}
else if (msg.data.substr(0, 4) == "rcfr")
{
uint32_t hid_hash = std::strtoul(msg.data.c_str() + 4, nullptr, 10);
for (auto& hid : hwHid::getAll())
{
if (hid_to_hash(hid) == hid_hash && hid_is_permitted(hid))
{
Buffer report;
try
{
hid.receiveFeatureReport(report);
}
catch (std::exception&)
{
}
BufferWriter bw;
uint8_t msgid = 2; bw.u8(msgid);
bw.u32_be(hid_hash);
bw.buf.append(report);
ServerWebService::wsSendBin(s, bw.buf.toString());
break;
}
}
}
}
else
{
Expand Down

0 comments on commit 1d71539

Please sign in to comment.