Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fairly major bacon.js input/output overhaul #11

Merged
merged 12 commits into from
Apr 7, 2024
Merged

Conversation

fchorney
Copy link
Collaborator

@fchorney fchorney commented Apr 5, 2024

Various changes and fixes mostly regarding using Bacon.js as the event handler for USB input/output.

Changes:

  • Clean up dead code
  • sdk/index.ts changed to just export the public API
  • major changes to sdk/smx.ts Bacon.js event streams to handle input/output properly
  • Allow SMXStage.updateConfig to return a promise so we can wait until we get a response to the config request (used on initialization)
  • Handle stage inputs properly (when a panel is pressed)
  • Move packet handling statemachine to sdk/state-machines/collate-packets.ts
  • Add UI throttling for stage input states
  • Fix test data checkbox to properly stop requesting/updating test data when it is unchecked.
  • Pass in isFsr to the Panel Test Data constructor so we know how to return the test data as FSRs are treated differently than LoadCells.

sdk/smx.ts Outdated
Comment on lines 42 to 46
this.dontSend = this.otherReports$
.filter((e) => e.type === 'host_cmd_finished')
.map((e) => e.type !== "host_cmd_finished")
.toProperty(false);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we can use a property to tell the output buffers to holdWhen the property is true, but I can't quite figure out how to set the property to false when we receive host_cmd_finished but then set it to true when we send a packet to stop it from sending packets until we get the host_cmd_finished back

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think we have to model it with a combination of two streams (our output and the input we see from the pad). it can watch both streams at once and emit true or false depending on which it saw most recently. I'm not totally sure how to code that with bacon yet, though

sdk/smx.ts Outdated Show resolved Hide resolved
sdk/smx.ts Outdated
Comment on lines 71 to 77
const combinedOutput$ = new Bacon.Bus<Array<number>>()
.merge(configOutput$)
.merge(otherOutput$)
.bufferingThrottle(100)
.takeWhile(okSend$)
.doAction(_ => this.startedSend$.push(true))
.onValue(async (value) => await this.writeToHID(value));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't get this to work without a bufferingThrottle.

I think what happens is okSend$ is true, so it lets one thing through, it then pushes startedSend$ so okSend$ becomes false, but by the time okSend$ becomes true again from a packet finishing, combinedOutput$ has 2 events lined up in the queue, so it then tries to send them both out at the same time. I tried bufferingCount(1) but that didn't help. Not really too sure how to get this to work how we want it quite yet. A little closer though.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I think we do need some kind of buffer on it. may need to play with bacon a bit more to better understand the best pattern to use here

Copy link
Owner

@noahm noahm Apr 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on the docs for takeWhile:

Takes while given predicate function holds true, and then ends.

The ends part is significant, because when a stream ends, I don't think it ever emits events again. So, either the docs are wrong on this, or something else mysterious is happening. Also, when looking at what seems to be the inverse of takeWhile, the holdWhen operator:

Pauses and buffers the event stream if last event in valve is truthy. All buffered events are released when valve becomes falsy.

This "all events are released" behavior seems like the undesirable behavior you were observing that we need to work around with bufferingThrottle?

noahm and others added 2 commits April 6, 2024 16:43
- Pass in `isFsr` to test data parsing
- Throttle stage panel inputs in UI for better reactivity
- General cleanup
@fchorney fchorney marked this pull request as ready for review April 7, 2024 01:36
@fchorney fchorney changed the title Get bacon output workin Fairly major bacon.js input/output overhaul Apr 7, 2024
@fchorney fchorney merged commit 8aef507 into main Apr 7, 2024
4 checks passed
@fchorney fchorney deleted the fc/bacon-output branch April 7, 2024 01:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants