Skip to content

Commit

Permalink
sort of works
Browse files Browse the repository at this point in the history
  • Loading branch information
fchorney committed Apr 5, 2024
1 parent edcdb9c commit b1d588f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion sdk/packet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function make_packets(data: Array<number>): Array<Uint8Array> {
return packets;
}

export async function requestSpecialDeviceInfo(dev: HIDDevice, debug = false) {
export async function makeSpecialDevicePacket(dev: HIDDevice, debug = false) {
const packet = pad_packet([PACKET_FLAG_DEVICE_INFO]);

if (debug) {
Expand Down
28 changes: 18 additions & 10 deletions sdk/smx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,21 @@ class SMXEvents {

// this.otherReports$.onValue((value) => console.log("Packet: ", value));

this.otherReports$
.filter((e) => e.type === 'host_cmd_finished')
.onValue((e) => console.log("Cmd Finished"));

const finishedCommand$ = this.otherReports$
.filter((e) => e.type === 'host_cmd_finished')
.map((e) => e.type === 'host_cmd_finished')
.map((e) => !e);
.map((e) => e.type === 'host_cmd_finished');

this.startedSend$ = new Bacon.Bus<boolean>();

// false means "it's ok to send", true means "don't send"
const dontSend$ = new Bacon.Bus<boolean>()
.merge(finishedCommand$) // Returns false when host_cmd_finished
.merge(this.startedSend$) // Return true when starting to send
.toProperty(false);
// true means "it's ok to send", false means "don't send"
const okSend$ = new Bacon.Bus<boolean>()
.merge(finishedCommand$) // Returns true when host_cmd_finished
.merge(this.startedSend$.not()) // Return false when starting to send
.toProperty(true);

// Main USB Output
this.output$ = new Bacon.Bus<Array<number>>();
Expand All @@ -68,12 +71,15 @@ class SMXEvents {
const combinedOutput$ = new Bacon.Bus<Array<number>>()
.merge(configOutput$)
.merge(otherOutput$)
.holdWhen(dontSend$)
.bufferingThrottle(100)
.takeWhile(okSend$)
.doAction(_ => this.startedSend$.push(true))
.onValue(async (value) => await this.writeToHID(value));
}

private async writeToHID(value: Array<number>) {
this.startedSend$.push(true);
//this.startedSend$.push(true);
console.log("writing to HID");
await send_data(this.dev, value);
}
}
Expand Down Expand Up @@ -117,7 +123,9 @@ export class SMXStage {
* 'i' command, but we can send it safely at any time, even if another
* application is talking to the device. Thus we can do this during enumeration.
*/
await requestSpecialDeviceInfo(this.dev);
//await requestSpecialDeviceInfo(this.dev); // Modify `send_data` to accept this somehow?

this.updateDeviceInfo();

// Request the config for this stage
this.updateConfig();
Expand Down

0 comments on commit b1d588f

Please sign in to comment.